From d3a7fd941449a25dc465800ef33e8b2ac6eba9a7 Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Thu, 17 Oct 2024 19:36:54 +0200 Subject: [PATCH 1/8] fix(babel): include ts files in prerequisites --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b1ef73b80a..3a7a448920 100644 --- a/package.json +++ b/package.json @@ -21,13 +21,13 @@ "base-test-unit": "cross-env BABEL_DISABLE_CACHE=1 mocha --file test/unit/bootstrap.js --import=./config/babel-register/register.mjs", "build": "cross-env NODE_ENV=production webpack", "build-dev": "cross-env NODE_ENV=development webpack", - "transpile": "cross-env BABEL_DISABLE_CACHE=1 babel src --out-dir lib", + "transpile": "cross-env BABEL_DISABLE_CACHE=1 babel src --out-dir lib --extensions .js,.ts", "start": "cross-env NODE_ENV=development webpack serve", "start-https": "cross-env NODE_ENV=development webpack serve --https", "debug": "cross-env noInline=true npm start", "prepublishOnly": "npm run build && npm run transpile", "prepare": "cross-env NO_UPDATE_NOTIFIER=true node ./config/prepare.mjs && node ./config/replace.config.mjs", - "watch": "cross-env BABEL_DISABLE_CACHE=1 babel --watch src --out-dir lib", + "watch": "npm run transpile -- --watch", "changelog": "conventional-changelog -n ./config/conventionalChangelog/config.cjs -i changelog.md -s", "bump": "if [ -z $npm_config_level ]; then grunt bump:minor; else grunt bump:$npm_config_level; fi && npm run changelog && npm install && git add -A && git commit --amend --no-edit", "publish-next": "npm version prerelease --preid next && npm publish --access public --tag=next --provenance", From 300718ca6b3c922790f647990cfa62281520e8f2 Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Thu, 3 Oct 2024 10:29:31 +0200 Subject: [PATCH 2/8] refacto: migrate Crs to typescript --- src/Core/Geographic/{Crs.js => Crs.ts} | 103 ++++++++++++------------- test/unit/crs.js | 8 ++ 2 files changed, 58 insertions(+), 53 deletions(-) rename src/Core/Geographic/{Crs.js => Crs.ts} (52%) diff --git a/src/Core/Geographic/Crs.js b/src/Core/Geographic/Crs.ts similarity index 52% rename from src/Core/Geographic/Crs.js rename to src/Core/Geographic/Crs.ts index b7c40cfc4f..d1a46f943e 100644 --- a/src/Core/Geographic/Crs.js +++ b/src/Core/Geographic/Crs.ts @@ -2,50 +2,55 @@ import proj4 from 'proj4'; proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs'); -function isString(s) { +/** + * A projection as a CRS identifier string. + */ +export type ProjectionLike = string; + +function isString(s: unknown): s is string { return typeof s === 'string' || s instanceof String; } -function mustBeString(crs) { +function mustBeString(crs: string) { if (!isString(crs)) { throw new Error(`Crs parameter value must be a string: '${crs}'`); } } -function isTms(crs) { +function isTms(crs: string) { return isString(crs) && crs.startsWith('TMS'); } -function isEpsg(crs) { +function isEpsg(crs: string) { return isString(crs) && crs.startsWith('EPSG'); } -function formatToTms(crs) { +function formatToTms(crs: string) { mustBeString(crs); - return isTms(crs) ? crs : `TMS:${crs.match(/\d+/)[0]}`; + return isTms(crs) ? crs : `TMS:${crs.match(/\d+/)?.[0]}`; } -function formatToEPSG(crs) { +function formatToEPSG(crs: string) { mustBeString(crs); - return isEpsg(crs) ? crs : `EPSG:${crs.match(/\d+/)[0]}`; + return isEpsg(crs) ? crs : `EPSG:${crs.match(/\d+/)?.[0]}`; } const UNIT = { DEGREE: 1, METER: 2, -}; +} as const; -function is4326(crs) { +function is4326(crs: ProjectionLike) { return crs === 'EPSG:4326'; } -function isGeocentric(crs) { +function isGeocentric(crs: ProjectionLike) { mustBeString(crs); const projection = proj4.defs(crs); return !projection ? false : projection.projName == 'geocent'; } -function _unitFromProj4Unit(projunit) { +function _unitFromProj4Unit(projunit: string) { if (projunit === 'degrees') { return UNIT.DEGREE; } else if (projunit === 'm') { @@ -55,14 +60,14 @@ function _unitFromProj4Unit(projunit) { } } -function toUnit(crs) { +function toUnit(crs: ProjectionLike) { mustBeString(crs); switch (crs) { case 'EPSG:4326' : return UNIT.DEGREE; case 'EPSG:4978' : return UNIT.METER; default: { const p = proj4.defs(formatToEPSG(crs)); - if (!p) { + if (!p?.units) { return undefined; } return _unitFromProj4Unit(p.units); @@ -70,7 +75,7 @@ function toUnit(crs) { } } -function toUnitWithError(crs) { +function toUnitWithError(crs: ProjectionLike) { mustBeString(crs); const u = toUnit(crs); if (u === undefined) { @@ -80,82 +85,74 @@ function toUnitWithError(crs) { } /** - * This module provides basic methods to manipulate a CRS (as a string). - * - * @module CRS + * This module provides basic methods to manipulate a CRS. */ export default { /** * Units that can be used for a CRS. - * - * @enum {number} */ UNIT, /** - * Assert that the CRS is valid one. + * Assert that the CRS is a valid one. * - * @param {string} crs - The CRS to validate. + * @param crs - The CRS to validate. * - * @throws {Error} if the CRS is not valid. + * @throws {@link Error} if the CRS is not valid. */ - isValid(crs) { + isValid(crs: ProjectionLike) { toUnitWithError(crs); }, /** * Assert that the CRS is geographic. * - * @param {string} crs - The CRS to validate. - * @return {boolean} - * @throws {Error} if the CRS is not valid. + * @param crs - The CRS to validate. + * @throws {@link Error} if the CRS is not valid. */ - isGeographic(crs) { + isGeographic(crs: ProjectionLike) { return (toUnitWithError(crs) == UNIT.DEGREE); }, /** * Assert that the CRS is using metric units. * - * @param {string} crs - The CRS to validate. - * @return {boolean} - * @throws {Error} if the CRS is not valid. + * @param crs - The CRS to validate. + * @throws {@link Error} if the CRS is not valid. */ - isMetricUnit(crs) { + isMetricUnit(crs: ProjectionLike) { return (toUnit(crs) == UNIT.METER); }, /** * Get the unit to use with the CRS. * - * @param {string} crs - The CRS to get the unit from. - * @return {number} Either `UNIT.METER`, `UNIT.DEGREE` or `undefined`. + * @param crs - The CRS to get the unit from. + * @returns Either `UNIT.METER`, `UNIT.DEGREE` or `undefined`. */ toUnit, /** - * Is the CRS EPSG:4326 ? + * Is the CRS EPSG:4326? * - * @param {string} crs - The CRS to test. - * @return {boolean} + * @param crs - The CRS to test. */ is4326, /** - * Is the CRS geocentric ? + * Is the CRS geocentric? * if crs isn't defined the method returns false. * - * @param {string} crs - The CRS to test. - * @return {boolean} + * @param crs - The CRS to test. */ isGeocentric, /** * Give a reasonnable epsilon to use with this CRS. * - * @param {string} crs - The CRS to use. - * @return {number} 0.01 if the CRS is EPSG:4326, 0.001 otherwise. + * @param crs - The CRS to use. + * @returns 0.01 if the CRS is EPSG:4326, 0.001 otherwise. */ - reasonnableEpsilon(crs) { + reasonnableEpsilon(crs: ProjectionLike) { if (is4326(crs)) { return 0.01; } else { @@ -163,17 +160,17 @@ export default { } }, /** - * format crs to European Petroleum Survey Group notation : EPSG:XXXX. + * Format crs to European Petroleum Survey Group notation: EPSG:XXXX. * - * @param {string} crs The crs to format - * @return {string} formated crs + * @param crs - The crs to format + * @returns formated crs */ formatToEPSG, /** - * format crs to tile matrix set notation : TMS:XXXX. + * Format crs to tile matrix set notation: TMS:XXXX. * - * @param {string} crs The crs to format - * @return {string} formated crs + * @param crs - The crs to format + * @returns formated crs */ formatToTms, isTms, @@ -183,9 +180,9 @@ export default { /** * Define a proj4 projection as a string and reference. * - * @param {string} code code is the projection's SRS code (only used internally by the Proj4js library) - * @param {string} proj4def is the Proj4 definition string for the projection to use - * @return {undefined} + * @param code - projection's SRS code (only used internally by the Proj4js + * library) + * @param proj4def - Proj4 definition string for the projection to use */ - defs: (code, proj4def) => proj4.defs(code, proj4def), + defs: (code: string, proj4def: string) => proj4.defs(code, proj4def), }; diff --git a/test/unit/crs.js b/test/unit/crs.js index 3e62240ac7..00c1f3a3b1 100644 --- a/test/unit/crs.js +++ b/test/unit/crs.js @@ -34,6 +34,7 @@ describe('CRS assertions', function () { assert.strictEqual(CRS.toUnit('EPSG:7133'), CRS.UNIT.DEGREE); assert.strictEqual(CRS.toUnit('EPSG:4978'), CRS.UNIT.METER); assert.strictEqual(CRS.toUnit('EPSG:3857'), CRS.UNIT.METER); + assert.strictEqual(CRS.toUnit('EPSG:INVALID'), undefined); }); it('should check if the CRS is EPSG:4326', function () { @@ -41,6 +42,13 @@ describe('CRS assertions', function () { assert.ok(!CRS.is4326('EPSG:3857')); }); + it('should assert that the CRS is geocentric', function () { + assert.ok(!CRS.isGeocentric('EPSG:4326')); + assert.ok(!CRS.isGeocentric('EPSG:7133')); + assert.ok(CRS.isGeocentric('EPSG:4978')); + assert.ok(!CRS.isGeocentric('EPSG:3857')); + }); + it('should return a reasonnable epsilon', function () { assert.strictEqual(CRS.reasonnableEpsilon('EPSG:4326'), 0.01); assert.strictEqual(CRS.reasonnableEpsilon('EPSG:3857'), 0.001); From 1288720eeac23b496c29eee83f031f3a7877a228 Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Thu, 17 Oct 2024 20:50:52 +0200 Subject: [PATCH 3/8] refacto(Crs): cleanup unit handling --- src/Core/Geographic/Crs.ts | 45 ++++++++++++++++++-------------------- test/unit/crs.js | 2 +- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/Core/Geographic/Crs.ts b/src/Core/Geographic/Crs.ts index d1a46f943e..ecb57a4c75 100644 --- a/src/Core/Geographic/Crs.ts +++ b/src/Core/Geographic/Crs.ts @@ -1,5 +1,7 @@ import proj4 from 'proj4'; +import type { ProjectionDefinition } from 'proj4'; + proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs'); /** @@ -50,10 +52,14 @@ function isGeocentric(crs: ProjectionLike) { return !projection ? false : projection.projName == 'geocent'; } -function _unitFromProj4Unit(projunit: string) { - if (projunit === 'degrees') { +function unitFromProj4Unit(proj: ProjectionDefinition) { + if (proj.units === 'degrees') { return UNIT.DEGREE; - } else if (projunit === 'm') { + } else if (proj.units === 'm') { + return UNIT.METER; + } else if (proj.units === undefined && proj.to_meter === undefined) { + // See https://proj.org/en/9.4/usage/projections.html [17/10/2024] + // > The default unit for projected coordinates is the meter. return UNIT.METER; } else { return undefined; @@ -62,26 +68,11 @@ function _unitFromProj4Unit(projunit: string) { function toUnit(crs: ProjectionLike) { mustBeString(crs); - switch (crs) { - case 'EPSG:4326' : return UNIT.DEGREE; - case 'EPSG:4978' : return UNIT.METER; - default: { - const p = proj4.defs(formatToEPSG(crs)); - if (!p?.units) { - return undefined; - } - return _unitFromProj4Unit(p.units); - } - } -} - -function toUnitWithError(crs: ProjectionLike) { - mustBeString(crs); - const u = toUnit(crs); - if (u === undefined) { - throw new Error(`No unit found for crs: '${crs}'`); + const p = proj4.defs(formatToEPSG(crs)); + if (!p) { + return undefined; } - return u; + return unitFromProj4Unit(p); } /** @@ -101,7 +92,13 @@ export default { * @throws {@link Error} if the CRS is not valid. */ isValid(crs: ProjectionLike) { - toUnitWithError(crs); + const proj = proj4.defs(crs); + if (!proj) { + throw new Error(`Undefined crs '${crs}'. Add it with proj4.defs('${crs}', string)`); + } + if (!unitFromProj4Unit(proj)) { + throw new Error(`No valid unit found for crs '${crs}', found ${proj.units}`); + } }, /** @@ -111,7 +108,7 @@ export default { * @throws {@link Error} if the CRS is not valid. */ isGeographic(crs: ProjectionLike) { - return (toUnitWithError(crs) == UNIT.DEGREE); + return (toUnit(crs) == UNIT.DEGREE); }, /** diff --git a/test/unit/crs.js b/test/unit/crs.js index 00c1f3a3b1..bb754de8e3 100644 --- a/test/unit/crs.js +++ b/test/unit/crs.js @@ -3,7 +3,7 @@ import proj4 from 'proj4'; import CRS from 'Core/Geographic/Crs'; proj4.defs('EPSG:7133', '+proj=longlat +ellps=GRS80 +no_defs +units=degrees'); -proj4.defs('EPSG:INVALID', '+no_defs'); +proj4.defs('EPSG:INVALID', '+units=invalid +no_defs'); describe('CRS assertions', function () { it('should assert that the CRS is valid', function () { From ede3dd6d09bf8319c3dc565d47ad7bb61e728c56 Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Fri, 15 Nov 2024 16:57:23 +0100 Subject: [PATCH 4/8] refacto(Crs): use named exports instead of default export --- src/Converter/Feature2Mesh.js | 2 +- src/Converter/textureConverter.js | 2 +- src/Core/Feature.js | 2 +- src/Core/Geographic/Coordinates.js | 2 +- src/Core/Geographic/Crs.ts | 224 ++++++++++++-------------- src/Core/Geographic/Extent.js | 2 +- src/Core/Geographic/GeoidGrid.js | 2 +- src/Core/Prefab/Globe/GlobeLayer.js | 2 +- src/Core/Prefab/GlobeView.js | 3 +- src/Core/Prefab/Planar/PlanarLayer.js | 2 +- src/Core/Tile/Tile.js | 2 +- src/Core/Tile/TileGrid.js | 2 +- src/Core/TileMesh.js | 2 +- src/Core/View.js | 2 +- src/Main.js | 2 +- src/Renderer/OBB.js | 2 +- src/Renderer/RasterTile.js | 2 +- src/Source/FileSource.js | 2 +- src/Source/Source.js | 2 +- src/Source/TMSSource.js | 2 +- src/Source/WFSSource.js | 2 +- test/unit/crs.js | 2 +- 22 files changed, 127 insertions(+), 140 deletions(-) diff --git a/src/Converter/Feature2Mesh.js b/src/Converter/Feature2Mesh.js index 27135ba50f..d3d4905ec9 100644 --- a/src/Converter/Feature2Mesh.js +++ b/src/Converter/Feature2Mesh.js @@ -1,10 +1,10 @@ import * as THREE from 'three'; +import * as Crs from 'Core/Geographic/Crs'; import Earcut from 'earcut'; import { FEATURE_TYPES } from 'Core/Feature'; import ReferLayerProperties from 'Layer/ReferencingLayerProperties'; import { deprecatedFeature2MeshOptions } from 'Core/Deprecated/Undeprecator'; import Extent from 'Core/Geographic/Extent'; -import Crs from 'Core/Geographic/Crs'; import OrientationUtils from 'Utils/OrientationUtils'; import Coordinates from 'Core/Geographic/Coordinates'; import Style, { StyleContext } from 'Core/Style'; diff --git a/src/Converter/textureConverter.js b/src/Converter/textureConverter.js index 41f103620f..9db079146e 100644 --- a/src/Converter/textureConverter.js +++ b/src/Converter/textureConverter.js @@ -1,7 +1,7 @@ import * as THREE from 'three'; +import * as CRS from 'Core/Geographic/Crs'; import Feature2Texture from 'Converter/Feature2Texture'; import Extent from 'Core/Geographic/Extent'; -import CRS from 'Core/Geographic/Crs'; const extentTexture = new Extent('EPSG:4326', [0, 0, 0, 0]); diff --git a/src/Core/Feature.js b/src/Core/Feature.js index 82980a747d..0e250a533b 100644 --- a/src/Core/Feature.js +++ b/src/Core/Feature.js @@ -1,7 +1,7 @@ import * as THREE from 'three'; +import * as CRS from 'Core/Geographic/Crs'; import Extent from 'Core/Geographic/Extent'; import Coordinates from 'Core/Geographic/Coordinates'; -import CRS from 'Core/Geographic/Crs'; import Style from 'Core/Style'; function defaultExtent(crs) { diff --git a/src/Core/Geographic/Coordinates.js b/src/Core/Geographic/Coordinates.js index 8fec118a7a..d0934066ea 100644 --- a/src/Core/Geographic/Coordinates.js +++ b/src/Core/Geographic/Coordinates.js @@ -1,6 +1,6 @@ import * as THREE from 'three'; import proj4 from 'proj4'; -import CRS from 'Core/Geographic/Crs'; +import * as CRS from 'Core/Geographic/Crs'; import Ellipsoid from 'Core/Math/Ellipsoid'; proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs'); diff --git a/src/Core/Geographic/Crs.ts b/src/Core/Geographic/Crs.ts index ecb57a4c75..b5513d2ce2 100644 --- a/src/Core/Geographic/Crs.ts +++ b/src/Core/Geographic/Crs.ts @@ -19,37 +19,54 @@ function mustBeString(crs: string) { } } -function isTms(crs: string) { +export function isTms(crs: string) { return isString(crs) && crs.startsWith('TMS'); } -function isEpsg(crs: string) { +export function isEpsg(crs: string) { return isString(crs) && crs.startsWith('EPSG'); } -function formatToTms(crs: string) { +/** + * Format crs to tile matrix set notation: TMS:XXXX. + * + * @param crs - The crs to format + * @returns formated crs + */ +export function formatToTms(crs: string) { mustBeString(crs); return isTms(crs) ? crs : `TMS:${crs.match(/\d+/)?.[0]}`; } -function formatToEPSG(crs: string) { +/** + * Format crs to European Petroleum Survey Group notation: EPSG:XXXX. + * + * @param crs - The crs to format + * @returns formated crs + */ +export function formatToEPSG(crs: string) { mustBeString(crs); return isEpsg(crs) ? crs : `EPSG:${crs.match(/\d+/)?.[0]}`; } -const UNIT = { +/** + * Units that can be used for a CRS. + */ +export const UNIT = { DEGREE: 1, METER: 2, } as const; -function is4326(crs: ProjectionLike) { - return crs === 'EPSG:4326'; -} +export const tms_3857 = 'TMS:3857'; +export const tms_4326 = 'TMS:4326'; -function isGeocentric(crs: ProjectionLike) { - mustBeString(crs); - const projection = proj4.defs(crs); - return !projection ? false : projection.projName == 'geocent'; +/** + * Is the CRS EPSG:4326? + * + * @param crs - The CRS to test. + */ +export function is4326(crs: ProjectionLike) { + return crs === 'EPSG:4326'; } function unitFromProj4Unit(proj: ProjectionDefinition) { @@ -66,7 +83,13 @@ function unitFromProj4Unit(proj: ProjectionDefinition) { } } -function toUnit(crs: ProjectionLike) { +/** + * Get the unit to use with the CRS. + * + * @param crs - The CRS to get the unit from. + * @returns Either `UNIT.METER`, `UNIT.DEGREE` or `undefined`. + */ +export function toUnit(crs: ProjectionLike) { mustBeString(crs); const p = proj4.defs(formatToEPSG(crs)); if (!p) { @@ -76,110 +99,73 @@ function toUnit(crs: ProjectionLike) { } /** - * This module provides basic methods to manipulate a CRS. + * Assert that the CRS is using metric units. + * + * @param crs - The CRS to validate. + * @throws {@link Error} if the CRS is not valid. + */ +export function isMetricUnit(crs: ProjectionLike) { + return (toUnit(crs) == UNIT.METER); +} + +/** + * Assert that the CRS is geographic. + * + * @param crs - The CRS to validate. + * @throws {@link Error} if the CRS is not valid. + */ +export function isGeographic(crs: ProjectionLike) { + return (toUnit(crs) == UNIT.DEGREE); +} + +/** + * Is the CRS geocentric? + * if crs isn't defined the method returns false. + * + * @param crs - The CRS to test. + */ +export function isGeocentric(crs: ProjectionLike) { + mustBeString(crs); + const projection = proj4.defs(crs); + return !projection ? false : projection.projName == 'geocent'; +} + +/** + * Assert that the CRS is a valid one. + * + * @param crs - The CRS to validate. + * + * @throws {@link Error} if the CRS is not valid. + */ +export function isValid(crs: ProjectionLike) { + const proj = proj4.defs(crs); + if (!proj) { + throw new Error(`Undefined crs '${crs}'. Add it with proj4.defs('${crs}', string)`); + } + if (!unitFromProj4Unit(proj)) { + throw new Error(`No valid unit found for crs '${crs}', found ${proj.units}`); + } +} + +/** + * Give a reasonnable epsilon to use with this CRS. + * + * @param crs - The CRS to use. + * @returns 0.01 if the CRS is EPSG:4326, 0.001 otherwise. + */ +export function reasonnableEpsilon(crs: ProjectionLike) { + if (is4326(crs)) { + return 0.01; + } else { + return 0.001; + } +} + +/** + * Define a proj4 projection as a string and reference. + * + * @param code - projection's SRS code (only used internally by the Proj4js + * library) + * @param proj4def - Proj4 definition string for the projection to use */ -export default { - /** - * Units that can be used for a CRS. - */ - UNIT, - - /** - * Assert that the CRS is a valid one. - * - * @param crs - The CRS to validate. - * - * @throws {@link Error} if the CRS is not valid. - */ - isValid(crs: ProjectionLike) { - const proj = proj4.defs(crs); - if (!proj) { - throw new Error(`Undefined crs '${crs}'. Add it with proj4.defs('${crs}', string)`); - } - if (!unitFromProj4Unit(proj)) { - throw new Error(`No valid unit found for crs '${crs}', found ${proj.units}`); - } - }, - - /** - * Assert that the CRS is geographic. - * - * @param crs - The CRS to validate. - * @throws {@link Error} if the CRS is not valid. - */ - isGeographic(crs: ProjectionLike) { - return (toUnit(crs) == UNIT.DEGREE); - }, - - /** - * Assert that the CRS is using metric units. - * - * @param crs - The CRS to validate. - * @throws {@link Error} if the CRS is not valid. - */ - isMetricUnit(crs: ProjectionLike) { - return (toUnit(crs) == UNIT.METER); - }, - - /** - * Get the unit to use with the CRS. - * - * @param crs - The CRS to get the unit from. - * @returns Either `UNIT.METER`, `UNIT.DEGREE` or `undefined`. - */ - toUnit, - - /** - * Is the CRS EPSG:4326? - * - * @param crs - The CRS to test. - */ - is4326, - /** - * Is the CRS geocentric? - * if crs isn't defined the method returns false. - * - * @param crs - The CRS to test. - */ - isGeocentric, - - /** - * Give a reasonnable epsilon to use with this CRS. - * - * @param crs - The CRS to use. - * @returns 0.01 if the CRS is EPSG:4326, 0.001 otherwise. - */ - reasonnableEpsilon(crs: ProjectionLike) { - if (is4326(crs)) { - return 0.01; - } else { - return 0.001; - } - }, - /** - * Format crs to European Petroleum Survey Group notation: EPSG:XXXX. - * - * @param crs - The crs to format - * @returns formated crs - */ - formatToEPSG, - /** - * Format crs to tile matrix set notation: TMS:XXXX. - * - * @param crs - The crs to format - * @returns formated crs - */ - formatToTms, - isTms, - isEpsg, - tms_3857: 'TMS:3857', - tms_4326: 'TMS:4326', - /** - * Define a proj4 projection as a string and reference. - * - * @param code - projection's SRS code (only used internally by the Proj4js - * library) - * @param proj4def - Proj4 definition string for the projection to use - */ - defs: (code: string, proj4def: string) => proj4.defs(code, proj4def), -}; +export const defs = (code: string, proj4def: string) => proj4.defs(code, proj4def); diff --git a/src/Core/Geographic/Extent.js b/src/Core/Geographic/Extent.js index f1ab0cd0dd..0fa844dfdb 100644 --- a/src/Core/Geographic/Extent.js +++ b/src/Core/Geographic/Extent.js @@ -1,6 +1,6 @@ import * as THREE from 'three'; +import * as CRS from './Crs'; import Coordinates from './Coordinates'; -import CRS from './Crs'; /** * Extent is a SIG-area (so 2D) diff --git a/src/Core/Geographic/GeoidGrid.js b/src/Core/Geographic/GeoidGrid.js index 2d6fdd8819..1d5d3cbfa7 100644 --- a/src/Core/Geographic/GeoidGrid.js +++ b/src/Core/Geographic/GeoidGrid.js @@ -1,6 +1,6 @@ import * as THREE from 'three'; +import * as CRS from 'Core/Geographic/Crs'; import Coordinates from 'Core/Geographic/Coordinates'; -import CRS from 'Core/Geographic/Crs'; const coord = new Coordinates('EPSG:4326'); diff --git a/src/Core/Prefab/Globe/GlobeLayer.js b/src/Core/Prefab/Globe/GlobeLayer.js index abc0f44ee1..629b085e59 100644 --- a/src/Core/Prefab/Globe/GlobeLayer.js +++ b/src/Core/Prefab/Globe/GlobeLayer.js @@ -1,9 +1,9 @@ import * as THREE from 'three'; +import * as CRS from 'Core/Geographic/Crs'; import TiledGeometryLayer from 'Layer/TiledGeometryLayer'; import { ellipsoidSizes } from 'Core/Math/Ellipsoid'; import { globalExtentTMS, schemeTiles } from 'Core/Tile/TileGrid'; import BuilderEllipsoidTile from 'Core/Prefab/Globe/BuilderEllipsoidTile'; -import CRS from 'Core/Geographic/Crs'; // matrix to convert sphere to ellipsoid const worldToScaledEllipsoid = new THREE.Matrix4(); diff --git a/src/Core/Prefab/GlobeView.js b/src/Core/Prefab/GlobeView.js index fbe2fd686f..ce70a36ebb 100644 --- a/src/Core/Prefab/GlobeView.js +++ b/src/Core/Prefab/GlobeView.js @@ -1,5 +1,7 @@ import * as THREE from 'three'; +import * as CRS from 'Core/Geographic/Crs'; + import View, { VIEW_EVENTS } from 'Core/View'; import GlobeControls from 'Controls/GlobeControls'; import Coordinates from 'Core/Geographic/Coordinates'; @@ -8,7 +10,6 @@ import GlobeLayer from 'Core/Prefab/Globe/GlobeLayer'; import Atmosphere from 'Core/Prefab/Globe/Atmosphere'; import CameraUtils from 'Utils/CameraUtils'; -import CRS from 'Core/Geographic/Crs'; import { ellipsoidSizes } from 'Core/Math/Ellipsoid'; /** diff --git a/src/Core/Prefab/Planar/PlanarLayer.js b/src/Core/Prefab/Planar/PlanarLayer.js index 0bee5987a8..d1fbb9f7d6 100644 --- a/src/Core/Prefab/Planar/PlanarLayer.js +++ b/src/Core/Prefab/Planar/PlanarLayer.js @@ -1,8 +1,8 @@ import * as THREE from 'three'; +import * as CRS from 'Core/Geographic/Crs'; import TiledGeometryLayer from 'Layer/TiledGeometryLayer'; import { globalExtentTMS } from 'Core/Tile/TileGrid'; -import CRS from 'Core/Geographic/Crs'; import PlanarTileBuilder from './PlanarTileBuilder'; /** diff --git a/src/Core/Tile/Tile.js b/src/Core/Tile/Tile.js index 1bd053a122..bda353c21f 100644 --- a/src/Core/Tile/Tile.js +++ b/src/Core/Tile/Tile.js @@ -1,6 +1,6 @@ import * as THREE from 'three'; +import * as CRS from '../Geographic/Crs'; import Coordinates from '../Geographic/Coordinates'; -import CRS from '../Geographic/Crs'; import Extent from '../Geographic/Extent'; import { getInfoTms, getCountTiles } from './TileGrid'; diff --git a/src/Core/Tile/TileGrid.js b/src/Core/Tile/TileGrid.js index 063b3c91ce..0a60f8d586 100644 --- a/src/Core/Tile/TileGrid.js +++ b/src/Core/Tile/TileGrid.js @@ -1,5 +1,5 @@ import * as THREE from 'three'; -import CRS from '../Geographic/Crs'; +import * as CRS from '../Geographic/Crs'; import Extent from '../Geographic/Extent'; const _countTiles = new THREE.Vector2(); diff --git a/src/Core/TileMesh.js b/src/Core/TileMesh.js index 675a2822bf..a647ee6f97 100644 --- a/src/Core/TileMesh.js +++ b/src/Core/TileMesh.js @@ -1,5 +1,5 @@ import * as THREE from 'three'; -import CRS from 'Core/Geographic/Crs'; +import * as CRS from 'Core/Geographic/Crs'; import { geoidLayerIsVisible } from 'Layer/GeoidLayer'; import { tiledCovering } from 'Core/Tile/Tile'; diff --git a/src/Core/View.js b/src/Core/View.js index 3465ee34ff..71a00bdd45 100644 --- a/src/Core/View.js +++ b/src/Core/View.js @@ -1,4 +1,5 @@ import * as THREE from 'three'; +import * as CRS from 'Core/Geographic/Crs'; import Camera from 'Renderer/Camera'; import initializeWebXR from 'Renderer/WebXR'; import MainLoop, { MAIN_LOOP_EVENTS, RENDERING_PAUSED } from 'Core/MainLoop'; @@ -6,7 +7,6 @@ import Capabilities from 'Core/System/Capabilities'; import { COLOR_LAYERS_ORDER_CHANGED } from 'Renderer/ColorLayersOrdering'; import c3DEngine from 'Renderer/c3DEngine'; import RenderMode from 'Renderer/RenderMode'; -import CRS from 'Core/Geographic/Crs'; import Coordinates from 'Core/Geographic/Coordinates'; import FeaturesUtils from 'Utils/FeaturesUtils'; import { getMaxColorSamplerUnitsCount } from 'Renderer/LayeredMaterial'; diff --git a/src/Main.js b/src/Main.js index fd2f7c3f6b..3b5d49c448 100644 --- a/src/Main.js +++ b/src/Main.js @@ -7,7 +7,7 @@ export const REVISION = conf.version; export { default as Extent } from 'Core/Geographic/Extent'; export { default as Coordinates } from 'Core/Geographic/Coordinates'; export { default as GeoidGrid } from 'Core/Geographic/GeoidGrid'; -export { default as CRS } from 'Core/Geographic/Crs'; +export * as CRS from 'Core/Geographic/Crs'; export { default as Ellipsoid, ellipsoidSizes } from 'Core/Math/Ellipsoid'; export { default as GlobeView, GLOBE_VIEW_EVENTS } from 'Core/Prefab/GlobeView'; diff --git a/src/Renderer/OBB.js b/src/Renderer/OBB.js index bd4c0a9974..6b00000986 100644 --- a/src/Renderer/OBB.js +++ b/src/Renderer/OBB.js @@ -1,8 +1,8 @@ import * as THREE from 'three'; +import * as CRS from 'Core/Geographic/Crs'; import TileGeometry from 'Core/TileGeometry'; import BuilderEllipsoidTile from 'Core/Prefab/Globe/BuilderEllipsoidTile'; import Coordinates from 'Core/Geographic/Coordinates'; -import CRS from 'Core/Geographic/Crs'; // get oriented bounding box of tile const builder = new BuilderEllipsoidTile({ crs: 'EPSG:4978', uvCount: 1 }); diff --git a/src/Renderer/RasterTile.js b/src/Renderer/RasterTile.js index 05e936cddc..a218be7b8b 100644 --- a/src/Renderer/RasterTile.js +++ b/src/Renderer/RasterTile.js @@ -1,7 +1,7 @@ import * as THREE from 'three'; +import * as CRS from 'Core/Geographic/Crs'; import { ELEVATION_MODES } from 'Renderer/LayeredMaterial'; import { checkNodeElevationTextureValidity, insertSignificantValuesFromParent, computeMinMaxElevation } from 'Parser/XbilParser'; -import CRS from 'Core/Geographic/Crs'; export const EMPTY_TEXTURE_ZOOM = -1; diff --git a/src/Source/FileSource.js b/src/Source/FileSource.js index b4dc474add..d5d7eda6bf 100644 --- a/src/Source/FileSource.js +++ b/src/Source/FileSource.js @@ -1,6 +1,6 @@ +import * as CRS from 'Core/Geographic/Crs'; import Source from 'Source/Source'; import Cache from 'Core/Scheduler/Cache'; -import CRS from 'Core/Geographic/Crs'; /** * An object defining the source of a single resource to get from a direct diff --git a/src/Source/Source.js b/src/Source/Source.js index d942276b7f..491e2de0c6 100644 --- a/src/Source/Source.js +++ b/src/Source/Source.js @@ -1,3 +1,4 @@ +import * as CRS from 'Core/Geographic/Crs'; import Extent from 'Core/Geographic/Extent'; import GeoJsonParser from 'Parser/GeoJsonParser'; import KMLParser from 'Parser/KMLParser'; @@ -8,7 +9,6 @@ import ISGParser from 'Parser/ISGParser'; import VectorTileParser from 'Parser/VectorTileParser'; import Fetcher from 'Provider/Fetcher'; import Cache from 'Core/Scheduler/Cache'; -import CRS from 'Core/Geographic/Crs'; /** @private */ export const supportedParsers = new Map([ diff --git a/src/Source/TMSSource.js b/src/Source/TMSSource.js index dbb51c1814..2359b98363 100644 --- a/src/Source/TMSSource.js +++ b/src/Source/TMSSource.js @@ -1,9 +1,9 @@ +import * as CRS from 'Core/Geographic/Crs'; import Source from 'Source/Source'; import URLBuilder from 'Provider/URLBuilder'; import Extent from 'Core/Geographic/Extent'; import Tile from 'Core/Tile/Tile'; import { globalExtentTMS } from 'Core/Tile/TileGrid'; -import CRS from 'Core/Geographic/Crs'; const _tile = new Tile(CRS.tms_4326, 0, 0, 0); diff --git a/src/Source/WFSSource.js b/src/Source/WFSSource.js index 73471dbb35..4f68286453 100644 --- a/src/Source/WFSSource.js +++ b/src/Source/WFSSource.js @@ -1,6 +1,6 @@ +import * as CRS from 'Core/Geographic/Crs'; import Source from 'Source/Source'; import URLBuilder from 'Provider/URLBuilder'; -import CRS from 'Core/Geographic/Crs'; import Extent from 'Core/Geographic/Extent'; const _extent = new Extent('EPSG:4326', [0, 0, 0, 0]); diff --git a/test/unit/crs.js b/test/unit/crs.js index bb754de8e3..f96d1d32d3 100644 --- a/test/unit/crs.js +++ b/test/unit/crs.js @@ -1,6 +1,6 @@ import assert from 'assert'; import proj4 from 'proj4'; -import CRS from 'Core/Geographic/Crs'; +import * as CRS from 'Core/Geographic/Crs'; proj4.defs('EPSG:7133', '+proj=longlat +ellps=GRS80 +no_defs +units=degrees'); proj4.defs('EPSG:INVALID', '+units=invalid +no_defs'); From 846f074abb605628ae8637a32df582d2a34aa3cc Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Sat, 16 Nov 2024 10:25:02 +0100 Subject: [PATCH 5/8] chore(Crs): update and refine documentation --- src/Core/Geographic/Crs.ts | 83 ++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/src/Core/Geographic/Crs.ts b/src/Core/Geographic/Crs.ts index b5513d2ce2..311967dc35 100644 --- a/src/Core/Geographic/Crs.ts +++ b/src/Core/Geographic/Crs.ts @@ -5,7 +5,9 @@ import type { ProjectionDefinition } from 'proj4'; proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs'); /** - * A projection as a CRS identifier string. + * A projection as a CRS identifier string. This identifier references a + * projection definition previously defined with + * [`proj4.defs`](https://github.com/proj4js/proj4js#named-projections). */ export type ProjectionLike = string; @@ -19,19 +21,31 @@ function mustBeString(crs: string) { } } +/** + * Checks that a given CRS identifier follows the TMS:XXXX format. + * @internal + * + * @param crs - The CRS identifier string. + */ export function isTms(crs: string) { return isString(crs) && crs.startsWith('TMS'); } +/** + * Checks that a given CRS identifier follows the EPSG:XXXX format. + * @internal + * + * @param crs - The CRS identifier string. + */ export function isEpsg(crs: string) { return isString(crs) && crs.startsWith('EPSG'); } /** - * Format crs to tile matrix set notation: TMS:XXXX. + * Converts the input to the tile matrix set notation: TMS:XXXX. + * @internal * - * @param crs - The crs to format - * @returns formated crs + * @param crs - The input to format. */ export function formatToTms(crs: string) { mustBeString(crs); @@ -39,10 +53,10 @@ export function formatToTms(crs: string) { } /** - * Format crs to European Petroleum Survey Group notation: EPSG:XXXX. + * Converts the input to European Petroleum Survey Group notation: EPSG:XXXX. + * @internal * - * @param crs - The crs to format - * @returns formated crs + * @param crs - The input to format. */ export function formatToEPSG(crs: string) { mustBeString(crs); @@ -50,18 +64,33 @@ export function formatToEPSG(crs: string) { } /** - * Units that can be used for a CRS. + * System units supported for a coordinate system. See + * [proj](https://proj4.org/en/9.5/operations/conversions/unitconvert.html#angular-units). + * Note that only degree and meters units are supported for now. */ export const UNIT = { + /** + * Angular unit in degree. + */ DEGREE: 1, + /** + * Distance unit in meter. + */ METER: 2, } as const; +/** + * @internal + */ export const tms_3857 = 'TMS:3857'; +/** + * @internal + */ export const tms_4326 = 'TMS:4326'; /** - * Is the CRS EPSG:4326? + * Checks that the CRS is EPSG:4326. + * @internal * * @param crs - The CRS to test. */ @@ -84,9 +113,9 @@ function unitFromProj4Unit(proj: ProjectionDefinition) { } /** - * Get the unit to use with the CRS. + * Returns the horizontal coordinates system units associated with this CRS. * - * @param crs - The CRS to get the unit from. + * @param crs - The CRS to extract the unit from. * @returns Either `UNIT.METER`, `UNIT.DEGREE` or `undefined`. */ export function toUnit(crs: ProjectionLike) { @@ -99,9 +128,9 @@ export function toUnit(crs: ProjectionLike) { } /** - * Assert that the CRS is using metric units. + * Asserts that the CRS is using metric units. * - * @param crs - The CRS to validate. + * @param crs - The CRS to check. * @throws {@link Error} if the CRS is not valid. */ export function isMetricUnit(crs: ProjectionLike) { @@ -109,9 +138,9 @@ export function isMetricUnit(crs: ProjectionLike) { } /** - * Assert that the CRS is geographic. + * Asserts that the CRS is geographic. * - * @param crs - The CRS to validate. + * @param crs - The CRS to check. * @throws {@link Error} if the CRS is not valid. */ export function isGeographic(crs: ProjectionLike) { @@ -119,10 +148,10 @@ export function isGeographic(crs: ProjectionLike) { } /** - * Is the CRS geocentric? - * if crs isn't defined the method returns false. + * Asserts that the CRS is geocentric. * * @param crs - The CRS to test. + * @returns false if the crs isn't defined. */ export function isGeocentric(crs: ProjectionLike) { mustBeString(crs); @@ -131,11 +160,11 @@ export function isGeocentric(crs: ProjectionLike) { } /** - * Assert that the CRS is a valid one. + * Asserts that the CRS is valid, meaning it has been previously defined and + * includes an unit. * - * @param crs - The CRS to validate. - * - * @throws {@link Error} if the CRS is not valid. + * @param crs - The CRS to test. + * @throws {@link Error} if the crs is not valid. */ export function isValid(crs: ProjectionLike) { const proj = proj4.defs(crs); @@ -148,7 +177,7 @@ export function isValid(crs: ProjectionLike) { } /** - * Give a reasonnable epsilon to use with this CRS. + * Gives a reasonnable epsilon for this CRS. * * @param crs - The CRS to use. * @returns 0.01 if the CRS is EPSG:4326, 0.001 otherwise. @@ -162,10 +191,12 @@ export function reasonnableEpsilon(crs: ProjectionLike) { } /** - * Define a proj4 projection as a string and reference. + * Defines a proj4 projection as a named alias. + * This function is a specialized wrapper over the + * [`proj4.defs`](https://github.com/proj4js/proj4js#named-projections) + * function. * - * @param code - projection's SRS code (only used internally by the Proj4js - * library) - * @param proj4def - Proj4 definition string for the projection to use + * @param code - Named alias of the currently defined projection. + * @param proj4def - Proj4 or WKT string of the defined projection. */ export const defs = (code: string, proj4def: string) => proj4.defs(code, proj4def); From 22c5d5cd002df86c0570be980ca1fe081d191eb7 Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Sat, 16 Nov 2024 10:36:48 +0100 Subject: [PATCH 6/8] fix(Crs): correctly renamed reasonableEpsilon function BREAKING CHANGE: CRS.reasonnableEspsilon renamed to CRS.reasonableEpsilon --- src/Core/Geographic/Crs.ts | 4 ++-- src/Core/Geographic/Extent.js | 2 +- test/unit/crs.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Core/Geographic/Crs.ts b/src/Core/Geographic/Crs.ts index 311967dc35..b53f2cee96 100644 --- a/src/Core/Geographic/Crs.ts +++ b/src/Core/Geographic/Crs.ts @@ -177,12 +177,12 @@ export function isValid(crs: ProjectionLike) { } /** - * Gives a reasonnable epsilon for this CRS. + * Gives a reasonable epsilon for this CRS. * * @param crs - The CRS to use. * @returns 0.01 if the CRS is EPSG:4326, 0.001 otherwise. */ -export function reasonnableEpsilon(crs: ProjectionLike) { +export function reasonableEpsilon(crs: ProjectionLike) { if (is4326(crs)) { return 0.01; } else { diff --git a/src/Core/Geographic/Extent.js b/src/Core/Geographic/Extent.js index 0fa844dfdb..10482b7fa9 100644 --- a/src/Core/Geographic/Extent.js +++ b/src/Core/Geographic/Extent.js @@ -234,7 +234,7 @@ class Extent { */ isInside(extent, epsilon) { extent.as(this.crs, _extent); - epsilon = epsilon == undefined ? CRS.reasonnableEpsilon(this.crs) : epsilon; + epsilon = epsilon ?? CRS.reasonableEpsilon(this.crs); return this.east - _extent.east <= epsilon && _extent.west - this.west <= epsilon && this.north - _extent.north <= epsilon && diff --git a/test/unit/crs.js b/test/unit/crs.js index f96d1d32d3..950299da77 100644 --- a/test/unit/crs.js +++ b/test/unit/crs.js @@ -49,8 +49,8 @@ describe('CRS assertions', function () { assert.ok(!CRS.isGeocentric('EPSG:3857')); }); - it('should return a reasonnable epsilon', function () { - assert.strictEqual(CRS.reasonnableEpsilon('EPSG:4326'), 0.01); - assert.strictEqual(CRS.reasonnableEpsilon('EPSG:3857'), 0.001); + it('should return a reasonable epsilon', function () { + assert.strictEqual(CRS.reasonableEpsilon('EPSG:4326'), 0.01); + assert.strictEqual(CRS.reasonableEpsilon('EPSG:3857'), 0.001); }); }); From 1a35131577b074dd03dd1a32f551ce01e77dc4f9 Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Sat, 16 Nov 2024 10:45:04 +0100 Subject: [PATCH 7/8] refacto(Crs): rename toUnit to getUnit BREAKING CHANGE: CRS.toUnit renamed to CRS.getUnit --- src/Core/Geographic/Crs.ts | 6 +++--- test/unit/crs.js | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Core/Geographic/Crs.ts b/src/Core/Geographic/Crs.ts index b53f2cee96..73bbcbddc7 100644 --- a/src/Core/Geographic/Crs.ts +++ b/src/Core/Geographic/Crs.ts @@ -118,7 +118,7 @@ function unitFromProj4Unit(proj: ProjectionDefinition) { * @param crs - The CRS to extract the unit from. * @returns Either `UNIT.METER`, `UNIT.DEGREE` or `undefined`. */ -export function toUnit(crs: ProjectionLike) { +export function getUnit(crs: ProjectionLike) { mustBeString(crs); const p = proj4.defs(formatToEPSG(crs)); if (!p) { @@ -134,7 +134,7 @@ export function toUnit(crs: ProjectionLike) { * @throws {@link Error} if the CRS is not valid. */ export function isMetricUnit(crs: ProjectionLike) { - return (toUnit(crs) == UNIT.METER); + return getUnit(crs) === UNIT.METER; } /** @@ -144,7 +144,7 @@ export function isMetricUnit(crs: ProjectionLike) { * @throws {@link Error} if the CRS is not valid. */ export function isGeographic(crs: ProjectionLike) { - return (toUnit(crs) == UNIT.DEGREE); + return getUnit(crs) === UNIT.DEGREE; } /** diff --git a/test/unit/crs.js b/test/unit/crs.js index 950299da77..4f9a1caff1 100644 --- a/test/unit/crs.js +++ b/test/unit/crs.js @@ -30,11 +30,11 @@ describe('CRS assertions', function () { }); it('should get the correct unit for this CRS', function () { - assert.strictEqual(CRS.toUnit('EPSG:4326'), CRS.UNIT.DEGREE); - assert.strictEqual(CRS.toUnit('EPSG:7133'), CRS.UNIT.DEGREE); - assert.strictEqual(CRS.toUnit('EPSG:4978'), CRS.UNIT.METER); - assert.strictEqual(CRS.toUnit('EPSG:3857'), CRS.UNIT.METER); - assert.strictEqual(CRS.toUnit('EPSG:INVALID'), undefined); + assert.strictEqual(CRS.getUnit('EPSG:4326'), CRS.UNIT.DEGREE); + assert.strictEqual(CRS.getUnit('EPSG:7133'), CRS.UNIT.DEGREE); + assert.strictEqual(CRS.getUnit('EPSG:4978'), CRS.UNIT.METER); + assert.strictEqual(CRS.getUnit('EPSG:3857'), CRS.UNIT.METER); + assert.strictEqual(CRS.getUnit('EPSG:INVALID'), undefined); }); it('should check if the CRS is EPSG:4326', function () { From 61c99df1cd1e6a33dbe2c25dd3ae5a5425b30729 Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Wed, 20 Nov 2024 18:50:03 +0100 Subject: [PATCH 8/8] refacto(Crs): remove tms/epsg family of functions BREAKING CHANGE: CRS.isEPSG and CRS.isTMS have been removed BREAKING CHANGE: CRS.formatToESPG and CRS.formatToTMS have been removed --- src/Converter/Feature2Mesh.js | 3 +- src/Converter/textureConverter.js | 3 +- src/Core/Feature.js | 3 +- src/Core/Geographic/Crs.ts | 53 +------------------ src/Core/Geographic/Extent.js | 4 -- src/Core/Prefab/Globe/GlobeLayer.js | 9 ++-- src/Core/Prefab/GlobeView.js | 6 +-- src/Core/Prefab/Planar/PlanarLayer.js | 4 +- src/Core/Tile/Tile.js | 6 +-- src/Core/Tile/TileGrid.js | 17 +++--- src/Core/TileMesh.js | 3 +- src/Core/View.js | 2 +- src/Renderer/OBB.js | 2 +- src/Renderer/RasterTile.js | 3 +- src/Source/FileSource.js | 3 +- src/Source/TMSSource.js | 5 +- src/Source/WFSSource.js | 3 +- test/functional/vector_tile_3d_mesh_mapbox.js | 2 +- test/unit/layeredmaterial.js | 2 +- test/unit/layeredmaterialnodeprocessing.js | 8 +-- test/unit/layerupdatestrategy.js | 8 +-- test/unit/provider_url.js | 4 +- test/unit/source.js | 10 ++-- test/unit/tile.js | 20 +++---- test/unit/tilemesh.js | 4 +- 25 files changed, 58 insertions(+), 129 deletions(-) diff --git a/src/Converter/Feature2Mesh.js b/src/Converter/Feature2Mesh.js index d3d4905ec9..85dca95ac1 100644 --- a/src/Converter/Feature2Mesh.js +++ b/src/Converter/Feature2Mesh.js @@ -1,5 +1,4 @@ import * as THREE from 'three'; -import * as Crs from 'Core/Geographic/Crs'; import Earcut from 'earcut'; import { FEATURE_TYPES } from 'Core/Feature'; import ReferLayerProperties from 'Layer/ReferencingLayerProperties'; @@ -64,7 +63,7 @@ class FeatureMesh extends THREE.Group { } else { // calculate the scale transformation to transform the feature.extent // to feature.extent.as(crs) - coord.crs = Crs.formatToEPSG(this.#originalCrs); + coord.crs = this.#originalCrs; // TODO: An extent here could be either a geographic extent (for // features from WFS) or a tiled extent (for features from MVT). // Unify both behavior. diff --git a/src/Converter/textureConverter.js b/src/Converter/textureConverter.js index 9db079146e..5455e9d96f 100644 --- a/src/Converter/textureConverter.js +++ b/src/Converter/textureConverter.js @@ -1,5 +1,4 @@ import * as THREE from 'three'; -import * as CRS from 'Core/Geographic/Crs'; import Feature2Texture from 'Converter/Feature2Texture'; import Extent from 'Core/Geographic/Extent'; @@ -27,7 +26,7 @@ export default { new THREE.Color(backgroundLayer.paint['background-color']) : undefined; - destinationTile.toExtent(CRS.formatToEPSG(layer.crs), extentTexture); + destinationTile.toExtent(layer.crs, extentTexture); texture = Feature2Texture.createTextureFromFeature(data, extentTexture, layer.subdivisionThreshold, layer.style, backgroundColor); texture.features = data; texture.extent = destinationTile; diff --git a/src/Core/Feature.js b/src/Core/Feature.js index 0e250a533b..018bb45c95 100644 --- a/src/Core/Feature.js +++ b/src/Core/Feature.js @@ -1,5 +1,4 @@ import * as THREE from 'three'; -import * as CRS from 'Core/Geographic/Crs'; import Extent from 'Core/Geographic/Extent'; import Coordinates from 'Core/Geographic/Coordinates'; import Style from 'Core/Style'; @@ -347,7 +346,7 @@ export class FeatureCollection extends THREE.Object3D { constructor(options) { super(); this.isFeatureCollection = true; - this.crs = CRS.formatToEPSG(options.accurate || !options.source?.crs ? options.crs : options.source.crs); + this.crs = options.accurate || !options.source?.crs ? options.crs : options.source.crs; this.features = []; this.mergeFeatures = options.mergeFeatures === undefined ? true : options.mergeFeatures; this.size = options.structure == '3d' ? 3 : 2; diff --git a/src/Core/Geographic/Crs.ts b/src/Core/Geographic/Crs.ts index 73bbcbddc7..9580dcfb77 100644 --- a/src/Core/Geographic/Crs.ts +++ b/src/Core/Geographic/Crs.ts @@ -21,48 +21,6 @@ function mustBeString(crs: string) { } } -/** - * Checks that a given CRS identifier follows the TMS:XXXX format. - * @internal - * - * @param crs - The CRS identifier string. - */ -export function isTms(crs: string) { - return isString(crs) && crs.startsWith('TMS'); -} - -/** - * Checks that a given CRS identifier follows the EPSG:XXXX format. - * @internal - * - * @param crs - The CRS identifier string. - */ -export function isEpsg(crs: string) { - return isString(crs) && crs.startsWith('EPSG'); -} - -/** - * Converts the input to the tile matrix set notation: TMS:XXXX. - * @internal - * - * @param crs - The input to format. - */ -export function formatToTms(crs: string) { - mustBeString(crs); - return isTms(crs) ? crs : `TMS:${crs.match(/\d+/)?.[0]}`; -} - -/** - * Converts the input to European Petroleum Survey Group notation: EPSG:XXXX. - * @internal - * - * @param crs - The input to format. - */ -export function formatToEPSG(crs: string) { - mustBeString(crs); - return isEpsg(crs) ? crs : `EPSG:${crs.match(/\d+/)?.[0]}`; -} - /** * System units supported for a coordinate system. See * [proj](https://proj4.org/en/9.5/operations/conversions/unitconvert.html#angular-units). @@ -79,15 +37,6 @@ export const UNIT = { METER: 2, } as const; -/** - * @internal - */ -export const tms_3857 = 'TMS:3857'; -/** - * @internal - */ -export const tms_4326 = 'TMS:4326'; - /** * Checks that the CRS is EPSG:4326. * @internal @@ -120,7 +69,7 @@ function unitFromProj4Unit(proj: ProjectionDefinition) { */ export function getUnit(crs: ProjectionLike) { mustBeString(crs); - const p = proj4.defs(formatToEPSG(crs)); + const p = proj4.defs(crs); if (!p) { return undefined; } diff --git a/src/Core/Geographic/Extent.js b/src/Core/Geographic/Extent.js index 10482b7fa9..39c9ddf1ab 100644 --- a/src/Core/Geographic/Extent.js +++ b/src/Core/Geographic/Extent.js @@ -49,10 +49,6 @@ class Extent { throw new Error(`${crs} is a geocentric projection, it doesn't make sense with a geographical extent`); } - if (CRS.isTms(crs)) { - throw new Error(`${crs} is a tiled projection, use Tile instead`); - } - this.isExtent = true; this.crs = crs; diff --git a/src/Core/Prefab/Globe/GlobeLayer.js b/src/Core/Prefab/Globe/GlobeLayer.js index 629b085e59..1fed4cd883 100644 --- a/src/Core/Prefab/Globe/GlobeLayer.js +++ b/src/Core/Prefab/Globe/GlobeLayer.js @@ -1,5 +1,4 @@ import * as THREE from 'three'; -import * as CRS from 'Core/Geographic/Crs'; import TiledGeometryLayer from 'Layer/TiledGeometryLayer'; import { ellipsoidSizes } from 'Core/Math/Ellipsoid'; import { globalExtentTMS, schemeTiles } from 'Core/Tile/TileGrid'; @@ -48,13 +47,13 @@ class GlobeLayer extends TiledGeometryLayer { */ constructor(id, object3d, config = {}) { // Configure tiles - const scheme = schemeTiles.get(CRS.tms_4326); + const scheme = schemeTiles.get('EPSG:4326'); const schemeTile = globalExtentTMS.get('EPSG:4326').subdivisionByScheme(scheme); // Supported tile matrix set for color/elevation layer config.tileMatrixSets = [ - CRS.tms_4326, - CRS.tms_3857, + 'EPSG:4326', + 'EPSG:3857', ]; const uvCount = config.tileMatrixSets.length; const builder = new BuilderEllipsoidTile({ crs: 'EPSG:4978', uvCount }); @@ -104,7 +103,7 @@ class GlobeLayer extends TiledGeometryLayer { subdivision(context, layer, node) { if (node.level == 5) { - const row = node.getExtentsByProjection(CRS.tms_4326)[0].row; + const row = node.getExtentsByProjection('EPSG:4326')[0].row; if (row == 31 || row == 0) { // doesn't subdivise the pole return false; diff --git a/src/Core/Prefab/GlobeView.js b/src/Core/Prefab/GlobeView.js index ce70a36ebb..ce90a53661 100644 --- a/src/Core/Prefab/GlobeView.js +++ b/src/Core/Prefab/GlobeView.js @@ -1,7 +1,5 @@ import * as THREE from 'three'; -import * as CRS from 'Core/Geographic/Crs'; - import View, { VIEW_EVENTS } from 'Core/View'; import GlobeControls from 'Controls/GlobeControls'; import Coordinates from 'Core/Geographic/Coordinates'; @@ -139,11 +137,11 @@ class GlobeView extends View { return Promise.reject(new Error('Add Layer type object')); } if (layer.isColorLayer) { - if (!this.tileLayer.tileMatrixSets.includes(CRS.formatToTms(layer.source.crs))) { + if (!this.tileLayer.tileMatrixSets.includes(layer.source.crs)) { return layer._reject(`Only ${this.tileLayer.tileMatrixSets} tileMatrixSet are currently supported for color layers`); } } else if (layer.isElevationLayer) { - if (CRS.formatToTms(layer.source.crs) !== this.tileLayer.tileMatrixSets[0]) { + if (layer.source.crs !== this.tileLayer.tileMatrixSets[0]) { return layer._reject(`Only ${this.tileLayer.tileMatrixSets[0]} tileMatrixSet is currently supported for elevation layers`); } } diff --git a/src/Core/Prefab/Planar/PlanarLayer.js b/src/Core/Prefab/Planar/PlanarLayer.js index d1fbb9f7d6..0a3bad7079 100644 --- a/src/Core/Prefab/Planar/PlanarLayer.js +++ b/src/Core/Prefab/Planar/PlanarLayer.js @@ -1,6 +1,5 @@ import * as THREE from 'three'; -import * as CRS from 'Core/Geographic/Crs'; import TiledGeometryLayer from 'Layer/TiledGeometryLayer'; import { globalExtentTMS } from 'Core/Tile/TileGrid'; import PlanarTileBuilder from './PlanarTileBuilder'; @@ -35,8 +34,7 @@ class PlanarLayer extends TiledGeometryLayer { * @throws {Error} `object3d` must be a valid `THREE.Object3d`. */ constructor(id, extent, object3d, config = {}) { - const tms = CRS.formatToTms(extent.crs); - const tileMatrixSets = [tms]; + const tileMatrixSets = [extent.crs]; if (!globalExtentTMS.get(extent.crs)) { // Add new global extent for this new crs projection. globalExtentTMS.set(extent.crs, extent); diff --git a/src/Core/Tile/Tile.js b/src/Core/Tile/Tile.js index bda353c21f..d0912b7c90 100644 --- a/src/Core/Tile/Tile.js +++ b/src/Core/Tile/Tile.js @@ -169,10 +169,10 @@ class Tile { * @returns {Tile[]} */ export function tiledCovering(e, tms) { - if (e.crs == 'EPSG:4326' && tms == CRS.tms_3857) { + if (e.crs == 'EPSG:4326' && tms == 'EPSG:3857') { const WMTS_PM = []; - const extent = _extent.copy(e).as(CRS.formatToEPSG(tms), _extent2); - const { globalExtent, globalDimension, sTs } = getInfoTms(CRS.formatToEPSG(tms)); + const extent = _extent.copy(e).as(tms, _extent2); + const { globalExtent, globalDimension, sTs } = getInfoTms(tms); extent.clampByExtent(globalExtent); extent.planarDimensions(_dimensionTile); diff --git a/src/Core/Tile/TileGrid.js b/src/Core/Tile/TileGrid.js index 0a60f8d586..a6eb619b35 100644 --- a/src/Core/Tile/TileGrid.js +++ b/src/Core/Tile/TileGrid.js @@ -1,5 +1,4 @@ import * as THREE from 'three'; -import * as CRS from '../Geographic/Crs'; import Extent from '../Geographic/Extent'; const _countTiles = new THREE.Vector2(); @@ -19,27 +18,25 @@ extent3857.clampSouthNorth(extent3857.west, extent3857.east); globalExtentTMS.set('EPSG:3857', extent3857); schemeTiles.set('default', new THREE.Vector2(1, 1)); -schemeTiles.set(CRS.tms_3857, schemeTiles.get('default')); -schemeTiles.set(CRS.tms_4326, new THREE.Vector2(2, 1)); +schemeTiles.set('EPSG:3857', schemeTiles.get('default')); +schemeTiles.set('EPSG:4326', new THREE.Vector2(2, 1)); export function getInfoTms(/** @type {string} */ crs) { - const epsg = CRS.formatToEPSG(crs); - const globalExtent = globalExtentTMS.get(epsg); + const globalExtent = globalExtentTMS.get(crs); const globalDimension = globalExtent.planarDimensions(_dim); - const tms = CRS.formatToTms(crs); - const sTs = schemeTiles.get(tms) || schemeTiles.get('default'); + const sTs = schemeTiles.get(crs) || schemeTiles.get('default'); // The isInverted parameter is to be set to the correct value, true or false // (default being false) if the computation of the coordinates needs to be // inverted to match the same scheme as OSM, Google Maps or other system. // See link below for more information // https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/ // in crs includes ':NI' => tms isn't inverted (NOT INVERTED) - const isInverted = !tms.includes(':NI'); - return { epsg, globalExtent, globalDimension, sTs, isInverted }; + const isInverted = !crs.includes(':NI'); + return { epsg: crs, globalExtent, globalDimension, sTs, isInverted }; } export function getCountTiles(/** @type {string} */ crs, /** @type {number} */ zoom) { - const sTs = schemeTiles.get(CRS.formatToTms(crs)) || schemeTiles.get('default'); + const sTs = schemeTiles.get(crs) || schemeTiles.get('default'); const count = 2 ** zoom; _countTiles.set(count, count).multiply(sTs); return _countTiles; diff --git a/src/Core/TileMesh.js b/src/Core/TileMesh.js index a647ee6f97..a12b4f967a 100644 --- a/src/Core/TileMesh.js +++ b/src/Core/TileMesh.js @@ -1,5 +1,4 @@ import * as THREE from 'three'; -import * as CRS from 'Core/Geographic/Crs'; import { geoidLayerIsVisible } from 'Layer/GeoidLayer'; import { tiledCovering } from 'Core/Tile/Tile'; @@ -77,7 +76,7 @@ class TileMesh extends THREE.Mesh { } getExtentsByProjection(crs) { - return this.#_tms.get(CRS.formatToTms(crs)); + return this.#_tms.get(crs); } /** diff --git a/src/Core/View.js b/src/Core/View.js index 71a00bdd45..72dff1f4ea 100644 --- a/src/Core/View.js +++ b/src/Core/View.js @@ -55,7 +55,7 @@ function _preprocessLayer(view, layer, parentLayer) { // Find crs projection layer, this is projection destination layer.crs = view.referenceCrs; } else if (!layer.crs) { - if (parentLayer && parentLayer.tileMatrixSets && parentLayer.tileMatrixSets.includes(CRS.formatToTms(source.crs))) { + if (parentLayer && parentLayer.tileMatrixSets && parentLayer.tileMatrixSets.includes(source.crs)) { layer.crs = source.crs; } else { layer.crs = parentLayer && parentLayer.extent.crs; diff --git a/src/Renderer/OBB.js b/src/Renderer/OBB.js index 6b00000986..567cce69f6 100644 --- a/src/Renderer/OBB.js +++ b/src/Renderer/OBB.js @@ -126,7 +126,7 @@ class OBB extends THREE.Object3D { this.position.copy(position); this.quaternion.copy(quaternion); this.updateMatrixWorld(true); - } else if (!CRS.isTms(extent.crs) && CRS.isMetricUnit(extent.crs)) { + } else if (CRS.isMetricUnit(extent.crs)) { extent.center(coord).toVector3(this.position); extent.planarDimensions(dimension); size.set(dimension.x, dimension.y, Math.abs(maxHeight - minHeight)); diff --git a/src/Renderer/RasterTile.js b/src/Renderer/RasterTile.js index a218be7b8b..af87699426 100644 --- a/src/Renderer/RasterTile.js +++ b/src/Renderer/RasterTile.js @@ -1,5 +1,4 @@ import * as THREE from 'three'; -import * as CRS from 'Core/Geographic/Crs'; import { ELEVATION_MODES } from 'Renderer/LayeredMaterial'; import { checkNodeElevationTextureValidity, insertSignificantValuesFromParent, computeMinMaxElevation } from 'Parser/XbilParser'; @@ -32,7 +31,7 @@ class RasterTile extends THREE.EventDispatcher { constructor(material, layer) { super(); this.layer = layer; - this.crs = layer.parent.tileMatrixSets.indexOf(CRS.formatToTms(layer.crs)); + this.crs = layer.parent.tileMatrixSets.indexOf(layer.crs); if (this.crs == -1) { console.error('Unknown crs:', layer.crs); } diff --git a/src/Source/FileSource.js b/src/Source/FileSource.js index d5d7eda6bf..a65ce63271 100644 --- a/src/Source/FileSource.js +++ b/src/Source/FileSource.js @@ -1,4 +1,3 @@ -import * as CRS from 'Core/Geographic/Crs'; import Source from 'Source/Source'; import Cache from 'Core/Scheduler/Cache'; @@ -159,7 +158,7 @@ class FileSource extends Source { if (!features) { options.out.buildExtent = this.crs != 'EPSG:4978'; if (options.out.buildExtent) { - options.out.forcedExtentCrs = options.out.crs != 'EPSG:4978' ? options.out.crs : CRS.formatToEPSG(this.crs); + options.out.forcedExtentCrs = options.out.crs != 'EPSG:4978' ? options.out.crs : this.crs; } features = this.parser(this.fetchedData, options); this._featuresCaches[options.out.crs].setByArray(features, [0]); diff --git a/src/Source/TMSSource.js b/src/Source/TMSSource.js index 2359b98363..6d669ceec3 100644 --- a/src/Source/TMSSource.js +++ b/src/Source/TMSSource.js @@ -1,11 +1,10 @@ -import * as CRS from 'Core/Geographic/Crs'; import Source from 'Source/Source'; import URLBuilder from 'Provider/URLBuilder'; import Extent from 'Core/Geographic/Extent'; import Tile from 'Core/Tile/Tile'; import { globalExtentTMS } from 'Core/Tile/TileGrid'; -const _tile = new Tile(CRS.tms_4326, 0, 0, 0); +const _tile = new Tile('EPSG:4326', 0, 0, 0); /** * An object defining the source of resources to get from a @@ -95,7 +94,7 @@ class TMSSource extends Source { this.zoom = source.zoom; this.isInverted = source.isInverted || false; - this.crs = CRS.formatToTms(source.crs); + this.crs = source.crs; this.tileMatrixSetLimits = source.tileMatrixSetLimits; this.extentSetlimits = {}; this.tileMatrixCallback = source.tileMatrixCallback || (zoomLevel => zoomLevel); diff --git a/src/Source/WFSSource.js b/src/Source/WFSSource.js index 4f68286453..5d2c771fa6 100644 --- a/src/Source/WFSSource.js +++ b/src/Source/WFSSource.js @@ -1,4 +1,3 @@ -import * as CRS from 'Core/Geographic/Crs'; import Source from 'Source/Source'; import URLBuilder from 'Provider/URLBuilder'; import Extent from 'Core/Geographic/Extent'; @@ -161,7 +160,7 @@ class WFSSource extends Source { } requestToKey(extent) { - if (CRS.isTms(extent.crs)) { + if (extent.isTile) { return super.requestToKey(extent); } else { return [extent.zoom, extent.south, extent.west]; diff --git a/test/functional/vector_tile_3d_mesh_mapbox.js b/test/functional/vector_tile_3d_mesh_mapbox.js index 98093a678b..b307e8e0cc 100644 --- a/test/functional/vector_tile_3d_mesh_mapbox.js +++ b/test/functional/vector_tile_3d_mesh_mapbox.js @@ -13,7 +13,7 @@ describe('vector_tile_3d_mesh_mapbox', function _describe() { it('should correctly load building features on a given TMS tile', async function _it() { const featuresCollection = await page.evaluate(async function _() { const layers = view.getLayers(l => l.source && l.source.isVectorSource); - const res = await layers[0].source.loadData({ zoom: 15, row: 11634, col: 16859 }, { crs: 'EPSG:4978', source: { crs: 'TMS:3857' } }); + const res = await layers[0].source.loadData({ zoom: 15, row: 11634, col: 16859 }, { crs: 'EPSG:4978', source: { crs: 'EPSG:3857' } }); return res; }); assert.ok(featuresCollection.isFeatureCollection); diff --git a/test/unit/layeredmaterial.js b/test/unit/layeredmaterial.js index 6a4fe7a85e..89f171abf0 100644 --- a/test/unit/layeredmaterial.js +++ b/test/unit/layeredmaterial.js @@ -35,7 +35,7 @@ describe('material state vs layer state', function () { view.tileLayer.colorLayersOrder = [layer.id]; view.addLayer(layer); - const extent = new Tile('TMS:4326', 3, 0, 0).toExtent('EPSG:4326'); + const extent = new Tile('EPSG:4326', 3, 0, 0).toExtent('EPSG:4326'); material = new LayeredMaterial(); const geom = new THREE.BufferGeometry(); geom.OBB = new OBB(new THREE.Vector3(), new THREE.Vector3(1, 1, 1)); diff --git a/test/unit/layeredmaterialnodeprocessing.js b/test/unit/layeredmaterialnodeprocessing.js index 9aae1ea00c..0f7e92af02 100644 --- a/test/unit/layeredmaterialnodeprocessing.js +++ b/test/unit/layeredmaterialnodeprocessing.js @@ -41,12 +41,12 @@ describe('updateLayeredMaterialNodeImagery', function () { crs: 'EPSG:4326', info: { update: () => {} }, tileMatrixSets: [ - 'TMS:4326', - 'TMS:3857', + 'EPSG:4326', + 'EPSG:3857', ], parent: { tileMatrixSets: [ - 'TMS:4326', - 'TMS:3857', + 'EPSG:4326', + 'EPSG:3857', ], }, }); diff --git a/test/unit/layerupdatestrategy.js b/test/unit/layerupdatestrategy.js index 2e4ebe488a..89b7abceda 100644 --- a/test/unit/layerupdatestrategy.js +++ b/test/unit/layerupdatestrategy.js @@ -44,12 +44,12 @@ describe('Handling no data source error', function () { crs: 'EPSG:4326', info: { update: () => {} }, tileMatrixSets: [ - 'TMS:4326', - 'TMS:3857', + 'EPSG:4326', + 'EPSG:3857', ], parent: { tileMatrixSets: [ - 'TMS:4326', - 'TMS:3857', + 'EPSG:4326', + 'EPSG:3857', ], }, }); diff --git a/test/unit/provider_url.js b/test/unit/provider_url.js index 599dc94249..28a714e95f 100644 --- a/test/unit/provider_url.js +++ b/test/unit/provider_url.js @@ -8,14 +8,14 @@ describe('URL creations', function () { const layer = { tileMatrixCallback: (zoomLevel => zoomLevel) }; it('should correctly replace ${x}, ${y} and ${z} by 359, 512 and 10', function () { - const coords = new Tile('TMS:4857', 10, 512, 359); + const coords = new Tile('EPSG:4857', 10, 512, 359); layer.url = 'http://server.geo/tms/${z}/${y}/${x}.jpg'; const result = URLBuilder.xyz(coords, layer); assert.equal(result, 'http://server.geo/tms/10/512/359.jpg'); }); it('should correctly replace %COL, %ROW, %TILEMATRIX by 2072, 1410 and 12', function () { - const coords = new Tile('TMS:4326', 12, 1410, 2072); + const coords = new Tile('EPSG:4326', 12, 1410, 2072); layer.url = 'http://server.geo/wmts/SERVICE=WMTS&TILEMATRIX=%TILEMATRIX&TILEROW=%ROW&TILECOL=%COL'; const result = URLBuilder.xyz(coords, layer); assert.equal(result, 'http://server.geo/wmts/SERVICE=WMTS&TILEMATRIX=12&TILEROW=1410&TILECOL=2072'); diff --git a/test/unit/source.js b/test/unit/source.js index 2a3a404d06..9e9d5a9b22 100644 --- a/test/unit/source.js +++ b/test/unit/source.js @@ -79,7 +79,7 @@ describe('Sources', function () { it('should return keys from request', function () { const source = new WFSSource(paramsWFS); - const tile = new Tile('TMS:4326', 5, 10, 15); + const tile = new Tile('EPSG:4326', 5, 10, 15); const keys = source.requestToKey(tile); assert.equal(tile.zoom, keys[0]); assert.equal(tile.row, keys[1]); @@ -105,7 +105,7 @@ describe('Sources', function () { it('should instance and use WMTSSource', function () { const source = new WMTSSource(paramsWMTS); - const extent = new Tile('TMS:3857', 5, 0, 0); + const extent = new Tile('EPSG:3857', 5, 0, 0); assert.ok(source.isWMTSSource); assert.ok(source.urlFromExtent(extent)); assert.ok(source.extentInsideLimit(extent, 5)); @@ -122,7 +122,7 @@ describe('Sources', function () { 5: { minTileRow: 0, maxTileRow: 32, minTileCol: 0, maxTileCol: 32 }, }; const source = new WMTSSource(paramsWMTS); - const extent = new Tile('TMS:3857', 5, 0, 0); + const extent = new Tile('EPSG:3857', 5, 0, 0); source.onLayerAdded({ out: { crs: 'EPSG:4326' } }); assert.ok(source.isWMTSSource); assert.ok(source.urlFromExtent(extent)); @@ -132,7 +132,7 @@ describe('Sources', function () { it('should use vendor specific parameters for the creation of the WMTS url', function () { paramsWMTS.vendorSpecific = vendorSpecific; const source = new WMTSSource(paramsWMTS); - const tile = new Tile('TMS:4326', 0, 10, 0); + const tile = new Tile('EPSG:4326', 0, 10, 0); const url = source.urlFromExtent(tile); const end = '&buffer=4096&format_options=dpi:300;quantizer:octree&tiled=true'; assert.ok(url.endsWith(end)); @@ -203,7 +203,7 @@ describe('Sources', function () { it('should instance and use TMSSource', function () { const source = new TMSSource(paramsTMS); source.onLayerAdded({ out: { crs: 'EPSG:4326' } }); - const extent = new Tile('TMS:3857', 5, 0, 0); + const extent = new Tile('EPSG:3857', 5, 0, 0); assert.ok(source.isTMSSource); assert.ok(source.urlFromExtent(extent)); assert.ok(source.extentInsideLimit(extent, extent.zoom)); diff --git a/test/unit/tile.js b/test/unit/tile.js index 3512ef27c5..845c29f5b5 100644 --- a/test/unit/tile.js +++ b/test/unit/tile.js @@ -9,24 +9,24 @@ describe('Tile', function () { const row = 22; const col = 10; - it('should convert tile TMS:4326 like expected', function () { - const withValues = new Tile('TMS:4326', 0, 0, 0).toExtent('EPSG:4326'); + it('should convert tile EPSG:4326 like expected', function () { + const withValues = new Tile('EPSG:4326', 0, 0, 0).toExtent('EPSG:4326'); assert.equal(-180, withValues.west); assert.equal(0, withValues.east); assert.equal(-90, withValues.south); assert.equal(90, withValues.north); }); - it('should convert TMS:3857 tile to EPSG:3857 extent like expected', function () { - const withValues = new Tile('TMS:3857', 0, 0, 0).toExtent('EPSG:3857'); + it('should convert EPSG:3857 tile to EPSG:3857 extent like expected', function () { + const withValues = new Tile('EPSG:3857', 0, 0, 0).toExtent('EPSG:3857'); assert.equal(-20037508.342789244, withValues.west); assert.equal(20037508.342789244, withValues.east); assert.equal(-20037508.342789244, withValues.south); assert.equal(20037508.342789244, withValues.north); }); - it('should convert TMS:3857 tile to EPSG:4326 extent like expected', function () { - const withValues = new Tile('TMS:3857', 0, 0, 0); + it('should convert EPSG:3857 tile to EPSG:4326 extent like expected', function () { + const withValues = new Tile('EPSG:3857', 0, 0, 0); const result = withValues.toExtent('EPSG:4326'); assert.equal(-180.00000000000003, result.west); assert.equal(180.00000000000003, result.east); @@ -35,8 +35,8 @@ describe('Tile', function () { }); it('should return expected offset using tiled extent', function () { - const withValues = new Tile('TMS:4326', zoom, row, col); - const parent = new Tile('TMS:4326', zoom - 2, row, col); + const withValues = new Tile('EPSG:4326', zoom, row, col); + const parent = new Tile('EPSG:4326', zoom - 2, row, col); const offset = withValues.offsetToParent(parent); assert.equal(offset.x, 0.5); assert.equal(offset.y, 0.5); @@ -45,7 +45,7 @@ describe('Tile', function () { }); it('should return expected tiled extent parent', function () { - const withValues = new Tile('TMS:4326', zoom, row, col); + const withValues = new Tile('EPSG:4326', zoom, row, col); const parent = withValues.tiledExtentParent(zoom - 2); assert.equal(parent.zoom, 3); assert.equal(parent.row, 5); @@ -53,7 +53,7 @@ describe('Tile', function () { }); it('should convert TMS extent values to string', function () { - const withValues = new Tile('TMS:4326', 0, 1, 2); + const withValues = new Tile('EPSG:4326', 0, 1, 2); const tostring = withValues.toString(','); const toValues = tostring.split(',').map(s => Number(s)); assert.equal(toValues[0], withValues.zoom); diff --git a/test/unit/tilemesh.js b/test/unit/tilemesh.js index efe12df674..bcdca3e261 100644 --- a/test/unit/tilemesh.js +++ b/test/unit/tilemesh.js @@ -23,7 +23,7 @@ FakeTileMesh.prototype.constructor = FakeTileMesh; FakeTileMesh.prototype.findCommonAncestor = TileMesh.prototype.findCommonAncestor; describe('TileMesh', function () { - const tile = new Tile('TMS:3857', 5, 10, 10); + const tile = new Tile('EPSG:3857', 5, 10, 10); const geom = new THREE.BufferGeometry(); geom.OBB = new OBB(); @@ -221,7 +221,7 @@ describe('TileMesh', function () { const tileMesh = new TileMesh(geom, material, planarlayer, tile.toExtent('EPSG:3857'), 0); const rasterNode = elevationLayer.setupRasterNode(tileMesh); const texture = new THREE.Texture(); - texture.extent = new Tile('TMS:3857', 4, 10, 10); + texture.extent = new Tile('EPSG:3857', 4, 10, 10); texture.image = { width: 3, height: 3,