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

Issue #2488 - Refresh GeoCore Layers on Language Change #2610

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
5 changes: 4 additions & 1 deletion packages/geoview-core/public/templates/demos-navigator.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ <h1><strong>Configurations Navigator</strong></h1>
<option value="fr">French</option>
<option value="unsupported">Not Supported</option>
</select>
<input type="checkbox" id="resetLayer" name="resetLayer" checked>
<label for="resetLayer">Reset Layers</label>
</div>
<p>Display Theme:</p>
<div class="selector">
Expand Down Expand Up @@ -272,8 +274,9 @@ <h1><strong>Configurations Navigator</strong></h1>

// ------------------ 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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function GuidePanel({ fullWidth }: GuidePanelType): JSX.Element {
fullWidth={fullWidth}
aria-label={t('guide.title')}
>
<Box sx={sxClasses.rightPanelContainer} aria-label={t('guide.title')} className="guidebox-container">
<Box sx={sxClasses.rightPanelContainer} aria-label={t('guide.title') || ''} className="guidebox-container">
<Box className="guideBox">{layersList[guideItemIndex]?.content}</Box>
</Box>
</Layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
49 changes: 49 additions & 0 deletions packages/geoview-core/src/geo/layer/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,55 @@ 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
*/
reloadGeocoreLayers(): 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
.filter((promise) => promise.status === 'fulfilled')
.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
10 changes: 6 additions & 4 deletions packages/geoview-core/src/geo/map/map-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -924,13 +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) {
logger.logInfo('reset layers not implemented yet');
// if flag is true, reload GeoCore layers
if (reloadLayers) {
this.layer.reloadGeocoreLayers().catch((error) => logger.logError(error));
}

// Emit language changed event
Expand Down
6 changes: 6 additions & 0 deletions packages/geoview-core/src/ui/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading