From b9f033515b53644f2ddefb2746c3e0d35298ed3d Mon Sep 17 00:00:00 2001 From: Alex <94073946+Alex-NRCan@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:33:56 -0500 Subject: [PATCH] Hotfix for the layer highlighting (#2638) --- .../legend-event-processor.ts | 2 +- .../map-event-processor.ts | 3 + .../src/geo/layer/gv-layers/raster/gv-wms.ts | 6 +- packages/geoview-core/src/geo/layer/layer.ts | 60 ++++++++++++------- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/packages/geoview-core/src/api/event-processors/event-processor-children/legend-event-processor.ts b/packages/geoview-core/src/api/event-processors/event-processor-children/legend-event-processor.ts index 21e16b3aaca..db0aea7329a 100644 --- a/packages/geoview-core/src/api/event-processors/event-processor-children/legend-event-processor.ts +++ b/packages/geoview-core/src/api/event-processors/event-processor-children/legend-event-processor.ts @@ -105,7 +105,7 @@ export class LegendEventProcessor extends AbstractEventProcessor { * @param {string} layerPath - The layer path * @param {Extent | undefined} bounds - The extent of the layer at the given path */ - static setLayerBounds(mapId: string, layerPath: string, bounds: Extent): void { + static setLayerBounds(mapId: string, layerPath: string, bounds: Extent | undefined): void { // Find the layer for the given layer path const layers = LegendEventProcessor.getLayerState(mapId).legendLayers; const layer = this.findLayerByPath(layers, layerPath); diff --git a/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts b/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts index 260bceefec1..ac657ef24c4 100644 --- a/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts +++ b/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts @@ -513,6 +513,9 @@ export class MapEventProcessor extends AbstractEventProcessor { // refresh layers so new projection is render properly and await on it await this.getMapViewer(mapId).refreshLayers(); + + // When the map projection is changed, all layer bounds must be recalculated + this.getMapViewer(mapId).layer.recalculateBoundsAll(); } finally { // Remove circular progress as refresh is done AppEventProcessor.setCircularProgress(mapId, false); diff --git a/packages/geoview-core/src/geo/layer/gv-layers/raster/gv-wms.ts b/packages/geoview-core/src/geo/layer/gv-layers/raster/gv-wms.ts index 694e6e227bb..032051934a0 100644 --- a/packages/geoview-core/src/geo/layer/gv-layers/raster/gv-wms.ts +++ b/packages/geoview-core/src/geo/layer/gv-layers/raster/gv-wms.ts @@ -569,7 +569,11 @@ export class GVWMS extends AbstractGVRaster { } // If both layer config had bounds and layer has real bounds, take the intersection between them - if (layerConfigBounds && layerBounds) layerBounds = getExtentIntersection(layerBounds, layerConfigBounds); + if (layerConfigBounds && layerBounds) { + layerBounds = getExtentIntersection(layerBounds, layerConfigBounds); + } else if (layerConfigBounds && !layerBounds) { + layerBounds = layerConfigBounds; + } // Validate layerBounds = validateExtentWhenDefined(layerBounds, this.getMapViewer().getProjection().getCode()); diff --git a/packages/geoview-core/src/geo/layer/layer.ts b/packages/geoview-core/src/geo/layer/layer.ts index 2c7d6e3ce82..e122a828a6f 100644 --- a/packages/geoview-core/src/geo/layer/layer.ts +++ b/packages/geoview-core/src/geo/layer/layer.ts @@ -1379,22 +1379,23 @@ export class LayerApi { // If it is a group layer, highlight sublayers if (layerEntryIsGroupLayer(this.#layerEntryConfigs[layerPath])) { Object.keys(this.#layerEntryConfigs).forEach((registeredLayerPath) => { - const theLayer = this.getGeoviewLayerHybrid(registeredLayerPath)!; + // Trying to get the layer associated with the layer path, can be undefined because the layer might be in error + const theLayer = this.getGeoviewLayerHybrid(registeredLayerPath); if (!registeredLayerPath.startsWith(layerPath) && !layerEntryIsGroupLayer(this.#layerEntryConfigs[registeredLayerPath])) { - const otherOpacity = theLayer.getOpacity(registeredLayerPath); - theLayer.setOpacity((otherOpacity || 1) * 0.25, registeredLayerPath); - } else this.getOLLayer(registeredLayerPath)!.setZIndex(999); + const otherOpacity = theLayer?.getOpacity(registeredLayerPath); + theLayer?.setOpacity((otherOpacity || 1) * 0.25, registeredLayerPath); + } else this.getOLLayer(registeredLayerPath)?.setZIndex(999); }); } else { Object.keys(this.#layerEntryConfigs).forEach((registeredLayerPath) => { - const theLayer = this.getGeoviewLayerHybrid(registeredLayerPath)!; - // check for otherOlLayer is undefined. It would be undefined if a layer status is error + // Trying to get the layer associated with the layer path, can be undefined because the layer might be in error + const theLayer = this.getGeoviewLayerHybrid(registeredLayerPath); if (registeredLayerPath !== layerPath && !layerEntryIsGroupLayer(this.#layerEntryConfigs[registeredLayerPath])) { - const otherOpacity = theLayer.getOpacity(registeredLayerPath); - theLayer.setOpacity((otherOpacity || 1) * 0.25, registeredLayerPath); + const otherOpacity = theLayer?.getOpacity(registeredLayerPath); + theLayer?.setOpacity((otherOpacity || 1) * 0.25, registeredLayerPath); } }); - this.getOLLayer(layerPath)!.setZIndex(999); + this.getOLLayer(layerPath)?.setZIndex(999); } } @@ -1407,20 +1408,21 @@ export class LayerApi { const { layerPath, originalOpacity } = this.#highlightedLayer; if (layerEntryIsGroupLayer(this.#layerEntryConfigs[layerPath])) { Object.keys(this.#layerEntryConfigs).forEach((registeredLayerPath) => { - const theLayer = this.getGeoviewLayerHybrid(registeredLayerPath)!; + // Trying to get the layer associated with the layer path, can be undefined because the layer might be in error + const theLayer = this.getGeoviewLayerHybrid(registeredLayerPath); if (!registeredLayerPath.startsWith(layerPath) && !layerEntryIsGroupLayer(this.#layerEntryConfigs[registeredLayerPath])) { - const otherOpacity = theLayer.getOpacity(registeredLayerPath); - theLayer.setOpacity(otherOpacity ? otherOpacity * 4 : 1, registeredLayerPath); - } else theLayer.setOpacity(originalOpacity || 1, registeredLayerPath); + const otherOpacity = theLayer?.getOpacity(registeredLayerPath); + theLayer?.setOpacity(otherOpacity ? otherOpacity * 4 : 1, registeredLayerPath); + } else theLayer?.setOpacity(originalOpacity || 1, registeredLayerPath); }); } else { Object.keys(this.#layerEntryConfigs).forEach((registeredLayerPath) => { - // check for otherOlLayer is undefined. It would be undefined if a layer status is error - const theLayer = this.getGeoviewLayerHybrid(registeredLayerPath)!; + // Trying to get the layer associated with the layer path, can be undefined because the layer might be in error + const theLayer = this.getGeoviewLayerHybrid(registeredLayerPath); if (registeredLayerPath !== layerPath && !layerEntryIsGroupLayer(this.#layerEntryConfigs[registeredLayerPath])) { - const otherOpacity = theLayer.getOpacity(registeredLayerPath); - theLayer.setOpacity(otherOpacity ? otherOpacity * 4 : 1, registeredLayerPath); - } else theLayer.setOpacity(originalOpacity || 1, registeredLayerPath); + const otherOpacity = theLayer?.getOpacity(registeredLayerPath); + theLayer?.setOpacity(otherOpacity ? otherOpacity * 4 : 1, registeredLayerPath); + } else theLayer?.setOpacity(originalOpacity || 1, registeredLayerPath); }); } MapEventProcessor.setLayerZIndices(this.getMapId()); @@ -1675,6 +1677,17 @@ export class LayerApi { return boundsUnion; } + /** + * Recalculates the bounds for all layers and updates the store. + */ + recalculateBoundsAll(): void { + // For each layer path + this.getLayerEntryConfigIds().forEach((layerPath: string) => { + const bounds = this.calculateBounds(layerPath); + LegendEventProcessor.setLayerBounds(this.getMapId(), layerPath, bounds); + }); + } + /** * Recursively gathers all bounds on the layers associated with the given layer path and store them in the bounds parameter. * @param {ConfigBaseClass} layerConfig - The layer config being processed @@ -1684,11 +1697,14 @@ export class LayerApi { // If a leaf if (!layerEntryIsGroupLayer(layerConfig)) { // Get the layer - const layer = this.getGeoviewLayerHybrid(layerConfig.layerPath) as AbstractGeoViewLayer | AbstractGVLayer; + const layer = this.getGeoviewLayerHybrid(layerConfig.layerPath); - // Get the bounds of the layer - const calculatedBounds = layer.getBounds(layerConfig.layerPath); - if (calculatedBounds) bounds.push(calculatedBounds); + // If the layer is of right type (should be, because we checked if not a group) + if (layer instanceof AbstractGeoViewLayer || layer instanceof AbstractGVLayer) { + // Get the bounds of the layer + const calculatedBounds = layer.getBounds(layerConfig.layerPath); + if (calculatedBounds) bounds.push(calculatedBounds); + } } else { // Is a group layerConfig.listOfLayerEntryConfig.forEach((subLayerConfig) => {