From cf5d2c5fca3bd3c82ee84016e944f7ffe27dfb54 Mon Sep 17 00:00:00 2001 From: AlexNRCan Date: Thu, 21 Nov 2024 13:54:44 -0500 Subject: [PATCH] Fixing the layer visiblity parenting --- common/config/rush/pnpm-lock.yaml | 6 +++--- packages/geoview-core/src/geo/layer/layer.ts | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 1e07eb04765..3b959905922 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -4533,7 +4533,7 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true dependencies: - caniuse-lite: 1.0.30001680 + caniuse-lite: 1.0.30001683 electron-to-chromium: 1.5.63 node-releases: 2.0.18 update-browserslist-db: 1.1.1(browserslist@4.24.2) @@ -4593,8 +4593,8 @@ packages: engines: {node: '>=10'} dev: true - /caniuse-lite@1.0.30001680: - resolution: {integrity: sha512-rPQy70G6AGUMnbwS1z6Xg+RkHYPAi18ihs47GH0jcxIG7wArmPgY3XbS2sRdBbxJljp3thdT8BIqv9ccCypiPA==} + /caniuse-lite@1.0.30001683: + resolution: {integrity: sha512-iqmNnThZ0n70mNwvxpEC2nBJ037ZHZUoBI5Gorh1Mw6IlEAZujEoU1tXA628iZfzm7R9FvFzxbfdgml82a3k8Q==} dev: true /ccount@2.0.1: diff --git a/packages/geoview-core/src/geo/layer/layer.ts b/packages/geoview-core/src/geo/layer/layer.ts index 9584c1e8e58..5d531809d6f 100644 --- a/packages/geoview-core/src/geo/layer/layer.ts +++ b/packages/geoview-core/src/geo/layer/layer.ts @@ -1456,10 +1456,6 @@ export class LayerApi { // Determine the outcome of the new visibility based on parameters const newVisibility = newValue !== undefined ? newValue : !layerVisibility; const layerInfos = curOrderedLayerInfo.filter((info: TypeOrderedLayerInfo) => info.layerPath.startsWith(layerPath)); - const parentLayerPathArray = layerPath.split('/'); - parentLayerPathArray.pop(); - const parentLayerPath = parentLayerPathArray.join('/'); - const parentLayerInfo = curOrderedLayerInfo.find((info: TypeOrderedLayerInfo) => info.layerPath === parentLayerPath); layerInfos.forEach((layerInfo: TypeOrderedLayerInfo) => { if (layerInfo) { @@ -1475,7 +1471,12 @@ export class LayerApi { } }); - if (parentLayerInfo !== undefined) { + // For each parent + const parentLayerPathArray = layerPath.split('/'); + parentLayerPathArray.pop(); + let parentLayerPath = parentLayerPathArray.join('/'); + let parentLayerInfo = curOrderedLayerInfo.find((info: TypeOrderedLayerInfo) => info.layerPath === parentLayerPath); + while (parentLayerInfo !== undefined) { const parentLayerVisibility = MapEventProcessor.getMapVisibilityFromOrderedLayerInfo(this.getMapId(), parentLayerPath); if ((!layerVisibility || newValue) && parentLayerVisibility === false) { if (parentLayerInfo) { @@ -1487,6 +1488,7 @@ export class LayerApi { } } const children = curOrderedLayerInfo.filter( + // eslint-disable-next-line no-loop-func (info: TypeOrderedLayerInfo) => info.layerPath.startsWith(parentLayerPath) && info.layerPath !== parentLayerPath ); if (!children.some((child: TypeOrderedLayerInfo) => child.visible === true)) { @@ -1495,6 +1497,12 @@ export class LayerApi { // Emit event this.#emitLayerVisibilityToggled({ layerPath, visibility: false }); } + + // Prepare for next parent + parentLayerPathArray.pop(); + parentLayerPath = parentLayerPathArray.join('/'); + // eslint-disable-next-line no-loop-func + parentLayerInfo = curOrderedLayerInfo.find((info: TypeOrderedLayerInfo) => info.layerPath === parentLayerPath); } // Redirect to processor so we can update the store with setterActions