Skip to content

Commit f6fd9d8

Browse files
authored
Merge pull request #2625 from Vizzuality/release/tree-loss-category-fixed
Release/tree loss category fixed
2 parents 83bfde1 + 749ef18 commit f6fd9d8

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

app/assets/javascripts/map/services/MapLayerService.js

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ define([
126126
source_json, \
127127
category_color, \
128128
category_slug, \
129+
is_forest_clearing, \
129130
category_name, \
130131
external, \
131132
iso, \

app/assets/javascripts/map/views/LegendView.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ define([
5959
'text!map/templates/legend/mex_forest_conserv.handlebars',
6060
'text!map/templates/legend/mex_forest_prod.handlebars',
6161
'text!map/templates/legend/mex_forest_rest.handlebars',
62-
62+
6363
], function(_, Handlebars, Presenter, tpl, tplMore, lossTpl, imazonTpl, firesTpl,
6464
forest2000Tpl, pantropicalTpl, idnPrimaryTpl, intact2013Tpl, grumpTpl, storiesTpl, terra_iTpl, concesionesTpl,
6565
concesionesTypeTpl, hondurasForestTPL,colombiaForestChangeTPL, tigersTPL, dam_hotspotsTPL, us_land_coverTPL,
@@ -156,7 +156,7 @@ define([
156156
mexican_pa:Handlebars.compile(mexPATpl),
157157
per_protected_areas:Handlebars.compile(perPATpl),
158158
mex_land_cover:Handlebars.compile(mex_land_coverTpl)
159-
159+
160160
},
161161

162162
events: {
@@ -248,9 +248,8 @@ define([
248248

249249
}, this);
250250

251-
categoriesGlobal = this.statusCategories(_.groupBy(layersGlobal, function(layer){ return layer.category_slug }));
252-
categoriesIso = this.statusCategories(_.groupBy(layersIso, function(layer){ return layer.category_slug }));
253-
251+
categoriesGlobal = this.statusCategories(this.getLayersByCategory(layersGlobal));
252+
categoriesIso = this.statusCategories(this.getLayersByCategory(layersIso));
254253
// Render
255254
this.render(this.template({
256255
categories: (_.isEmpty(categoriesGlobal)) ? false : categoriesGlobal,
@@ -263,13 +262,21 @@ define([
263262
this.presenter.toggleLayerOptions();
264263
},
265264

265+
getLayersByCategory: function(layers){
266+
return _.groupBy(layers, function(layer){
267+
// Hack to keep the forest_clearing slug in layers which have to be analyzed but not grouped by the said slug in the legend
268+
if (layer.category_slug === 'forest_clearing' && !layer.is_forest_clearing) return 'forest_clearing_2';
269+
return layer.category_slug;
270+
})
271+
},
272+
266273
statusCategories: function(array){
267274
// Search for layer 'nothing'
268275
var categories_status = this.model.get('categories_status');
269276
_.each(array, function(category) {
270277
for (var i = 0; i< category.length; i++) {
271278
// Mantain categories closed in rendering
272-
(categories_status.indexOf(category[i]['category_status']) != -1) ? category['closed'] = true : category['closed'] = false;
279+
category['closed'] = categories_status.indexOf(category[i]['category_status']) != -1;
273280
// Get layer's length of each category
274281
category['layers_length'] = i + 1;
275282
}

0 commit comments

Comments
 (0)