Skip to content

Commit

Permalink
Integration of the source property in the schema and renaming some fi…
Browse files Browse the repository at this point in the history
…elds
  • Loading branch information
ychoquet committed May 8, 2024
1 parent 6662e0e commit 8d06a8a
Show file tree
Hide file tree
Showing 13 changed files with 602 additions and 527 deletions.
160 changes: 153 additions & 7 deletions packages/geoview-core/public/templates/config-sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ <h1><strong>Sandbox Configuration</strong></h1>
'map': {
'interaction': 'dynamic',
'viewSettings': {
'minZoom': 5,
'projection': 3978
},
'basemapOptions': {
Expand All @@ -109,18 +108,165 @@ <h1><strong>Sandbox Configuration</strong></h1>
{
'geoviewLayerId': 'wmsLYR1',
'geoviewLayerName': {
'en': 'earthquakes'
'en': 'Earthquakes',
'fr': 'Tremblements de terre'
},
'metadataAccessPath': {
'fr': 'https://maps-cartes.services.geo.ca/server_serveur/rest/services/NRCan/earthquakes_en/MapServer/'
'accessPath': {
'en': 'https://maps-cartes.services.geo.ca/server_serveur/rest/services/NRCan/earthquakes_en/MapServer/',
'fr': 'https://maps-cartes.services.geo.ca/server_serveur/rest/services/NRCan/earthquakes_fr/MapServer/'
},
'geoviewLayerType': 'esriDynamic',
'geoviewLayerType': 'esriFeature',
'listOfLayerEntryConfig': [
{
'layerId': '0'
'id': '0',
'geometryType': 'point',
'name': {
'en': 'Earthquakes 1980-1990',
'fr': ' Tremblements de terre 1980-1990'
},
"initialSettings": {
"controls": {
"query": true
},
"states": {
"queryable": true
}
},
'attributtions': 'Ressources naturelles Canada, Secteur des terres et des minéraux, Commission Géologique du Canada, Service canadien d\'information sur les risques',
'source': {
'layerFilter': '',
'maxRecordCount': 0,
'featureInfo': {
'nameField': 'date',
'outfields': [
{
'name': 'magnitude_codelist',
'alias': 'magnitude_codelist',
'type': 'date',
'domaine': []
},
{
'name': 'magnitude',
'alias': 'Magnitude',
'type': 'number',
'domaine': []
},
{
'name': 'magnitude_type',
'alias': 'Magnitude Type',
'type': 'string',
'domaine': []
},
{
'name': 'date',
'alias': 'Date',
'type': 'string',
'domaine': []
},
{
'name': 'place',
'alias': 'Place',
'type': 'string',
'domaine': []
},
{
'name': 'depth',
'alias': 'Depth',
'type': 'number',
'domaine': []
},
{
'name': 'latitude',
'alias': 'Latitude',
'type': 'number',
'domaine': []
},
{
'name': 'longitude',
'alias': 'Longitude',
'type': 'number',
'domaine': []
},
{
'name': 'OBJECTID',
'alias': 'OBJECTID',
'type': 'number',
'domaine': []
}
]
}
}
},
{
'layerId': '1'
'id': '1',
'name': {
'en': 'Earthquakes 1990-2000',
'fr': ' Tremblements de terre 1990-2000'
},
'attributtions': 'Ressources naturelles Canada, Secteur des terres et des minéraux, Commission Géologique du Canada, Service canadien d\'information sur les risques',
'source': {
'layerFilter': '',
'maxRecordCount': 0,
'featureInfo': {
'nameField': 'date',
'outfields': [
{
'name': 'magnitude_codelist',
'alias': 'magnitude_codelist',
'type': 'date',
'domaine': []
},
{
'name': 'magnitude',
'alias': 'Magnitude',
'type': 'number',
'domaine': []
},
{
'name': 'magnitude_type',
'alias': 'Magnitude Type',
'type': 'string',
'domaine': []
},
{
'name': 'date',
'alias': 'Date',
'type': 'string',
'domaine': []
},
{
'name': 'place',
'alias': 'Place',
'type': 'string',
'domaine': []
},
{
'name': 'depth',
'alias': 'Depth',
'type': 'number',
'domaine': []
},
{
'name': 'latitude',
'alias': 'Latitude',
'type': 'number',
'domaine': []
},
{
'name': 'longitude',
'alias': 'Longitude',
'type': 'number',
'domaine': []
},
{
'name': 'OBJECTID',
'alias': 'OBJECTID',
'type': 'number',
'domaine': []
}
]
}
}
}
]
}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ export abstract class AbstractGeoviewLayerConfig {
*/
geoviewLayerName: string;

/** A flag used to indicate that the layer is a GeoCore layer (default: false). When true, geoviewLayerId must be a geocoreId. */
isGeocore: boolean;

/** The GeoView layer access path (English/French). */
metadataAccessPath: string;
accessPath: string;

/** Date format used by the service endpoint. */
serviceDateFormat: string | undefined;
Expand All @@ -50,7 +53,7 @@ export abstract class AbstractGeoviewLayerConfig {
* Initial settings to apply to the GeoView layer at creation time.
* This attribute is allowed only if listOfLayerEntryConfig.length > 1.
*/
initialSettings: TypeLayerInitialSettings;
#initialSettings: TypeLayerInitialSettings;

/** The layer entries to use from the GeoView layer. */
listOfLayerEntryConfig: ConfigBaseClass[] = [];
Expand All @@ -66,12 +69,17 @@ export abstract class AbstractGeoviewLayerConfig {
this.#mapFeatureConfig = mapFeatureConfig;
this.#language = language;

this.isGeocore = (this.#originalgeoviewLayerConfig.isGeocore as boolean) || false;

this.#initialSettings = Cast<TypeLayerInitialSettings>(
defaultsDeep(this.#originalgeoviewLayerConfig.initialSettings, CV_DEFAULT_LAYER_INITIAL_SETTINGS)
);
// Topmost layer must be a layer group or a leaf node.
if ((this.#originalgeoviewLayerConfig.listOfLayerEntryConfig as TypeJsonArray).length > 1)
(this.#originalgeoviewLayerConfig.listOfLayerEntryConfig as TypeJsonArray) = [
{
layerId: this.#originalgeoviewLayerConfig.geoviewLayerId,
initialSettings: defaultsDeep(this.#originalgeoviewLayerConfig.initialSettings, CV_DEFAULT_LAYER_INITIAL_SETTINGS),
initialSettings: this.#initialSettings as TypeJsonObject,
layerName: { ...(this.#originalgeoviewLayerConfig.geoviewLayerName as object) },
entryType: CV_CONST_SUB_LAYER_TYPES.GROUP as TypeJsonObject,
listOfLayerEntryConfig: this.#originalgeoviewLayerConfig.listOfLayerEntryConfig,
Expand All @@ -80,16 +88,13 @@ export abstract class AbstractGeoviewLayerConfig {

this.geoviewLayerId = (this.#originalgeoviewLayerConfig.geoviewLayerId || generateId()) as string;
this.geoviewLayerName = normalizeLocalizedString(this.#originalgeoviewLayerConfig.geoviewLayerName)![this.#language]!;
this.metadataAccessPath = normalizeLocalizedString(this.#originalgeoviewLayerConfig.metadataAccessPath)![this.#language]!;
this.accessPath = normalizeLocalizedString(this.#originalgeoviewLayerConfig.accessPath)![this.#language]!;
this.serviceDateFormat = (this.#originalgeoviewLayerConfig.serviceDateFormat || 'DD/MM/YYYY HH:MM:SSZ') as string;
this.externalDateFormat = (this.#originalgeoviewLayerConfig.externalDateFormat || 'DD/MM/YYYY HH:MM:SSZ') as string;
this.initialSettings = Cast<TypeLayerInitialSettings>(
defaultsDeep(this.#originalgeoviewLayerConfig.initialSettings, CV_DEFAULT_LAYER_INITIAL_SETTINGS)
);
this.listOfLayerEntryConfig = (this.#originalgeoviewLayerConfig.listOfLayerEntryConfig as TypeJsonArray)
.map((subLayerConfig) => {
if (layerEntryIsGroupLayer(subLayerConfig)) return new GroupLayerEntryConfig(subLayerConfig, this.initialSettings, language, this);
return this.createLeafNode(subLayerConfig, this.initialSettings, language, this);
if (layerEntryIsGroupLayer(subLayerConfig)) return new GroupLayerEntryConfig(subLayerConfig, this.#initialSettings, language, this);
return this.createLeafNode(subLayerConfig, this.#initialSettings, language, this);
})
.filter((subLayerConfig) => {
return subLayerConfig;
Expand Down Expand Up @@ -139,7 +144,7 @@ export abstract class AbstractGeoviewLayerConfig {
* type needed.
*
* @param {TypeJsonObject} layerConfig The sublayer configuration.
* @param {TypeLayerInitialSettings} initialSettings The initial settings inherited.
* @param {TypeLayerInitialSettings | TypeJsonObject} initialSettings The initial settings inherited.
* @param {TypeDisplayLanguage} language The initial language to use when interacting with the geoview layer.
* @param {AbstractGeoviewLayerConfig} geoviewConfig The GeoView instance that owns the sublayer.
* @param {ConfigBaseClass} parentNode The The parent node that owns this layer or undefined if it is the root layer..
Expand All @@ -149,7 +154,7 @@ export abstract class AbstractGeoviewLayerConfig {
*/
abstract createLeafNode(
layerConfig: TypeJsonObject,
initialSettings: TypeLayerInitialSettings,
initialSettings: TypeLayerInitialSettings | TypeJsonObject,
language: TypeDisplayLanguage,
geoviewConfig: AbstractGeoviewLayerConfig,
parentNode?: ConfigBaseClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export class EsriDynamicLayerConfig extends AbstractGeoviewLayerConfig {
if (!this.geoviewLayerId) {
throw new Error(`geoviewLayerId is mandatory for GeoView layer of type ${this.geoviewLayerType}.`);
}
if (!this.metadataAccessPath) {
throw new Error(`metadataAccessPath is mandatory for GeoView layer ${this.geoviewLayerId} of type ${this.geoviewLayerType}.`);
}
this.validate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export class EsriFeatureLayerConfig extends AbstractGeoviewLayerConfig {
if (!this.geoviewLayerId) {
throw new Error(`geoviewLayerId is mandatory for GeoView layer of type ${this.geoviewLayerType}.`);
}
if (!this.metadataAccessPath) {
throw new Error(`metadataAccessPath is mandatory for GeoView layer ${this.geoviewLayerId} of type ${this.geoviewLayerType}.`);
}
this.validate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import cloneDeep from 'lodash/cloneDeep';
import defaultsDeep from 'lodash/defaultsDeep';

import {
Extent,
TypeAppBarProps,
TypeDisplayLanguage,
TypeDisplayTheme,
Expand Down Expand Up @@ -294,17 +293,6 @@ export class MapFeatureConfig {
this.schemaVersionUsed = VALID_VERSIONS.includes(this.schemaVersionUsed!)
? this.schemaVersionUsed
: CV_DEFAULT_MAP_FEATURE_CONFIG.schemaVersionUsed!;

const minZoom = this.map.viewSettings.minZoom!;
this.map.viewSettings.minZoom =
!Number.isNaN(minZoom) && minZoom >= 0 && minZoom <= 50 ? minZoom : CV_DEFAULT_MAP_FEATURE_CONFIG.map.viewSettings.minZoom;

const maxZoom = this.map.viewSettings.maxZoom!;
this.map.viewSettings.maxZoom =
!Number.isNaN(maxZoom) && maxZoom >= 0 && maxZoom <= 50 ? maxZoom : CV_DEFAULT_MAP_FEATURE_CONFIG.map.viewSettings.maxZoom;

this.#validateMaxExtent();

this.#logModifs();
}

Expand Down Expand Up @@ -349,26 +337,6 @@ export class MapFeatureConfig {
: CV_DEFAULT_MAP_FEATURE_CONFIG.map.basemapOptions.labeled;
}

/**
* Validate the maxExtent property.
* @private
*/
#validateMaxExtent(): void {
const { projection } = this.map.viewSettings;
const center = this.map.viewSettings.initialView!.zoomAndCenter![1];
const maxExtent = this.map.viewSettings.maxExtent!;
// TODO: Which one do we want, the commented one or the next one?
// const [extentMinX, extentMinY, extentMaxX, extentMaxY] = getMinOrMaxExtents(maxExtent, CV_MAP_EXTENTS[projection], 'min');
const [extentMinX, extentMinY, extentMaxX, extentMaxY] = maxExtent;

const minX = !Number.isNaN(extentMinX) && extentMinX < center[0] ? extentMinX : CV_MAP_CENTER[projection].long[0];
const minY = !Number.isNaN(extentMinY) && extentMinY < center[1] ? extentMinY : CV_MAP_CENTER[projection].lat[0];
const maxX = !Number.isNaN(extentMaxX) && extentMaxX > center[0] ? extentMaxX : CV_MAP_CENTER[projection].long[1];
const maxY = !Number.isNaN(extentMaxY) && extentMaxY > center[1] ? extentMaxY : CV_MAP_CENTER[projection].lat[1];

this.map.viewSettings.maxExtent! = [minX, minY, maxX, maxY] as Extent;
}

/**
* Log modifications made to configuration by the validator. This method compares the values provided by the user to the
* final values of the configuration and log all modifications made to the config.
Expand Down
Loading

0 comments on commit 8d06a8a

Please sign in to comment.