Skip to content

Commit

Permalink
Legend printing: separate handling of cases 'no child layer has a leg…
Browse files Browse the repository at this point in the history
…end image' => print group legend; 'no child layer is activated' => print nothing
  • Loading branch information
werrolf committed Nov 14, 2018
1 parent b8cd8af commit 077cf79
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -285,15 +285,23 @@
function _getLegends(layer) {
var legend = {};
if (!layer.options.treeOptions.selected) {
return legend;
return false;
}
if (layer.children) {
var childrenActive = false;
for (var i = 0; i < layer.children.length; i++) {
_.assign(legend, _getLegends(layer.children[i]));
var childLegends = _getLegends(layer.children[i]);
if (childLegends !== false) {
_.assign(legend, childLegends);
childrenActive = true;
}
}
if (!childrenActive) {
return false;
}
}
// Only include the legend for a "group" / non-leaf layer if we haven't collected any
// legend images from leaf layers yet.
// legend images from leaf layers yet, but at least one leaf layer is actually active
if (!Object.keys(legend).length) {
if (layer.options.legend && layer.options.legend.url && layer.options.treeOptions.selected) {
legend[layer.options.title] = layer.options.legend.url;
Expand Down

0 comments on commit 077cf79

Please sign in to comment.