diff --git a/packages/geoview-core/src/geo/layer/geoview-layers/abstract-geoview-layers.ts b/packages/geoview-core/src/geo/layer/geoview-layers/abstract-geoview-layers.ts index 4a730d7b9e9..096a4aa2914 100644 --- a/packages/geoview-core/src/geo/layer/geoview-layers/abstract-geoview-layers.ts +++ b/packages/geoview-core/src/geo/layer/geoview-layers/abstract-geoview-layers.ts @@ -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 }); } /** diff --git a/packages/geoview-core/src/geo/layer/gv-layers/abstract-gv-layer.ts b/packages/geoview-core/src/geo/layer/gv-layers/abstract-gv-layer.ts index 734c5035184..c901d6709bc 100644 --- a/packages/geoview-core/src/geo/layer/gv-layers/abstract-gv-layer.ts +++ b/packages/geoview-core/src/geo/layer/gv-layers/abstract-gv-layer.ts @@ -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() }); } /** diff --git a/packages/geoview-core/src/geo/layer/layer.ts b/packages/geoview-core/src/geo/layer/layer.ts index a6d83cc7751..b0737a2023c 100644 --- a/packages/geoview-core/src/geo/layer/layer.ts +++ b/packages/geoview-core/src/geo/layer/layer.ts @@ -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 @@ -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!); @@ -1861,7 +1874,7 @@ type LayerLoadedDelegate = EventDelegateBase; */ export type LayerLoadedEvent = { // The loaded layer - layer: AbstractGeoViewLayer; + layer: AbstractGeoViewLayer | AbstractGVLayer; layerPath: string; };