From 84009228dc5a37aacde9355bc5e6d5fde31123b0 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 26 Mar 2024 16:54:38 +0100 Subject: [PATCH] feat: make the print legend respect theme visibility of thematicstyling layers (#1969) --- src/controls/print/print-legend.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/controls/print/print-legend.js b/src/controls/print/print-legend.js index 19c38bc6d..514174b3a 100644 --- a/src/controls/print/print-legend.js +++ b/src/controls/print/print-legend.js @@ -170,11 +170,14 @@ const LayerRow = function LayerRow(options) { return getTitleWithIcon(title, getStyleIcon(style[0])); } + const hasThematicStyle = (layer.get('thematicStyling') === true); const children = style.map((thisStyle, index) => { - if (!isHidden(thisStyle)) { - const styleIcon = getStyleIcon(thisStyle); - const rowTitle = thisStyle[0].label ? thisStyle[0].label : index + 1; - return getListItem(rowTitle, styleIcon); + if (!(isHidden(thisStyle))) { + if ((!(hasThematicStyle)) || (!(thisStyle[0]?.visible === false))) { + const styleIcon = getStyleIcon(thisStyle); + const rowTitle = thisStyle[0].label ? thisStyle[0].label : index + 1; + return getListItem(rowTitle, styleIcon); + } } return ''; }); @@ -205,11 +208,16 @@ const LayerRow = function LayerRow(options) { return getTitleWithIcon(title, icon); } - const rules = json.Legend[0].rules.map((rule, index) => { - const ruleImageUrl = `${getLegendGraphicUrl}&rule=${rule.name}`; - const rowTitle = rule.title ? rule.title : index + 1; - return getListItem(rowTitle, ruleImageUrl, true); - }); + const thematicStyle = (layer.get('thematicStyling') === true) ? viewer.getStyle(layer.get('styleName')) : undefined; + const rules = json.Legend[0].rules.reduce((okRules, rule, index) => { + if (!(layer.get('thematicStyling')) || thematicStyle[0]?.thematic[index]?.visible) { + const ruleImageUrl = `${getLegendGraphicUrl}&rule=${rule.name}`; + const rowTitle = rule.title ? rule.title : index + 1; + okRules.push(getListItem(rowTitle, ruleImageUrl, true)); + } + return okRules; + }, []); + return getTitleWithChildren(title, rules); };