Skip to content

Commit

Permalink
Input and internal schema validation plus maxExtent default issue (#2124
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ychoquet authored May 14, 2024
1 parent c674a73 commit daaaff7
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
TypeNavBarProps,
TypeOverviewMapProps,
TypeServiceUrls,
TypeValidMapProjectionCodes,
TypeValidVersions,
VALID_PROJECTION_CODES,
VALID_VERSIONS,
Expand All @@ -33,6 +34,7 @@ import {
CV_DEFAULT_MAP_FEATURE_CONFIG,
CV_MAP_CENTER,
CV_MAP_CONFIG_SCHEMA_PATH,
CV_MAP_EXTENTS,
} from '@config/types/config-constants';
import { isvalidComparedToSchema } from '@config/utils';
import { isJsonString, removeCommentsFromJSON } from '@/core/utils/utilities';
Expand Down Expand Up @@ -87,7 +89,8 @@ export class MapFeatureConfig {
/**
* ISO 639-1 code indicating the languages supported by the configuration file. It will use value(s) provided here to
* access bilangual configuration nodes. For value(s) provided here, each bilingual configuration node MUST provide a value.
* */
*/
// TODO: Delete the suportedLanguages property from the viewer.
suportedLanguages: TypeListOfLocalizedLanguages;

/**
Expand Down Expand Up @@ -116,7 +119,9 @@ export class MapFeatureConfig {
// set map configuration
const gvMap = clonedJsonConfig.map as TypeJsonObject;
if (gvMap) (gvMap.listOfGeoviewLayerConfig as TypeJsonArray) = (gvMap.listOfGeoviewLayerConfig || []) as TypeJsonArray;
this.map = Cast<TypeMapConfig>(defaultsDeep(gvMap, CV_DEFAULT_MAP_FEATURE_CONFIG.map));
this.map = Cast<TypeMapConfig>(
defaultsDeep(gvMap, this.#getDefaultMapConfig(gvMap?.viewSettings?.projection as TypeValidMapProjectionCodes))
);
this.map.listOfGeoviewLayerConfig = (gvMap.listOfGeoviewLayerConfig as TypeJsonArray)
.map((geoviewLayerConfig) => {
return MapFeatureConfig.nodeFactory(geoviewLayerConfig, this.#language, this);
Expand All @@ -136,7 +141,7 @@ export class MapFeatureConfig {
...((clonedJsonConfig.externalPackages || CV_DEFAULT_MAP_FEATURE_CONFIG.externalPackages) as TypeExternalPackages),
];
this.suportedLanguages = [
...((clonedJsonConfig.suportedLanguages || CV_DEFAULT_MAP_FEATURE_CONFIG.supportedLanguages) as TypeListOfLocalizedLanguages),
...((clonedJsonConfig.suportedLanguages || CV_DEFAULT_MAP_FEATURE_CONFIG.suportedLanguages) as TypeListOfLocalizedLanguages),
];
this.schemaVersionUsed = (clonedJsonConfig.schemaVersionUsed as TypeValidVersions) || CV_DEFAULT_MAP_FEATURE_CONFIG.schemaVersionUsed;
this.#errorDetected = this.#errorDetected || !isvalidComparedToSchema(CV_MAP_CONFIG_SCHEMA_PATH, this);
Expand Down Expand Up @@ -272,6 +277,21 @@ export class MapFeatureConfig {
return undefined;
}

/**
* Get the default values for the mapFeatureConfig.map using the projection code.
* @param {TypeValidMapProjectionCodes} projection The projection code.
*
* @returns {TypeMapConfig} The default map configuration associated to the projection.
*/
#getDefaultMapConfig(projection?: TypeValidMapProjectionCodes): TypeMapConfig {

Check warning on line 286 in packages/geoview-core/src/api/config/types/classes/map-feature-config.ts

View workflow job for this annotation

GitHub Actions / Build demo files / build-geoview

Expected 'this' to be used by class private method #getDefaultMapConfig
const proj =
projection && VALID_PROJECTION_CODES.includes(projection) ? projection : CV_DEFAULT_MAP_FEATURE_CONFIG.map.viewSettings.projection;
const mapConfig = cloneDeep(CV_DEFAULT_MAP_FEATURE_CONFIG.map);
mapConfig.viewSettings.maxExtent = [...CV_MAP_EXTENTS[proj]];

return mapConfig;
}

/**
* This method attempts to recover a valid configuration following the detection of an error. It will attempt to replace the
* erroneous values with the default values associated with the properties in error. There is a limit to this recovery
Expand Down
52 changes: 18 additions & 34 deletions packages/geoview-core/src/api/config/types/config-constants.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
// TODO: When we are done with the config extraction, do a review of all the constants, types and utilities to
// TODOCONT: remove code duplication.

import { AbstractGeoviewLayerConfig } from '@config/types/classes/geoview-config/abstract-geoview-layer-config';
import { LayerEntryTypesKey, LayerTypesKey, TypeGeoviewLayerType } from '@config/types/config-types';
import {
TypeAppBarProps,
TypeBasemapId,
TypeBasemapOptions,
TypeDisplayTheme,
TypeExternalPackages,
TypeInteraction,
TypeLayerEntryType,
TypeListOfLocalizedLanguages,
TypeMapConfig,
TypeNavBarProps,
TypeOverviewMapProps,
TypeServiceUrls,
TypeValidMapProjectionCodes,
TypeValidVersions,
TypeViewSettings,
} from '@config/types/map-schema-types';
import { Cast, LayerEntryTypesKey, LayerTypesKey, TypeGeoviewLayerType } from '@config/types/config-types';
import { TypeBasemapId, TypeLayerEntryType, TypeValidMapProjectionCodes } from '@config/types/map-schema-types';
import { MapFeatureConfig } from '@config/types/classes/map-feature-config';

/** The default geocore url */
export const CV_CONFIG_GEOCORE_URL = 'https://geocore-stage.api.geo.ca';
Expand Down Expand Up @@ -136,9 +120,9 @@ export const CV_MAP_EXTENTS: Record<TypeValidMapProjectionCodes, number[]> = {
* Definition of the MapFeatureConfig default values. All the default values that applies to the map feature configuration are
* defined here.
*/
export const CV_DEFAULT_MAP_FEATURE_CONFIG = {
export const CV_DEFAULT_MAP_FEATURE_CONFIG = Cast<MapFeatureConfig>({
map: {
interaction: 'dynamic' as TypeInteraction,
interaction: 'dynamic',
viewSettings: {
initialView: {
zoomAndCenter: [3.5, [-90, 60]],
Expand All @@ -149,29 +133,29 @@ export const CV_DEFAULT_MAP_FEATURE_CONFIG = {
maxZoom: 50,
maxExtent: [-125, 30, -60, 89],
projection: 3978,
} as TypeViewSettings,
},
basemapOptions: {
basemapId: 'transport',
shaded: true,
labeled: true,
} as TypeBasemapOptions,
listOfGeoviewLayerConfig: [] as AbstractGeoviewLayerConfig[],
},
listOfGeoviewLayerConfig: [],
extraOptions: {},
} as TypeMapConfig,
theme: 'geo.ca' as TypeDisplayTheme,
},
theme: 'geo.ca',
components: ['north-arrow', 'overview-map'],
appBar: { tabs: { core: ['geolocator'] } } as TypeAppBarProps,
navBar: ['zoom', 'fullscreen', 'home'] as TypeNavBarProps,
appBar: { tabs: { core: ['geolocator'] } },
navBar: ['zoom', 'fullscreen', 'home'],
corePackages: [],
overviewMap: undefined as TypeOverviewMapProps | undefined,
externalPackages: [] as TypeExternalPackages,
overviewMap: undefined,
externalPackages: [],
serviceUrls: {
geocoreUrl: CV_CONFIG_GEOCORE_URL,
geolocator: CV_CONFIG_GEOLOCATOR_URL,
} as TypeServiceUrls,
supportedLanguages: ['en', 'fr'] as TypeListOfLocalizedLanguages,
schemaVersionUsed: '1.0' as TypeValidVersions,
};
},
suportedLanguages: ['en', 'fr'],
schemaVersionUsed: '1.0',
});

/**
* Definition of the initial settings default values.
Expand Down
Loading

0 comments on commit daaaff7

Please sign in to comment.