Skip to content

Commit

Permalink
Merge pull request #2625 from Vizzuality/release/tree-loss-category-f…
Browse files Browse the repository at this point in the history
…ixed

Release/tree loss category fixed
  • Loading branch information
j8seangel authored Oct 18, 2016
2 parents 83bfde1 + 749ef18 commit f6fd9d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/map/services/MapLayerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ define([
source_json, \
category_color, \
category_slug, \
is_forest_clearing, \
category_name, \
external, \
iso, \
Expand Down
19 changes: 13 additions & 6 deletions app/assets/javascripts/map/views/LegendView.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ define([
'text!map/templates/legend/mex_forest_conserv.handlebars',
'text!map/templates/legend/mex_forest_prod.handlebars',
'text!map/templates/legend/mex_forest_rest.handlebars',

], function(_, Handlebars, Presenter, tpl, tplMore, lossTpl, imazonTpl, firesTpl,
forest2000Tpl, pantropicalTpl, idnPrimaryTpl, intact2013Tpl, grumpTpl, storiesTpl, terra_iTpl, concesionesTpl,
concesionesTypeTpl, hondurasForestTPL,colombiaForestChangeTPL, tigersTPL, dam_hotspotsTPL, us_land_coverTPL,
Expand Down Expand Up @@ -156,7 +156,7 @@ define([
mexican_pa:Handlebars.compile(mexPATpl),
per_protected_areas:Handlebars.compile(perPATpl),
mex_land_cover:Handlebars.compile(mex_land_coverTpl)

},

events: {
Expand Down Expand Up @@ -248,9 +248,8 @@ define([

}, this);

categoriesGlobal = this.statusCategories(_.groupBy(layersGlobal, function(layer){ return layer.category_slug }));
categoriesIso = this.statusCategories(_.groupBy(layersIso, function(layer){ return layer.category_slug }));

categoriesGlobal = this.statusCategories(this.getLayersByCategory(layersGlobal));
categoriesIso = this.statusCategories(this.getLayersByCategory(layersIso));
// Render
this.render(this.template({
categories: (_.isEmpty(categoriesGlobal)) ? false : categoriesGlobal,
Expand All @@ -263,13 +262,21 @@ define([
this.presenter.toggleLayerOptions();
},

getLayersByCategory: function(layers){
return _.groupBy(layers, function(layer){
// Hack to keep the forest_clearing slug in layers which have to be analyzed but not grouped by the said slug in the legend
if (layer.category_slug === 'forest_clearing' && !layer.is_forest_clearing) return 'forest_clearing_2';
return layer.category_slug;
})
},

statusCategories: function(array){
// Search for layer 'nothing'
var categories_status = this.model.get('categories_status');
_.each(array, function(category) {
for (var i = 0; i< category.length; i++) {
// Mantain categories closed in rendering
(categories_status.indexOf(category[i]['category_status']) != -1) ? category['closed'] = true : category['closed'] = false;
category['closed'] = categories_status.indexOf(category[i]['category_status']) != -1;
// Get layer's length of each category
category['layers_length'] = i + 1;
}
Expand Down

0 comments on commit f6fd9d8

Please sign in to comment.