From 42aba676bb91362e8f7f1d39831e63159f639415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 28 Jun 2021 11:36:35 +0200 Subject: [PATCH] Fix static legend on printing Get the right node when the layer is in a subgroup --- contribs/gmf/src/objectediting/Query.js | 4 ++-- contribs/gmf/src/print/LegendMapFishPrintV3.js | 14 ++++++++------ contribs/gmf/src/theme/Themes.js | 16 ++++++++-------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/contribs/gmf/src/objectediting/Query.js b/contribs/gmf/src/objectediting/Query.js index 66a03bb99f0a..06b69272b4c1 100644 --- a/contribs/gmf/src/objectediting/Query.js +++ b/contribs/gmf/src/objectediting/Query.js @@ -119,12 +119,12 @@ function getQueryableLayersInfoFromThemes(themes, ogcServers) { continue; } - /** @type {Array} */ + /** @type {Array} */ const nodes = []; getFlatNodes(group, nodes); for (let k = 0, kk = nodes.length; k < kk; k++) { - const nodeGroup = /** @type {import('gmf/themes.js').GmfGroup} */ (nodes[k]); + const nodeGroup = /** @type {import('gmf/themes.js').GmfGroup} */ (/** @type {any} */ (nodes[k])); // Skip groups within groups if (nodeGroup.children && nodeGroup.children.length) { continue; diff --git a/contribs/gmf/src/print/LegendMapFishPrintV3.js b/contribs/gmf/src/print/LegendMapFishPrintV3.js index 521c6d836a2a..56a0483bcd3e 100644 --- a/contribs/gmf/src/print/LegendMapFishPrintV3.js +++ b/contribs/gmf/src/print/LegendMapFishPrintV3.js @@ -26,7 +26,7 @@ import {dpi as screenDpi} from 'ngeo/utils.js'; import {NODE_IS_LEAF, LAYER_NODE_NAME_KEY} from 'ngeo/map/LayerHelper.js'; import {DATALAYERGROUP_NAME} from 'gmf/index.js'; import ExternalOGC from 'gmf/datasource/ExternalOGC.js'; -import {findGroupByLayerNodeName, findObjectByName} from 'gmf/theme/Themes.js'; +import {getFlatNodes, findObjectByName} from 'gmf/theme/Themes.js'; /** * Get the print legend for MapFishPrint V3 from the OpenLayers map and the GMF Layertree. @@ -390,12 +390,14 @@ export default class LegendMapFishPrintV3 { if (dpi == -1) { dpi = screenDpi(); } - const groupNode = findGroupByLayerNodeName(currentThemes, layerName); - let found_dpi = dpi; - let node; - if (groupNode && groupNode.children) { - node = findObjectByName(groupNode.children, layerName); + /** @type {import("gmf/themes").GmfLayer[]} */ + const nodes = []; + for (const theme of currentThemes) { + getFlatNodes(theme, nodes); } + const node = findObjectByName(nodes, layerName); + + let found_dpi = dpi; let legendImage; let hiDPILegendImages; if (node && node.metadata) { diff --git a/contribs/gmf/src/theme/Themes.js b/contribs/gmf/src/theme/Themes.js index 9f89cd09d755..78b5c42049d5 100644 --- a/contribs/gmf/src/theme/Themes.js +++ b/contribs/gmf/src/theme/Themes.js @@ -497,7 +497,7 @@ export function findGroupByLayerNodeName(themes, name) { const theme = themes[i]; for (let j = 0, jj = theme.children.length; j < jj; j++) { const group = theme.children[j]; - /** @type {(import("gmf/themes").GmfGroup | import("gmf/themes").GmfLayer)[]} */ + /** @type {import("gmf/themes").GmfLayer[]} */ const childNodes = []; getFlatNodes(group, childNodes); if (findObjectByName(childNodes, name)) { @@ -520,7 +520,7 @@ export function findGroupByName(themes, name) { const theme = themes[i]; for (let j = 0, jj = theme.children.length; j < jj; j++) { const group = theme.children[j]; - /** @type {(import("gmf/themes").GmfGroup | import("gmf/themes").GmfLayer)[]} */ + /** @type {import("gmf/themes").GmfGroup[]} */ const internalNodes = []; getFlatInternalNodes(group, internalNodes); if (findObjectByName(internalNodes, name)) { @@ -559,7 +559,7 @@ export function findThemeByName(themes, themeName) { * Fill the given "nodes" array with all internal nodes (non-leaf nones) in the given node. * * @param {import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayer} node Layertree node. - * @param {Array} nodes An array. + * @param {Array} nodes An array. * @private * @hidden */ @@ -567,7 +567,7 @@ function getFlatInternalNodes(node, nodes) { const gmfGroup = /** @type {import('gmf/themes.js').GmfGroup} */ (node); const children = gmfGroup.children; if (children !== undefined) { - nodes.push(node); + nodes.push(/** @type {import('gmf/themes.js').GmfGroup} */ (node)); for (const child of children) { getFlatInternalNodes(child, nodes); } @@ -577,19 +577,19 @@ function getFlatInternalNodes(node, nodes) { /** * Fill the given "nodes" array with all leaf nodes in the given node. * - * @param {import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayer} node Layertree node. - * @param {Array} nodes An array. + * @param {import('gmf/themes.js').GmfTheme|import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayer} node Layertree node. + * @param {Array} nodes An array. * @hidden */ export function getFlatNodes(node, nodes) { - const gmfGroup = /** @type {import('gmf/themes.js').GmfGroup} */ (node); + const gmfGroup = /** @type {import('gmf/themes.js').GmfTheme|import('gmf/themes.js').GmfGroup} */ (node); const children = gmfGroup.children; if (children !== undefined) { for (const child of children) { getFlatNodes(child, nodes); } } else { - nodes.push(node); + nodes.push(/** @type {import('gmf/themes.js').GmfLayer} */ (node)); } }