Skip to content

Commit

Permalink
Merge pull request #7274 from camptocamp/gmf-1638-fix-print-static-le…
Browse files Browse the repository at this point in the history
…gend

Fix static legend on printing
  • Loading branch information
sbrunner authored Jun 28, 2021
2 parents 8d2022f + 42aba67 commit cf734f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions contribs/gmf/src/objectediting/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ function getQueryableLayersInfoFromThemes(themes, ogcServers) {
continue;
}

/** @type {Array<import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayer>} */
/** @type {Array<import('gmf/themes.js').GmfLayer>} */
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;
Expand Down
14 changes: 8 additions & 6 deletions contribs/gmf/src/print/LegendMapFishPrintV3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions contribs/gmf/src/theme/Themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -559,15 +559,15 @@ 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<import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayer>} nodes An array.
* @param {Array<import('gmf/themes.js').GmfGroup>} nodes An array.
* @private
* @hidden
*/
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);
}
Expand All @@ -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<import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayer>} nodes An array.
* @param {import('gmf/themes.js').GmfTheme|import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayer} node Layertree node.
* @param {Array<import('gmf/themes.js').GmfLayer>} 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));
}
}

Expand Down

0 comments on commit cf734f4

Please sign in to comment.