Skip to content

Commit

Permalink
Hotfix for the layer highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-NRCan committed Dec 6, 2024
1 parent a362e50 commit 456a771
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
60 changes: 38 additions & 22 deletions packages/geoview-core/src/geo/layer/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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) => {
Expand Down

0 comments on commit 456a771

Please sign in to comment.