From 38d80d43a5a8086a2b2c924a246e726a97984700 Mon Sep 17 00:00:00 2001 From: MatthewMuehlhauserNRCan Date: Wed, 20 Nov 2024 11:20:49 -0500 Subject: [PATCH 1/6] Refresh layers on language change (2488) and CSS for datatable scrolling --- .../geoview-core/src/geo/map/map-viewer.ts | 39 ++++++++++++++++++- packages/geoview-core/src/ui/style/style.css | 6 +++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/geoview-core/src/geo/map/map-viewer.ts b/packages/geoview-core/src/geo/map/map-viewer.ts index c1293e1846d..b67d0a7fc4f 100644 --- a/packages/geoview-core/src/geo/map/map-viewer.ts +++ b/packages/geoview-core/src/geo/map/map-viewer.ts @@ -925,12 +925,49 @@ export class MapViewer { * @returns {Promise<[void, void]>} */ setLanguage(displayLanguage: TypeDisplayLanguage, resetLayer?: boolean | false): Promise<[void, void]> { + // If the language hasn't changed don't do anything + if (AppEventProcessor.getDisplayLanguage(this.mapId) === displayLanguage) return Promise.resolve([undefined, undefined]); if (VALID_DISPLAY_LANGUAGE.includes(displayLanguage)) { const promise = AppEventProcessor.setDisplayLanguage(this.mapId, displayLanguage); // if flag is true, check if config support the layers change and apply if (resetLayer) { - logger.logInfo('reset layers not implemented yet'); + const re = /[\w\d]{8}-[\w\d]{4}-[\w\d]{4}-[\w\d]{4}-[\w\d]{12}/g; + + 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 (re.test(config.geoviewLayerConfig.geoviewLayerId) && config.parentLayerConfig === undefined) { + return config; + } + return false; + }) + .map((config) => { + // Remove and add back in GeoCore Layers and return their promises + const uuid = config.geoviewLayerConfig.geoviewLayerId.match(re)![0]; + 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)); } // Emit language changed event diff --git a/packages/geoview-core/src/ui/style/style.css b/packages/geoview-core/src/ui/style/style.css index ef205bdc9d3..35952a22f1d 100644 --- a/packages/geoview-core/src/ui/style/style.css +++ b/packages/geoview-core/src/ui/style/style.css @@ -37,3 +37,9 @@ Hold viewer specific css not inside theme .guideBox p img { vertical-align: bottom; } + +/* smooth data table scrolling */ +.MuiTableContainer-root { + contain: paint; + will-change: transform; +} \ No newline at end of file From 4e6e9c5b6f0f1b28991ea3f06a9dd91e7e9120d3 Mon Sep 17 00:00:00 2001 From: MatthewMuehlhauserNRCan Date: Thu, 21 Nov 2024 08:21:17 -0500 Subject: [PATCH 2/6] Added Reset Layer Checkmark to Navigator page --- .../geoview-core/public/templates/demos-navigator.html | 5 ++++- packages/geoview-core/src/geo/map/map-viewer.ts | 9 ++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/geoview-core/public/templates/demos-navigator.html b/packages/geoview-core/public/templates/demos-navigator.html index 45ff08ce426..d90fe683a05 100644 --- a/packages/geoview-core/public/templates/demos-navigator.html +++ b/packages/geoview-core/public/templates/demos-navigator.html @@ -162,6 +162,8 @@

Configurations Navigator

+ +

Display Theme:

@@ -272,8 +274,9 @@

Configurations Navigator

// ------------------ SWITCHER SECTION START ----------------------------------------- const switchLang = document.getElementById('switchLang'); + const resetLayer = document.getElementById('resetLayer'); switchLang.addEventListener('change', (e) => { - cgpv.api.maps['sandboxMap'].setLanguage(e.target.value); + cgpv.api.maps['sandboxMap'].setLanguage(e.target.value, resetLayer.checked); }); const switchThemeElem = document.getElementById('switchTheme'); diff --git a/packages/geoview-core/src/geo/map/map-viewer.ts b/packages/geoview-core/src/geo/map/map-viewer.ts index b67d0a7fc4f..8c16c304728 100644 --- a/packages/geoview-core/src/geo/map/map-viewer.ts +++ b/packages/geoview-core/src/geo/map/map-viewer.ts @@ -931,9 +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 re = /[\w\d]{8}-[\w\d]{4}-[\w\d]{4}-[\w\d]{4}-[\w\d]{12}/g; + 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 @@ -942,14 +941,14 @@ export class MapViewer { configs .filter((config) => { // Filter to just Geocore layers and not child layers - if (re.test(config.geoviewLayerConfig.geoviewLayerId) && config.parentLayerConfig === undefined) { - return config; + 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.match(re)![0]; + const uuid = config.geoviewLayerConfig.geoviewLayerId; this.layer.removeLayerUsingPath(config.layerPath); return this.layer.addGeoviewLayerByGeoCoreUUID(uuid); }) From d89a22389cc7f8f8a0ddf977c7e8994ce43a98f8 Mon Sep 17 00:00:00 2001 From: MatthewMuehlhauserNRCan Date: Tue, 26 Nov 2024 08:06:31 -0500 Subject: [PATCH 3/6] 2488 refresh layers alternate solution --- packages/geoview-core/src/geo/layer/layer.ts | 48 +++++++++++++++++++ .../geoview-core/src/geo/map/map-viewer.ts | 36 +------------- 2 files changed, 49 insertions(+), 35 deletions(-) diff --git a/packages/geoview-core/src/geo/layer/layer.ts b/packages/geoview-core/src/geo/layer/layer.ts index 358071f6c3b..3a841a5f054 100644 --- a/packages/geoview-core/src/geo/layer/layer.ts +++ b/packages/geoview-core/src/geo/layer/layer.ts @@ -559,6 +559,54 @@ export class LayerApi { logger.logError(`Duplicate use of geoview layer identifier ${mapConfigLayerEntry.geoviewLayerId} on map ${this.getMapId()}`); } + /** + * Refreshes GeoCore Layers + * @returns {Promise} A promise which resolves when done refreshing + */ + refreshGeocoreLayers(): Promise { + const configs = this.getLayerEntryConfigs(); + const originalMapOrderedLayerInfo = MapEventProcessor.getMapOrderedLayerInfo(this.getMapId()); + const promisesOfGeoCoreGeoviewLayers: Promise[] = []; + + 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) + .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 diff --git a/packages/geoview-core/src/geo/map/map-viewer.ts b/packages/geoview-core/src/geo/map/map-viewer.ts index 8c16c304728..6a41a38813a 100644 --- a/packages/geoview-core/src/geo/map/map-viewer.ts +++ b/packages/geoview-core/src/geo/map/map-viewer.ts @@ -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 From 5e673249964c1f0323cc2de461173f88a17055e2 Mon Sep 17 00:00:00 2001 From: MatthewMuehlhauserNRCan Date: Wed, 27 Nov 2024 11:36:20 -0500 Subject: [PATCH 4/6] Ensure registered layer paths are removed --- .../src/geo/layer/layer-sets/abstract-layer-set.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/geoview-core/src/geo/layer/layer-sets/abstract-layer-set.ts b/packages/geoview-core/src/geo/layer/layer-sets/abstract-layer-set.ts index 0b9e30c1237..c34b761eff2 100644 --- a/packages/geoview-core/src/geo/layer/layer-sets/abstract-layer-set.ts +++ b/packages/geoview-core/src/geo/layer/layer-sets/abstract-layer-set.ts @@ -285,6 +285,9 @@ export abstract class AbstractLayerSet { // Delete the result set for the layer path delete this.resultSet[layerPath]; + // Remove layer path from registered layer paths + this.#registeredLayerLayerPaths = this.#registeredLayerLayerPaths.filter((registeredLayer) => registeredLayer !== layerPath); + // Inform that the layer set has been updated this.onLayerSetUpdatedProcess(layerPath); } From f5d0060f423bc311a7136d21f158274c113b3525 Mon Sep 17 00:00:00 2001 From: MatthewMuehlhauserNRCan Date: Thu, 28 Nov 2024 12:09:33 -0500 Subject: [PATCH 5/6] Update method name and comments. --- .../src/core/components/guide/guide-panel.tsx | 2 +- packages/geoview-core/src/geo/layer/layer.ts | 2 +- packages/geoview-core/src/geo/map/map-viewer.ts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/geoview-core/src/core/components/guide/guide-panel.tsx b/packages/geoview-core/src/core/components/guide/guide-panel.tsx index b8fcda7fd14..83f05df8f0e 100644 --- a/packages/geoview-core/src/core/components/guide/guide-panel.tsx +++ b/packages/geoview-core/src/core/components/guide/guide-panel.tsx @@ -105,7 +105,7 @@ export function GuidePanel({ fullWidth }: GuidePanelType): JSX.Element { fullWidth={fullWidth} aria-label={t('guide.title')} > - + {layersList[guideItemIndex]?.content} diff --git a/packages/geoview-core/src/geo/layer/layer.ts b/packages/geoview-core/src/geo/layer/layer.ts index 3a841a5f054..2e4424f5bd7 100644 --- a/packages/geoview-core/src/geo/layer/layer.ts +++ b/packages/geoview-core/src/geo/layer/layer.ts @@ -563,7 +563,7 @@ export class LayerApi { * Refreshes GeoCore Layers * @returns {Promise} A promise which resolves when done refreshing */ - refreshGeocoreLayers(): Promise { + reloadGeocoreLayers(): Promise { const configs = this.getLayerEntryConfigs(); const originalMapOrderedLayerInfo = MapEventProcessor.getMapOrderedLayerInfo(this.getMapId()); const promisesOfGeoCoreGeoviewLayers: Promise[] = []; diff --git a/packages/geoview-core/src/geo/map/map-viewer.ts b/packages/geoview-core/src/geo/map/map-viewer.ts index 6a41a38813a..b860c26cc8a 100644 --- a/packages/geoview-core/src/geo/map/map-viewer.ts +++ b/packages/geoview-core/src/geo/map/map-viewer.ts @@ -924,15 +924,15 @@ export class MapViewer { * @param {boolean} resetLayer - Optional flag to ask viewer to reload layers with the new localize language * @returns {Promise<[void, void]>} */ - setLanguage(displayLanguage: TypeDisplayLanguage, resetLayer?: boolean | false): Promise<[void, void]> { + setLanguage(displayLanguage: TypeDisplayLanguage, reloadLayers?: boolean | false): Promise<[void, void]> { // If the language hasn't changed don't do anything if (AppEventProcessor.getDisplayLanguage(this.mapId) === displayLanguage) return Promise.resolve([undefined, undefined]); if (VALID_DISPLAY_LANGUAGE.includes(displayLanguage)) { const promise = AppEventProcessor.setDisplayLanguage(this.mapId, displayLanguage); - // if flag is true, check if config support the layers change and apply - if (resetLayer) { - this.layer.refreshGeocoreLayers().catch((error) => logger.logError(error)); + // if flag is true, reload GeoCore layers + if (reloadLayers) { + this.layer.reloadGeocoreLayers().catch((error) => logger.logError(error)); } // Emit language changed event From 14f87ffc7a8ac9c14420db0e08f44dfb15d75bd0 Mon Sep 17 00:00:00 2001 From: MatthewMuehlhauserNRCan Date: Thu, 28 Nov 2024 13:06:29 -0500 Subject: [PATCH 6/6] Added filter to Promise.allSettled --- packages/geoview-core/src/geo/layer/layer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/geoview-core/src/geo/layer/layer.ts b/packages/geoview-core/src/geo/layer/layer.ts index 2e4424f5bd7..d9b9425f6ee 100644 --- a/packages/geoview-core/src/geo/layer/layer.ts +++ b/packages/geoview-core/src/geo/layer/layer.ts @@ -586,6 +586,7 @@ export class LayerApi { return Promise.allSettled(promisesOfGeoCoreGeoviewLayers) .then((promisedLayers) => { promisedLayers + .filter((promise) => promise.status === 'fulfilled') .map((promise) => promise as PromiseFulfilledResult) .forEach((promise) => { promise.value.forEach((geoviewLayerConfig) => {