Skip to content

Commit

Permalink
Fixing extent densification
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-NRCan committed Dec 12, 2024
1 parent fc3ebda commit e813683
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
13 changes: 9 additions & 4 deletions packages/geoview-core/src/geo/map/map-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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
Expand Down
31 changes: 27 additions & 4 deletions packages/geoview-core/src/geo/utils/projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -429,6 +451,7 @@ initCSRSProjection();
initCSRS98Projection();
init3578Projection();
init3979Projection();
init102100Projection();
init102184Projection();
init102190Projection();
logger.logInfo('Projections initialized');

0 comments on commit e813683

Please sign in to comment.