From e8136839046fdf9ba1b1dbfa6e6a8204bfaa036d Mon Sep 17 00:00:00 2001 From: AlexNRCan Date: Thu, 12 Dec 2024 11:56:52 -0500 Subject: [PATCH] Fixing extent densification --- .../geoview-core/src/geo/map/map-viewer.ts | 13 +++++--- .../geoview-core/src/geo/utils/projection.ts | 31 ++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/packages/geoview-core/src/geo/map/map-viewer.ts b/packages/geoview-core/src/geo/map/map-viewer.ts index ab7b8c4c8ab..cce61ec9043 100644 --- a/packages/geoview-core/src/geo/map/map-viewer.ts +++ b/packages/geoview-core/src/geo/map/map-viewer.ts @@ -76,6 +76,9 @@ export class MapViewer { // Minimum delay (in milliseconds) for map to be in loading state static readonly #MIN_DELAY_LOADING = 2000; + // The default densification number when forming layer extents, to make ture to compensate for earth curvature + static DEFAULT_STOPS: number = 25; + // map config properties mapFeaturesConfig: TypeMapFeaturesConfig; @@ -1444,11 +1447,12 @@ export class MapViewer { /** * Transforms extent from LngLat to the current projection of the map. * @param {Extent} extent - The LngLat extent + * @param {number} stops - The number of stops to perform densification on the extent * @returns {Extent} The extent in the map projection */ - convertExtentLngLatToMapProj(extent: Extent): Extent { + convertExtentLngLatToMapProj(extent: Extent, stops: number = MapViewer.DEFAULT_STOPS): Extent { // Redirect - return this.convertExtentFromProjToMapProj(extent, Projection.PROJECTION_NAMES.LNGLAT); + return this.convertExtentFromProjToMapProj(extent, Projection.PROJECTION_NAMES.LNGLAT, stops); } /** @@ -1497,12 +1501,13 @@ export class MapViewer { * Transforms extent from given projection to the current projection of the map. * @param {Extent} extent - The given extent * @param {ProjectionLike} fromProj - The projection of the given extent + * @param {number} stops - The number of stops to perform densification on the extent * @returns {Extent} The extent in the map projection */ - convertExtentFromProjToMapProj(extent: Extent, fromProj: ProjectionLike): Extent { + convertExtentFromProjToMapProj(extent: Extent, fromProj: ProjectionLike, stops: number = MapViewer.DEFAULT_STOPS): Extent { // If different projections if (fromProj !== this.getProjection().getCode()) { - return Projection.transformExtentFromProj(extent, fromProj, this.getProjection()); + return Projection.transformExtentFromProj(extent, fromProj, this.getProjection(), stops); } // Same projection diff --git a/packages/geoview-core/src/geo/utils/projection.ts b/packages/geoview-core/src/geo/utils/projection.ts index 6515e237cbf..25e9b87050b 100644 --- a/packages/geoview-core/src/geo/utils/projection.ts +++ b/packages/geoview-core/src/geo/utils/projection.ts @@ -16,7 +16,7 @@ import { logger } from '@/core/utils/logger'; import { TypeJsonObject } from '@/core/types/global-types'; /** - * Class used to handle functions for trasforming projections + * Class used to handle functions for transforming projections * * @exports * @class Projection @@ -34,6 +34,7 @@ export abstract class Projection { 3578: 'EPSG:3578', LCC: 'EPSG:3978', 3979: 'EPSG:3979', + 102100: 'EPSG:102100', // TODO: Minor - This is technically supposed to be ESRI:102100, but some things would need to change in order to support this, works now 102184: 'EPSG:102184', // TODO: Minor - This is technically supposed to be ESRI:102184, but more things would need to change in order to support this, works now 102190: 'EPSG:102190', // TODO: Minor - This is technically supposed to be ESRI:102190, but some things would need to change in order to support this, works now WM: 'EPSG:3857', @@ -225,9 +226,14 @@ export abstract class Projection { */ static getProjectionFromObj(projection: TypeJsonObject | undefined): olProjection | undefined { // If wkid - if (projection && projection.wkid) { - // Redirect - return Projection.getProjectionFromProj(`EPSG:${projection.wkid}`); + if (projection) { + if (projection.latestWkid) { + return Projection.getProjectionFromProj(`EPSG:${projection.latestWkid}`); + } + if (projection.wkid) { + // Redirect + return Projection.getProjectionFromProj(`EPSG:${projection.wkid}`); + } } // If wkt @@ -389,6 +395,22 @@ function init3979Projection(): void { if (projection) Projection.PROJECTIONS['3979'] = projection; } +/** + * initialize EPSG:102100 (ESRI:102100) projection + * @private + */ +function init102100Projection(): void { + proj4.defs( + Projection.PROJECTION_NAMES[102100], + '+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs' + ); + register(proj4); + + const projection = olGetProjection(Projection.PROJECTION_NAMES[102100]); + + if (projection) Projection.PROJECTIONS['102100'] = projection; +} + /** * initialize EPSG:102184 (ESRI:102184) projection * @private @@ -429,6 +451,7 @@ initCSRSProjection(); initCSRS98Projection(); init3578Projection(); init3979Projection(); +init102100Projection(); init102184Projection(); init102190Projection(); logger.logInfo('Projections initialized');