Skip to content

Commit

Permalink
Hotfix for the LayerApi.layerLoaded event (#2634)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-NRCan authored Dec 5, 2024
1 parent 7f0d0b4 commit a362e50
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1364,11 +1364,11 @@ export abstract class AbstractGeoViewLayer {
// Set loaded
layerConfig.layerStatus = 'loaded';

// Emit event
this.#emitIndividualLayerLoaded({ layerPath: layerConfig.layerPath });

// Set visibility
this.setVisible(layerConfig.initialSettings?.states?.visible !== false, layerConfig.layerPath);

// Emit event
this.#emitIndividualLayerLoaded({ layerPath: layerConfig.layerPath });
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ export abstract class AbstractGVLayer extends AbstractBaseLayer {
// Set the layer config status to loaded to keep mirroring the AbstractGeoViewLayer for now
this.getLayerConfig().layerStatus = 'loaded';

// Emit event
this.#emitIndividualLayerLoaded({ layerPath: this.getLayerPath() });

// Now that the layer is loaded, set its visibility correctly (had to be done in the loaded event, not before, per prior note in pre-refactor)
this.setVisible(this.getLayerConfig().initialSettings?.states?.visible !== false);

// Emit event
this.#emitIndividualLayerLoaded({ layerPath: this.getLayerPath() });
}

/**
Expand Down
29 changes: 21 additions & 8 deletions packages/geoview-core/src/geo/layer/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,17 @@ export class LayerApi {
// If new layers mode, create the corresponding GVLayer
if (LayerApi.LAYERS_HYBRID_MODE) {
const gvLayer = this.#createGVLayer(this.getMapId(), geoviewLayer, event.source, event.config, event.extraConfig);
if (gvLayer) return gvLayer.getOLLayer();

// If found the GV layer
if (gvLayer) {
// Register a hook when a layer is loaded on the map
gvLayer!.onIndividualLayerLoaded((sender, payload) => {
// Log
logger.logDebug(`${payload.layerPath} loaded on map ${this.getMapId()}`);
this.#emitLayerLoaded({ layer: sender, layerPath: payload.layerPath });
});
return gvLayer.getOLLayer();
}
}

// Don't provide any layer, working in old mode
Expand Down Expand Up @@ -766,12 +776,15 @@ export class LayerApi {
layerBeingAdded!
.createGeoViewLayers()
.then(() => {
// Register a hook when a layer is loaded on the map
layerBeingAdded!.onIndividualLayerLoaded((sender, payload) => {
// Log
logger.logDebug(`${payload.layerPath} loaded on map ${this.getMapId()}`);
this.#emitLayerLoaded({ layer: sender, layerPath: payload.layerPath });
});
// If not HYBRID MODE
if (!LayerApi.LAYERS_HYBRID_MODE) {
// Register a hook when a layer is loaded on the map
layerBeingAdded!.onIndividualLayerLoaded((sender, payload) => {
// Log
logger.logDebug(`${payload.layerPath} loaded on map ${this.getMapId()}`);
this.#emitLayerLoaded({ layer: sender, layerPath: payload.layerPath });
});
}

// Add the layer on the map
this.#addToMap(layerBeingAdded!);
Expand Down Expand Up @@ -1861,7 +1874,7 @@ type LayerLoadedDelegate = EventDelegateBase<LayerApi, LayerLoadedEvent, void>;
*/
export type LayerLoadedEvent = {
// The loaded layer
layer: AbstractGeoViewLayer;
layer: AbstractGeoViewLayer | AbstractGVLayer;

layerPath: string;
};
Expand Down

0 comments on commit a362e50

Please sign in to comment.