Skip to content

Commit

Permalink
- Added support for more projections (wkids (3578, 3979, 102184, 1021…
Browse files Browse the repository at this point in the history
…90)) to support a wider variety of services.

- Added support for wkt projections (when wkt instead of wkid is used) in the metadata.
- Fixed a few projection issues.
- Fixed an issue with the `supportsDynamicLayers` flag, now continuing the layer loading (instead of stopping with an error)
- Fixed a couple of ESLint warnings
- Added some robustness when extent is badly or not defined at the service level
  • Loading branch information
Alex-NRCan committed Nov 29, 2024
1 parent fa9ce16 commit ee46501
Show file tree
Hide file tree
Showing 24 changed files with 329 additions and 198 deletions.
124 changes: 2 additions & 122 deletions packages/geoview-core/public/configs/navigator/06-basic-footer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,130 +9,10 @@
"shaded": true,
"labeled": true
},
"overlayObjects": {
"pointMarkers": {
"group1": [
{
"id": "1",
"coordinate": [-100, 60],
"color": "blue",
"opacity": 0.5
},
{
"id": "2",
"coordinate": [-80, 65],
"color": "rgb(0, 226, 0)"
},
{
"id": "3",
"coordinate": [-115, 66],
"color": "#C52022"
}
]
}
},
"listOfGeoviewLayerConfig": [
{
"geoviewLayerId": "airborne_radioactivity",
"geoviewLayerName": "Airborne Radioactivity",
"metadataAccessPath": "https://maps-cartes.services.geo.ca/server_serveur/rest/services/HC/airborne_radioactivity_en/MapServer",
"geoviewLayerType": "esriDynamic",
"listOfLayerEntryConfig": [
{
"layerId": "1"
}
]
},
{
"geoviewLayerId": "uniqueValueId",
"geoviewLayerName": "uniqueValue",
"metadataAccessPath": "https://maps-cartes.ec.gc.ca/arcgis/rest/services/CESI/MapServer/",
"geoviewLayerType": "esriFeature",
"listOfLayerEntryConfig": [
{
"layerId": "1",
"layerFilter": "E_Province = 'Alberta' or E_Province = 'Manitoba'"
}
]
},
{
"geoviewLayerId": "fail_bad_url",
"geoviewLayerName": "Test fail bad url",
"metadataAccessPath": "https://maps-cartes.services.geo.caaaaaa/server_serveur/rest/services/HC/airborne_radioactivity_en/MapServer",
"geoviewLayerType": "esriDynamic",
"listOfLayerEntryConfig": [
{
"layerId": "1"
}
]
},
{
"geoviewLayerId": "esriFeatureLYR5",
"geoviewLayerName": "Top Projects",
"metadataAccessPath": "https://maps-cartes.services.geo.ca/server_serveur/rest/services/NRCan/900A_and_top_100_en/MapServer/",
"geoviewLayerType": "esriFeature",
"listOfLayerEntryConfig": [
{
"layerId": "0"
}
]
},
{
"geoviewLayerId": "nonmetalmines",
"geoviewLayerName": "Non metal mines",
"metadataAccessPath": "https://maps-cartes.services.geo.ca/server_serveur/rest/services/NRCan/900A_and_top_100_en/MapServer/",
"geoviewLayerType": "esriFeature",
"listOfLayerEntryConfig": [
{
"layerId": "5"
}
]
},
{
"geoviewLayerId": "geojsonLYR1",
"geoviewLayerName": "GeoJSON Sample",
"metadataAccessPath": "./datasets/geojson/metadata.meta",
"geoviewLayerType": "GeoJSON",
"listOfLayerEntryConfig": [
{
"layerId": "polygons.json",
"layerName": "Polygons"
},
{
"layerId": "lines.json",
"layerName": "Lines"
},
{
"entryType": "group",
"layerId": "point-feature-group",
"layerName": "Points & Icons",
"listOfLayerEntryConfig": [
{
"layerId": "icon_points.json",
"layerName": "Icons"
},
{
"layerId": "points.json",
"layerName": "Points"
},
{
"layerId": "points_1.json",
"layerName": "Points 1",
"initialSettings": {
"controls": { "remove": true }
}
},
{
"layerId": "points_2.json",
"layerName": "Points 2"
},
{
"layerId": "points_3.json",
"layerName": "Points 3"
}
]
}
]
"geoviewLayerId": "b7859aed-bb3c-4abe-8a98-444c194b260f",
"geoviewLayerType": "geoCore"
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion packages/geoview-core/src/api/config/config-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ export class ConfigApi {
// we return undefined to signal that we cannot create the GeoView layer.
if (!geoviewLayerConfig) return undefined;
} catch (error) {
logger.logError(`Unable to convert GeoCore layer (Id=${serviceAccessString}).`);
// Log error
logger.logError(`Unable to convert GeoCore layer (Id=${serviceAccessString}).`, error);
return undefined;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ export class WmsLayerConfig extends AbstractGeoviewLayerConfig {
// In the event of a service metadata reading error, we report the geoview layer and all its sublayers as being in error.
this.setErrorDetectedFlag();
this.setErrorDetectedFlagForAllLayers(this.listOfLayerEntryConfig);
logger.logError(`Error detected while reading WMS metadata for geoview layer ${this.geoviewLayerId}.`);
// Log error
logger.logError(`Error detected while reading WMS metadata for geoview layer ${this.geoviewLayerId}.`, error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class EsriGroupLayerConfig extends GroupLayerEntryConfig {
if (sourceProj === '4326') this.initialSettings.extent = validateExtentWhenDefined(metadataExtent);
else
this.initialSettings.extent = validateExtentWhenDefined(
Projection.transformExtent(metadataExtent, `EPSG:${sourceProj}`, Projection.PROJECTION_NAMES.LNGLAT)
Projection.transformExtentFromObj(metadataExtent, layerMetadata.initialExtent.spatialReference, Projection.PROJECTION_NAMES.LNGLAT)
);

if (layerMetadata.defaultVisibility !== undefined) this.initialSettings.states!.visible = layerMetadata.defaultVisibility as boolean;
Expand Down Expand Up @@ -133,7 +133,11 @@ export class EsriGroupLayerConfig extends GroupLayerEntryConfig {
if (sourceProj === '4326') this.initialSettings.extent = validateExtentWhenDefined(metadataExtent);
else
this.initialSettings.extent = validateExtentWhenDefined(
Projection.transformExtent(metadataExtent, `EPSG:${sourceProj}`, Projection.PROJECTION_NAMES.LNGLAT)
Projection.transformExtentFromObj(
metadataExtent,
serviceMetadata.initialExtent.spatialReference,
Projection.PROJECTION_NAMES.LNGLAT
)
);

this.initialSettings.states!.queryable = (serviceMetadata?.capabilities as string)?.includes('Query') || false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ export abstract class AbstractBaseEsriLayerEntryConfig extends AbstractBaseLayer
const sourceProj = layerMetadata.extent.spatialReference.wkid;
if (sourceProj === '4326') this.initialSettings.extent = validateExtentWhenDefined(metadataExtent);
else {
metadataExtent = Projection.transformExtent(metadataExtent, `EPSG:${sourceProj}`, Projection.PROJECTION_NAMES.LNGLAT);
metadataExtent = Projection.transformExtentFromObj(
metadataExtent,
layerMetadata.extent.spatialReference,
Projection.PROJECTION_NAMES.LNGLAT
);
this.initialSettings.extent = validateExtentWhenDefined(metadataExtent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,10 +893,10 @@ export class MapEventProcessor extends AbstractEventProcessor {

const projectionConfig = Projection.PROJECTIONS[this.getMapState(mapId).currentProjection];
if (bbox) {
// GV There were issues with fromLonLat in rare cases in LCC projections, transformExtent seems to solve them.
// GV fromLonLat and transformExtent give differing results in many cases, fromLonLat had issues with the first
// GV There were issues with fromLonLat in rare cases in LCC projections, transformExtentFromProj seems to solve them.
// GV fromLonLat and transformExtentFromProj give differing results in many cases, fromLonLat had issues with the first
// GV three results from a geolocator search for "vancouver river"
const convertedExtent = Projection.transformExtent(bbox, Projection.PROJECTION_NAMES.LNGLAT, projectionConfig);
const convertedExtent = Projection.transformExtentFromProj(bbox, Projection.PROJECTION_NAMES.LNGLAT, projectionConfig);

// Highlight
this.getMapViewerLayerAPI(mapId).featureHighlight.highlightGeolocatorBBox(convertedExtent);
Expand Down Expand Up @@ -958,7 +958,7 @@ export class MapEventProcessor extends AbstractEventProcessor {
// If extent is in config, use it
if (getGeoViewStore(mapId).getState().mapConfig!.map.viewSettings.initialView?.extent) {
const lnglatExtent = getGeoViewStore(mapId).getState().mapConfig!.map.viewSettings.initialView!.extent as Extent;
extent = Projection.transformExtent(lnglatExtent, Projection.PROJECTION_NAMES.LNGLAT, `EPSG:${currProjection}`);
extent = Projection.transformExtentFromProj(lnglatExtent, Projection.PROJECTION_NAMES.LNGLAT, `EPSG:${currProjection}`);
options.padding = [0, 0, 0, 0];
}

Expand Down
3 changes: 2 additions & 1 deletion packages/geoview-core/src/api/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ export abstract class Plugin {
pluginConfigObj = result;
}
} catch (error) {
// config not found
// Log error
logger.logError(`Config not found.`, error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class AppBarApi {
this.#emitAppBarRemoved({ buttonPanelId, group });
} catch (error) {
// Log
logger.logError(`Failed to get app bar panel button ${group}/${buttonPanelId}`);
logger.logError(`Failed to get app bar panel button ${group}/${buttonPanelId}`, error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ export function AddNewLayer(): JSX.Element {
} else {
setLayerList(layers);
}
} catch (err) {
if ((err as Error).message === 'proj') {
} catch (error) {
// Log error
logger.logError(error);
if ((error as Error).message === 'proj') {
emitErrorProj('WMS', proj, supportedProj);
} else {
emitErrorServer('WMS');
Expand Down Expand Up @@ -315,8 +317,10 @@ export function AddNewLayer(): JSX.Element {
} else {
setLayerList(layers);
}
} catch (err) {
} catch (error) {
emitErrorServer('WFS');
// Log error
logger.logError(error);
return false;
}
return true;
Expand Down Expand Up @@ -404,8 +408,10 @@ export function AddNewLayer(): JSX.Element {
} else {
setLayerList(layers);
}
} catch (err) {
} catch (error) {
emitErrorServer('OGC API Feature');
// Log error
logger.logError(error);
return false;
}
return true;
Expand All @@ -431,8 +437,10 @@ export function AddNewLayer(): JSX.Element {
setLayerList(layers);
}
}
} catch (err) {
} catch (error) {
emitErrorServer('GeoCore UUID');
// Log error
logger.logError(error);
return false;
}
return true;
Expand Down Expand Up @@ -504,8 +512,10 @@ export function AddNewLayer(): JSX.Element {
} else {
throw new Error('err');
}
} catch (err) {
} catch (error) {
emitErrorServer(esriOptions(type).err);
// Log error
logger.logError(error);
return false;
}
return true;
Expand Down Expand Up @@ -540,8 +550,10 @@ export function AddNewLayer(): JSX.Element {
];
setLayerName(layers[0].layerName!);
setLayerEntries([layers[0]]);
} catch (err) {
} catch (error) {
emitErrorServer('ESRI Image');
// Log error
logger.logError(error);
return false;
}
return true;
Expand Down Expand Up @@ -583,8 +595,10 @@ export function AddNewLayer(): JSX.Element {
];
setLayerName(layers[0].layerName!);
setLayerEntries([layers[0]]);
} catch (err) {
} catch (error) {
emitErrorServer('XYZ Tile');
// Log error
logger.logError(error);
return false;
}
return true;
Expand Down Expand Up @@ -621,8 +635,10 @@ export function AddNewLayer(): JSX.Element {
];
setLayerName(layers[0].layerName!);
setLayerEntries([layers[0]]);
} catch (err) {
} catch (error) {
emitErrorServer('CSV');
// Log error
logger.logError(error);
return false;
}
return true;
Expand Down Expand Up @@ -687,8 +703,10 @@ export function AddNewLayer(): JSX.Element {
setLayerName(layers[0].layerName!);
setLayerEntries([layers[0]]);
}
} catch (err) {
} catch (error) {
emitErrorServer('GeoJSON');
// Log error
logger.logError(error);
return false;
}
return true;
Expand Down Expand Up @@ -723,8 +741,10 @@ export function AddNewLayer(): JSX.Element {
];
setLayerName(layers[0].layerName!);
setLayerEntries([layers[0]]);
} catch (err) {
} catch (error) {
emitErrorServer('GeoPackage');
// Log error
logger.logError(error);
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// map-info.tsx
export const getSxClasses = () => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const getSxClasses = (): any => ({
mouseScaleControlsContainer: {
display: 'flex',
flexDirection: 'row',
Expand Down
4 changes: 2 additions & 2 deletions packages/geoview-core/src/core/utils/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getItemAsNumber = (key: string, defaultValue?: number): number | un

// If set and valid: return it; else default will be returned
if (levelValueNumber && !Number.isNaN(levelValueNumber)) return levelValueNumber;
} catch (e) {
} catch {
// Failed to read localStorage, eat the exception and continue to set the value to the default
}

Expand Down Expand Up @@ -49,7 +49,7 @@ export const getItemAsNumberOrNumberArray = (key: string, defaultValue?: number

// If set and valid: return it; else default will be returned
if (levelValueNumber && !Number.isNaN(levelValueNumber)) return levelValueNumber;
} catch (e) {
} catch {
// Failed to read localStorage, eat the exception and continue to set the value to the default
}

Expand Down
2 changes: 1 addition & 1 deletion packages/geoview-core/src/core/utils/useWhatChanged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function stringifyValue(dependencyItem: unknown): string | unknown {
}
}
return dependencyItem;
} catch (e) {
} catch {
// Failed to read as string
return 'COMPLEX OBJECT';
}
Expand Down
2 changes: 2 additions & 0 deletions packages/geoview-core/src/core/utils/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ export function getXMLHttpRequest(url: string): Promise<string> {
};
jsonObj.send(null);
} catch (error) {
// Log warning
logger.logWarning(error);
resolve('{}');
}
});
Expand Down
Loading

0 comments on commit ee46501

Please sign in to comment.