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 d3ad007f75b..2156f9154f8 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 @@ -512,6 +512,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 b0737a2023c..798b1f5f666 100644 --- a/packages/geoview-core/src/geo/layer/layer.ts +++ b/packages/geoview-core/src/geo/layer/layer.ts @@ -1344,22 +1344,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); } } @@ -1372,20 +1373,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()); @@ -1640,6 +1642,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 @@ -1649,11 +1662,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) => {