Skip to content

Commit

Permalink
2488 refresh layers alternate solution
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewMuehlhauserNRCan committed Nov 26, 2024
1 parent f7e592d commit 7fa9e4a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
48 changes: 48 additions & 0 deletions packages/geoview-core/src/geo/layer/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,54 @@ export class LayerApi {
logger.logError(`Duplicate use of geoview layer identifier ${mapConfigLayerEntry.geoviewLayerId} on map ${this.getMapId()}`);
}

/**
* Refreshes GeoCore Layers
* @returns {Promise<void>} A promise which resolves when done refreshing
*/
refreshGeocoreLayers(): Promise<void> {
const configs = this.getLayerEntryConfigs();
const originalMapOrderedLayerInfo = MapEventProcessor.getMapOrderedLayerInfo(this.getMapId());
const promisesOfGeoCoreGeoviewLayers: Promise<TypeGeoviewLayerConfig[]>[] = [];

configs
.filter((config) => {
// Filter to just Geocore layers and not child layers
if (api.config.isValidUUID(config.geoviewLayerConfig.geoviewLayerId) && config.parentLayerConfig === undefined) {
return true;
}
return false;
})
.forEach((config) => {
// Remove and add back in GeoCore Layers and return their promises
this.removeLayerUsingPath(config.layerPath);
const geoCore = new GeoCore(this.getMapId(), this.mapViewer.getDisplayLanguage());
promisesOfGeoCoreGeoviewLayers.push(geoCore.createLayersFromUUID(config.geoviewLayerConfig.geoviewLayerId));
});

return Promise.allSettled(promisesOfGeoCoreGeoviewLayers)
.then((promisedLayers) => {
promisedLayers
.map((promise) => promise as PromiseFulfilledResult<TypeGeoviewLayerConfig[]>)
.forEach((promise) => {
promise.value.forEach((geoviewLayerConfig) => {
this.addGeoviewLayer(geoviewLayerConfig);
});
});
const newMapOrderedLayerInfo = MapEventProcessor.getMapOrderedLayerInfo(this.getMapId());
const originalLayerPaths = originalMapOrderedLayerInfo.map((layer) => layer.layerPath);
const childLayersToRemove = newMapOrderedLayerInfo
.map((layer) => layer.layerPath)
.filter((path) => !originalLayerPaths.includes(path));
if (childLayersToRemove) {
childLayersToRemove.forEach((childPath) => {
this.removeLayerUsingPath(childPath);
});
}
MapEventProcessor.setMapOrderedLayerInfo(this.getMapId(), originalMapOrderedLayerInfo);
})
.catch((error) => logger.logError(error));
}

/**
* Adds a Geoview Layer by GeoCore UUID.
* @param {string} uuid - The GeoCore UUID to add to the map
Expand Down
36 changes: 1 addition & 35 deletions packages/geoview-core/src/geo/map/map-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,42 +931,8 @@ export class MapViewer {
const promise = AppEventProcessor.setDisplayLanguage(this.mapId, displayLanguage);

// if flag is true, check if config support the layers change and apply

if (resetLayer) {
const configs = this.layer.getLayerEntryConfigs();
const originalMapOrderedLayerInfo = MapEventProcessor.getMapOrderedLayerInfo(this.mapId);
// Need to wait for all refreshed GeoCore layers to be settles before trying to update
// the ordered layer info. Otherwise, the map doesn't update correctly
Promise.allSettled(
configs
.filter((config) => {
// Filter to just Geocore layers and not child layers
if (api.config.isValidUUID(config.geoviewLayerConfig.geoviewLayerId) && config.parentLayerConfig === undefined) {
return true;
}
return false;
})
.map((config) => {
// Remove and add back in GeoCore Layers and return their promises
const uuid = config.geoviewLayerConfig.geoviewLayerId;
this.layer.removeLayerUsingPath(config.layerPath);
return this.layer.addGeoviewLayerByGeoCoreUUID(uuid);
})
)
.then(() => {
// Can use the setMapOrderedLayerInfo to update the maps states, BUT
// still need to remove any children layers first that weren't in the original.
const newMapOrderedLayerInfo = MapEventProcessor.getMapOrderedLayerInfo(this.mapId);
const originalLayerPaths = originalMapOrderedLayerInfo.map((layer) => layer.layerPath);
const childLayersToRemove = newMapOrderedLayerInfo
.map((layer) => layer.layerPath)
.filter((path) => !originalLayerPaths.includes(path));
childLayersToRemove.forEach((childPath) => {
this.layer.removeLayerUsingPath(childPath);
});
MapEventProcessor.setMapOrderedLayerInfo(this.mapId, originalMapOrderedLayerInfo);
})
.catch((err) => logger.logError(err));
this.layer.refreshGeocoreLayers().catch((error) => logger.logError(error));
}

// Emit language changed event
Expand Down

0 comments on commit 7fa9e4a

Please sign in to comment.