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(layerLoaded) - Hotfix for the LayerApi.layerLoaded event #2634

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 @@ -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
Loading