Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/611 redundant group layer legends print #1053

Merged
merged 4 commits into from Nov 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -284,12 +284,27 @@
var scale = this._getPrintScale();
function _getLegends(layer) {
var legend = {};
if (layer.options.legend && layer.options.legend.url && layer.options.treeOptions.selected) {
legend[layer.options.title] = layer.options.legend.url;
if (!layer.options.treeOptions.selected) {
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, 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;
}
}
return legend;
Expand All @@ -299,7 +314,7 @@
var source = sources[i];
if (source.type === 'wms' && this._getRasterVisibilityInfo(source, scale).layers.length) {
var ll = _getLegends(sources[i].configuration.children[0]);
if (ll) {
if (ll && Object.keys(ll).length) {
legends = legends.concat(ll);
}
}
Expand Down