diff --git a/packages/geoview-core/public/templates/default-config.html b/packages/geoview-core/public/templates/default-config.html
index 74ce8a6b266..f2fd8f119c5 100644
--- a/packages/geoview-core/public/templates/default-config.html
+++ b/packages/geoview-core/public/templates/default-config.html
@@ -53,7 +53,8 @@
Default Configuration
2. Load with wrong JSON object
3. Load with bad config values
4. Load layers with bad config values
- 5. Load config from URL params
+ 5.A Load config from URL params
+ 5.B Load config from div params
6. Load config from file
7. Load config from function call
@@ -184,13 +185,45 @@ 4. Load layers with bad config values
-
5. Load config from URL params
+
5.A. Load config from URL params
Top
-
+
- This map loads it's configurations from the URL parameters by providing data-shared. If
- data-config is provided then it will override all loaded config from parameters.
+ This map loads it's configurations from the URL parameters by providing a data-shared attribute. If a
+ data-config attribute was also provided then the later will have its configuration overriden with config from url parameters.
+
+
+
+
+
5.B. Load config from div params
+
Top
+
+
+
+
+ This map loads it's configurations from the div parameters by providing a data-geocore-keys and optionally a data-geocore-endpoint.
diff --git a/packages/geoview-core/src/api/events/payloads/get-legends-payload.ts b/packages/geoview-core/src/api/events/payloads/get-legends-payload.ts
index 1e7f1e9b4ba..55104c4538e 100644
--- a/packages/geoview-core/src/api/events/payloads/get-legends-payload.ts
+++ b/packages/geoview-core/src/api/events/payloads/get-legends-payload.ts
@@ -170,8 +170,7 @@ export class GetLegendsPayload extends PayloadBaseClass {
* Static method used to create a get legends payload that will run a get legend on the specified layer path.
*
* @param {string | null} handlerName the handler name
- * @param {string} layerPath layer path to query
- * the set.
+ * @param {string} layerPath layer path to query the set.
*
* @returns {TypeQueryLegendPayload} the queryLegendPayload object created
*/
diff --git a/packages/geoview-core/src/core/utils/config/config-validation.ts b/packages/geoview-core/src/core/utils/config/config-validation.ts
index 148bf715652..fd951c973f9 100644
--- a/packages/geoview-core/src/core/utils/config/config-validation.ts
+++ b/packages/geoview-core/src/core/utils/config/config-validation.ts
@@ -717,7 +717,8 @@ export class ConfigValidation {
if (typeof config === 'object') {
Object.keys(config).forEach((key) => {
if (!key.startsWith('_') && typeof config[key] === 'object') {
- logger.logDebug(`Key=${key}`, config[key]);
+ // Leaving the commented line here in case a developer needs to quickly uncomment it again to troubleshoot
+ // logger.logDebug(`Key=${key}`, config[key]);
if (config?.[key]?.en || config?.[key]?.fr)
this.SynchronizeLocalizedString(Cast(config[key]), sourceKey, destinationKey);
// Avoid the 'geoviewLayerConfig' and 'parentLayerConfig' properties because they loop on themself and cause a
diff --git a/packages/geoview-core/src/core/utils/config/config.ts b/packages/geoview-core/src/core/utils/config/config.ts
index 51eea78cdf7..749289da116 100644
--- a/packages/geoview-core/src/core/utils/config/config.ts
+++ b/packages/geoview-core/src/core/utils/config/config.ts
@@ -152,7 +152,7 @@ export class Config {
let mapFeaturesConfig: TypeMapFeaturesConfig | undefined;
// check if inline div config has been passed
- const inlineDivConfig = InlineDivConfigReader.getMapFeaturesConfig(this.mapId, this.mapElement);
+ const inlineDivConfig = await InlineDivConfigReader.getMapFeaturesConfig(this.mapId, this.mapElement);
// use inline config if provided
if (inlineDivConfig) mapFeaturesConfig = { ...inlineDivConfig };
@@ -166,10 +166,7 @@ export class Config {
const shared = this.mapElement.getAttribute('data-shared');
if (shared === 'true') {
// check if config params have been passed
- const urlParamsConfig = await URLmapConfigReader.getMapFeaturesConfig(
- this.configValidation.defaultMapFeaturesConfig.serviceUrls.geocoreUrl,
- this.mapId
- );
+ const urlParamsConfig = await URLmapConfigReader.getMapFeaturesConfig(this.mapId);
// use the url params config if provided
if (urlParamsConfig) mapFeaturesConfig = { ...urlParamsConfig };
diff --git a/packages/geoview-core/src/core/utils/config/reader/div-config-reader.ts b/packages/geoview-core/src/core/utils/config/reader/div-config-reader.ts
index 1f91229d3b8..9066a004910 100644
--- a/packages/geoview-core/src/core/utils/config/reader/div-config-reader.ts
+++ b/packages/geoview-core/src/core/utils/config/reader/div-config-reader.ts
@@ -1,8 +1,10 @@
/* eslint-disable no-console */
-import { TypeMapFeaturesConfig } from '@/core/types/global-types';
-import { isJsonString, removeCommentsFromJSON } from '../../utilities';
+import { TypeJsonValue, TypeMapFeaturesConfig } from '@/core/types/global-types';
+import { getLocalizedMessage, isJsonString, removeCommentsFromJSON, replaceParams, showError } from '../../utilities';
import { logger } from '@/core/utils/logger';
import { api } from '@/app';
+import { ConfigValidation } from '../config-validation';
+import { UUIDmapConfigReader } from './uuid-config-reader';
/**
* A class to read the configuration of the GeoView map features from an online div. The configuration is provided in an HTML div
@@ -24,9 +26,9 @@ export class InlineDivConfigReader {
*
* @returns {TypeMapFeaturesConfig | undefined} The generated map features config object from inline map element.
*/
- static getMapFeaturesConfig(mapId: string, mapElement: Element): TypeMapFeaturesConfig | undefined {
- // create a new config object
- let mapConfig: TypeMapFeaturesConfig | undefined;
+ static async getMapFeaturesConfig(mapId: string, mapElement: Element): Promise {
+ // instanciate the configValidation object used to validate map config attributes and define default values.
+ const configValidation = new ConfigValidation();
let configObjStr = mapElement.getAttribute('data-config');
@@ -41,14 +43,53 @@ export class InlineDivConfigReader {
// Then, replace apostrophes preceded by a backslash with a single apostrophe
configObjStr = configObjStr.replace(/\\'/gm, "'");
- if (!isJsonString(configObjStr)) {
- logger.logWarning(`- Map: ${mapId} - Invalid JSON configuration object in div, a fallback strategy will be used -`);
- api.utilities.showError(mapId, api.utilities.getLocalizedMessage(mapId, 'validation.invalidConfig'), true);
- } else {
- mapConfig = { ...JSON.parse(configObjStr) };
+ if (isJsonString(configObjStr)) {
+ // Create the config
+ const gvConfig = JSON.parse(configObjStr);
+
+ // Read the geocore keys
+ const geocoreKeys = mapElement.getAttribute('data-geocore-keys');
+
+ // If any
+ if (geocoreKeys) {
+ try {
+ // Make sure we have a mapConfig.serviceUrls.geocoreUrl set by default
+ if (!gvConfig.serviceUrls)
+ gvConfig.serviceUrls = { geocoreUrl: configValidation.defaultMapFeaturesConfig.serviceUrls.geocoreUrl };
+
+ // If there's a data-geocore-endpoint attribute, use it as the geoCoreUrl
+ const geocoreEndpoint = mapElement.getAttribute('data-geocore-endpoint');
+ if (geocoreEndpoint) gvConfig.serviceUrls.geocoreUrl = geocoreEndpoint;
+
+ // Get the layers config
+ const promise = UUIDmapConfigReader.getGVConfigFromUUIDs(
+ gvConfig.serviceUrls.geocoreUrl,
+ gvConfig.displayLanguage || 'en',
+ geocoreKeys.split(',')
+ );
+ const listOfGeoviewLayerConfig = (await promise).layers;
+
+ // Append the layers to the config (possibly with others)
+ if (!gvConfig.map.listOfGeoviewLayerConfig) gvConfig.map.listOfGeoviewLayerConfig = [];
+ gvConfig.map.listOfGeoviewLayerConfig.push(...listOfGeoviewLayerConfig);
+ } catch (error) {
+ // Log
+ logger.logError('Failed to get the GeoView layers from url keys', mapElement.getAttribute('data-geocore-keys'), error);
+ const message = replaceParams([error as TypeJsonValue, mapId], getLocalizedMessage(mapId, 'validation.layer.loadfailed'));
+ showError(mapId, message);
+ }
+ }
+
+ // Return the config
+ return gvConfig;
}
+
+ // Log
+ logger.logWarning(`- Map: ${mapId} - Invalid JSON configuration object in div, a fallback strategy will be used -`);
+ api.utilities.showError(mapId, api.utilities.getLocalizedMessage(mapId, 'validation.invalidConfig'), true);
}
- return mapConfig;
+ // None
+ return undefined;
}
}
diff --git a/packages/geoview-core/src/core/utils/config/reader/url-config-reader.ts b/packages/geoview-core/src/core/utils/config/reader/url-config-reader.ts
index b053d734004..1c64211aafc 100644
--- a/packages/geoview-core/src/core/utils/config/reader/url-config-reader.ts
+++ b/packages/geoview-core/src/core/utils/config/reader/url-config-reader.ts
@@ -94,7 +94,7 @@ export class URLmapConfigReader {
*
* @returns {Promise} A map features configuration object generated from url parameters
*/
- static async getMapFeaturesConfig(baseUrl: string, mapId: string): Promise {
+ static async getMapFeaturesConfig(mapId: string): Promise {
// instanciate the configValidation object used to validate map config attributes and define default values.
const configValidation = new ConfigValidation();
@@ -132,7 +132,7 @@ export class URLmapConfigReader {
try {
// Get the layers config
const promise = UUIDmapConfigReader.getGVConfigFromUUIDs(
- baseUrl,
+ configValidation.defaultMapFeaturesConfig.serviceUrls.geocoreUrl,
displayLanguage.split('-')[0],
urlParams.keys.toString().split(',')
);
@@ -172,7 +172,7 @@ export class URLmapConfigReader {
extraOptions: {},
},
serviceUrls: {
- geocoreUrl: baseUrl,
+ geocoreUrl: configValidation.defaultMapFeaturesConfig.serviceUrls.geocoreUrl,
},
components,
corePackages,
@@ -182,7 +182,7 @@ export class URLmapConfigReader {
}
// Trace the detail config read from url
- logger.logTraceDetailed('URL Config - ', mapConfig);
+ logger.logTraceDetailed('URL Config - ', mapId, mapConfig);
return mapConfig;
}