Skip to content

Commit

Permalink
2259 osdp geocore (#2535)
Browse files Browse the repository at this point in the history
* feat(core): Apply custom geocore config
Closes #2259

* fix build

* fix uuid, init geochart

* fix tab problem and layer def for date regex

* rebase pnpm lock1

* Fix comments

* fix commment

* Fix outFields unwanted present

* Fix build

* fix typo

* fix more typo

---------

Co-authored-by: jolevesq <[email protected]>
  • Loading branch information
jolevesq and jolevesq authored Oct 4, 2024
1 parent 0b83f14 commit 8f4d8b5
Show file tree
Hide file tree
Showing 21 changed files with 286 additions and 103 deletions.
13 changes: 12 additions & 1 deletion common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"map": {
"interaction": "dynamic",
"viewSettings": {
"projection": 3978
},
"basemapOptions": {
"basemapId": "transport",
"shaded": true,
"labeled": false
},
"listOfGeoviewLayerConfig": [
{
"geoviewLayerType": "geoCore",
"geoviewLayerId": "ea4c0bdb-a63f-49a4-b14a-09c1560aad0b"
},
{
"geoviewLayerId": "21b821cf-0f1c-40ee-8925-eab12d357668",
"geoviewLayerType": "geoCore"
}
]
},
"components": [
"overview-map"
],
"overviewMap": {
"hideOnZoom": 7
},
"footerBar": {
"tabs": {
"core": [
"legend",
"layers",
"details",
"geochart",
"data-table"
]
}
},
"corePackages": [],
"theme": "geo.ca"
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ <h1><strong>Configurations Navigator</strong></h1>
<option value="./configs/navigator/23-csv.json">Layer - CSV -</option>
<option value="./configs/navigator/24-vector-tile.json">Layer - Vector Tile -</option>
<option value="./configs/navigator/25-geojson-multi.json">Layer - GeoJSON MutiPolygon -</option>
<option value="./configs/navigator/27-geocore-custom.json">Layer - GeoCore Custom Config -</option>
</select>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h4 id="HMap1">Water</h4>
'map': {
'interaction': 'dynamic',
'viewSettings': {
'projection': 3978
'projection': 3857
},
'basemapOptions': {
'basemapId': 'transport',
Expand Down
9 changes: 8 additions & 1 deletion packages/geoview-core/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@
},
"domain": {
"description": "An array of values that constitute the domain.",
"type": "array"
"oneOf": [
{
"type": "null"
},
{
"type": "array"
}
]
}
},
"required": ["name", "alias", "type", "domain"]
Expand Down
39 changes: 36 additions & 3 deletions packages/geoview-core/src/api/config/uuid-config-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, { AxiosResponse } from 'axios';

import { TypeJsonObject, TypeJsonArray, toJsonObject } from '@config/types/config-types';
import { CV_CONST_LAYER_TYPES } from '@config/types/config-constants';
import { createLocalizedString } from '@/core/utils/utilities';
import { createLocalizedString, deepMergeObjects } from '@/core/utils/utilities';
import { logger } from '@/core/utils/logger';

// The GeoChart Json object coming out of the GeoCore response
Expand Down Expand Up @@ -58,6 +58,11 @@ export class UUIDmapConfigReader {
if (layer) {
const { layerType, layerEntries, name, url, id, serverType, isTimeAware } = layer;

// Get Geocore custom config layer entries values
// TODO: The proof of concept is done only for WMS layers. We need to implement other layer types after the refactor
// TODO.CONT: We need to support config for the geoviewLAyer and children layer entries...
const customGeocoreLayerConfig = this.#getGeocoreCustomLayerConfig(result, lang);

const isFeature = (url as string).indexOf('FeatureServer') > -1;

if (layerType === CV_CONST_LAYER_TYPES.ESRI_DYNAMIC && !isFeature) {
Expand Down Expand Up @@ -126,12 +131,20 @@ export class UUIDmapConfigReader {
});
(geoviewLayerConfig.listOfLayerEntryConfig as TypeJsonObject[]) = (layerEntries as TypeJsonArray).map(
(item): TypeJsonObject => {
return toJsonObject({
const originalConfig = {
layerId: `${item.id}`,
source: {
serverType: serverType === undefined ? 'mapserver' : serverType,
},
});
};

// Overwrite default from geocore custom config
const mergedConfig = deepMergeObjects(
originalConfig as unknown as TypeJsonObject,
customGeocoreLayerConfig as unknown as TypeJsonObject
);

return mergedConfig;
}
);
listOfGeoviewLayerConfig.push(geoviewLayerConfig);
Expand Down Expand Up @@ -298,6 +311,26 @@ export class UUIDmapConfigReader {
return listOfGeoviewLayerConfig;
}

/**
* Reads the layers config from uuid request result
* @param {AxiosResponse<GeoChartGeoCoreConfig>} result - the uuid request result
* @param {string} lang - the language to use to read results
* @returns {TypeJsonObject} the layers snippet configs
* @private
*/
static #getGeocoreCustomLayerConfig(result: AxiosResponse<TypeJsonObject>, lang: string): TypeJsonObject {
// If no custon geocore information
if (!result?.data || !result.data.response || !result.data.response.gcs || !Array.isArray(result.data.response.gcs)) return {};

// TODO: Once refactor done rename to layers
// TODO: Before moving to the new api, layers will need to link to ids inside the gsc response so we can customize group, or specific id
// Find custom layer entry configuration
const foundConfigs = result.data.response.gcs.map((gcs) => gcs?.[lang]?.layersNew as TypeJsonObject);

return foundConfigs[0] || {};
}

// GV This is important, it sets the geochart config, we need to relink
// TODO: Check - Commented out as not called anymore by method `getGVConfigFromUUIDs`, but maybe it should still?
// /**
// * Reads and parses GeoChart configs from uuid request result
Expand Down
2 changes: 1 addition & 1 deletion packages/geoview-core/src/api/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export abstract class Plugin {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static loadScript(pluginId: string): Promise<any> {
return new Promise((resolve, reject) => {
const existingScript = document.getElementById(pluginId);
const existingScript = document.querySelector(`script#${pluginId}`);

if (!existingScript) {
// Get the main script URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ export function FooterBar(props: FooterBarProps): JSX.Element | null {
// inject guide tab at last position of tabs.
return Object.keys({ ...tabsList, ...{ guide: {} } }).map((tab, index) => {
return {
id: `${mapId}-${tab}${index}`,
id: `${tab}`,
value: index,
label: `${camelCase(tab)}.title`,
icon: allTabs[tab]?.icon ?? '',
content: allTabs[tab]?.content ?? '',
} as TypeTabs;
});
}, [memoTabs, tabsList, mapId]);
}, [memoTabs, tabsList]);

/**
* Calculate resize values from popover values defined in store.
Expand Down Expand Up @@ -192,7 +192,7 @@ export function FooterBar(props: FooterBarProps): JSX.Element | null {
logger.logTraceUseEffect('FOOTER-TABS - arrayOfLayerDataBatch', arrayOfLayerDataBatch, selectedTab, isCollapsed);

// If we're on the details panel and the footer is collapsed
if (selectedTab === `${mapId}-details-2` && isCollapsed) {
if (selectedTab === `details` && isCollapsed) {
// Uncollapse it
setFooterBarIsCollapsed(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export class ConfigValidation {
const validateLocalizedString = (config: TypeJsonObject): void => {
if (typeof config === 'object') {
Object.keys(config).forEach((key) => {
if (!key.startsWith('_') && typeof config[key] === 'object') {
if (!key.startsWith('_') && config[key] !== null && typeof config[key] === 'object') {
if (config?.[key]?.en || config?.[key]?.fr) {
// delete empty localized strings
if (!config[key].en && !config[key].fr) delete config[key];
Expand Down Expand Up @@ -420,7 +420,7 @@ export class ConfigValidation {
const propagateLocalizedString = (config: TypeJsonObject): void => {
if (typeof config === 'object') {
Object.keys(config).forEach((key) => {
if (!key.startsWith('_') && typeof config[key] === 'object') {
if (!key.startsWith('_') && config[key] !== null && typeof config[key] === 'object') {
// 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)
Expand Down
Loading

0 comments on commit 8f4d8b5

Please sign in to comment.