Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(layer-highlight) Hotfix for the layer highlighting #2638

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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);
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 @@ -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);
}
}

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