@itowns/geographic 2.45.1 → 2.45.2-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Coordinates.d.ts +7 -7
- package/lib/Coordinates.js +2 -2
- package/lib/Crs.d.ts +9 -9
- package/lib/Extent.d.ts +6 -6
- package/lib/Extent.js +2 -2
- package/lib/OrientationUtils.d.ts +1 -1
- package/lib/OrientationUtils.js +12 -10
- package/package.json +8 -6
- package/src/Coordinates.ts +10 -9
- package/src/Crs.ts +10 -10
- package/src/Extent.ts +6 -6
- package/src/OrientationUtils.ts +19 -11
package/lib/Coordinates.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProjectionAlias } from './Crs';
|
|
3
3
|
export interface CoordinatesLike {
|
|
4
4
|
readonly crs: string;
|
|
5
5
|
readonly x: number;
|
|
@@ -44,9 +44,9 @@ declare class Coordinates {
|
|
|
44
44
|
*/
|
|
45
45
|
readonly isCoordinates: boolean;
|
|
46
46
|
/**
|
|
47
|
-
* A default or user-defined CRS (see {@link
|
|
47
|
+
* A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
48
48
|
*/
|
|
49
|
-
crs:
|
|
49
|
+
crs: ProjectionAlias;
|
|
50
50
|
/** The x value (or longitude) of this coordinate. */
|
|
51
51
|
x: number;
|
|
52
52
|
/** The y value (or latitude) of this coordinate. */
|
|
@@ -56,17 +56,17 @@ declare class Coordinates {
|
|
|
56
56
|
private _normal;
|
|
57
57
|
private _normalNeedsUpdate;
|
|
58
58
|
/**
|
|
59
|
-
* @param crs - A default or user-defined CRS (see {@link
|
|
59
|
+
* @param crs - A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
60
60
|
* @param x - x or longitude value.
|
|
61
61
|
* @param y - y or latitude value.
|
|
62
62
|
* @param z - z or altitude value.
|
|
63
63
|
*/
|
|
64
|
-
constructor(crs:
|
|
64
|
+
constructor(crs: ProjectionAlias, x?: number, y?: number, z?: number);
|
|
65
65
|
/**
|
|
66
66
|
* Sets the Coordinate Reference System.
|
|
67
67
|
* @param crs - Coordinate Reference System (e.g. 'EPSG:4978')
|
|
68
68
|
*/
|
|
69
|
-
setCrs(crs:
|
|
69
|
+
setCrs(crs: ProjectionAlias): this;
|
|
70
70
|
/**
|
|
71
71
|
* Sets the x, y and z components of this coordinate.
|
|
72
72
|
*
|
|
@@ -191,6 +191,6 @@ declare class Coordinates {
|
|
|
191
191
|
* const geographicCoords = geocentricCoords.as('EPSG:4326');
|
|
192
192
|
* ```
|
|
193
193
|
*/
|
|
194
|
-
as(crs:
|
|
194
|
+
as(crs: ProjectionAlias, target?: Coordinates): Coordinates;
|
|
195
195
|
}
|
|
196
196
|
export default Coordinates;
|
package/lib/Coordinates.js
CHANGED
|
@@ -56,7 +56,7 @@ class Coordinates {
|
|
|
56
56
|
*/
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* A default or user-defined CRS (see {@link
|
|
59
|
+
* A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
60
60
|
*/
|
|
61
61
|
|
|
62
62
|
/** The x value (or longitude) of this coordinate. */
|
|
@@ -66,7 +66,7 @@ class Coordinates {
|
|
|
66
66
|
/** The z value (or altitude) of this coordinate. */
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
* @param crs - A default or user-defined CRS (see {@link
|
|
69
|
+
* @param crs - A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
70
70
|
* @param x - x or longitude value.
|
|
71
71
|
* @param y - y or latitude value.
|
|
72
72
|
* @param z - z or altitude value.
|
package/lib/Crs.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* projection definition previously defined with
|
|
4
4
|
* [`proj4.defs`](https://github.com/proj4js/proj4js#named-projections).
|
|
5
5
|
*/
|
|
6
|
-
export type
|
|
6
|
+
export type ProjectionAlias = string;
|
|
7
7
|
/**
|
|
8
8
|
* System units supported for a coordinate system. See
|
|
9
9
|
* [proj](https://proj4.org/en/9.5/operations/conversions/unitconvert.html#angular-units).
|
|
@@ -29,35 +29,35 @@ export declare const UNIT: {
|
|
|
29
29
|
*
|
|
30
30
|
* @param crs - The CRS to test.
|
|
31
31
|
*/
|
|
32
|
-
export declare function is4326(crs:
|
|
32
|
+
export declare function is4326(crs: ProjectionAlias): crs is "EPSG:4326";
|
|
33
33
|
/**
|
|
34
34
|
* Returns the horizontal coordinates system units associated with this CRS.
|
|
35
35
|
*
|
|
36
36
|
* @param crs - The CRS to extract the unit from.
|
|
37
37
|
* @returns Either `UNIT.METER`, `UNIT.DEGREE`, `UNIT.FOOT` or `undefined`.
|
|
38
38
|
*/
|
|
39
|
-
export declare function getUnit(crs:
|
|
39
|
+
export declare function getUnit(crs: ProjectionAlias): 1 | 2 | 3 | undefined;
|
|
40
40
|
/**
|
|
41
41
|
* Asserts that the CRS is using metric units.
|
|
42
42
|
*
|
|
43
43
|
* @param crs - The CRS to check.
|
|
44
44
|
* @throws {@link Error} if the CRS is not valid.
|
|
45
45
|
*/
|
|
46
|
-
export declare function isMetricUnit(crs:
|
|
46
|
+
export declare function isMetricUnit(crs: ProjectionAlias): boolean;
|
|
47
47
|
/**
|
|
48
48
|
* Asserts that the CRS is geographic.
|
|
49
49
|
*
|
|
50
50
|
* @param crs - The CRS to check.
|
|
51
51
|
* @throws {@link Error} if the CRS is not valid.
|
|
52
52
|
*/
|
|
53
|
-
export declare function isGeographic(crs:
|
|
53
|
+
export declare function isGeographic(crs: ProjectionAlias): boolean;
|
|
54
54
|
/**
|
|
55
55
|
* Asserts that the CRS is geocentric.
|
|
56
56
|
*
|
|
57
57
|
* @param crs - The CRS to test.
|
|
58
58
|
* @returns false if the crs isn't defined.
|
|
59
59
|
*/
|
|
60
|
-
export declare function isGeocentric(crs:
|
|
60
|
+
export declare function isGeocentric(crs: ProjectionAlias): boolean;
|
|
61
61
|
/**
|
|
62
62
|
* Asserts that the CRS is valid, meaning it has been previously defined and
|
|
63
63
|
* includes an unit.
|
|
@@ -65,14 +65,14 @@ export declare function isGeocentric(crs: ProjectionLike): boolean;
|
|
|
65
65
|
* @param crs - The CRS to test.
|
|
66
66
|
* @throws {@link Error} if the crs is not valid.
|
|
67
67
|
*/
|
|
68
|
-
export declare function isValid(crs:
|
|
68
|
+
export declare function isValid(crs: ProjectionAlias): void;
|
|
69
69
|
/**
|
|
70
70
|
* Gives a reasonable epsilon for this CRS.
|
|
71
71
|
*
|
|
72
72
|
* @param crs - The CRS to use.
|
|
73
73
|
* @returns 0.01 if the CRS is EPSG:4326, 0.001 otherwise.
|
|
74
74
|
*/
|
|
75
|
-
export declare function reasonableEpsilon(crs:
|
|
75
|
+
export declare function reasonableEpsilon(crs: ProjectionAlias): 0.01 | 0.001;
|
|
76
76
|
/**
|
|
77
77
|
* Returns the axis parameter defined in proj4 for the provided crs.
|
|
78
78
|
* Might be undefined depending on crs definition.
|
|
@@ -80,7 +80,7 @@ export declare function reasonableEpsilon(crs: ProjectionLike): 0.01 | 0.001;
|
|
|
80
80
|
* @param crs - The CRS to get axis from.
|
|
81
81
|
* @returns the matching proj4 axis string, 'enu' for instance (east, north, up)
|
|
82
82
|
*/
|
|
83
|
-
export declare function axisOrder(crs:
|
|
83
|
+
export declare function axisOrder(crs: ProjectionAlias): string | undefined;
|
|
84
84
|
/**
|
|
85
85
|
* Defines a proj4 projection as a named alias.
|
|
86
86
|
* This function is a specialized wrapper over the
|
package/lib/Extent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import Coordinates from './Coordinates';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ProjectionAlias } from './Crs';
|
|
4
4
|
export interface ExtentLike {
|
|
5
5
|
readonly west: number;
|
|
6
6
|
readonly east: number;
|
|
@@ -22,9 +22,9 @@ declare class Extent {
|
|
|
22
22
|
*/
|
|
23
23
|
readonly isExtent: true;
|
|
24
24
|
/**
|
|
25
|
-
* A default or user-defined CRS (see {@link
|
|
25
|
+
* A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
26
26
|
*/
|
|
27
|
-
crs:
|
|
27
|
+
crs: ProjectionAlias;
|
|
28
28
|
/**
|
|
29
29
|
* West longitude bound of this extent.
|
|
30
30
|
*/
|
|
@@ -42,13 +42,13 @@ declare class Extent {
|
|
|
42
42
|
*/
|
|
43
43
|
north: number;
|
|
44
44
|
/**
|
|
45
|
-
* @param crs - A default or user-defined CRS (see {@link
|
|
45
|
+
* @param crs - A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
46
46
|
* @param west - the `west` value of this extent. Default is 0.
|
|
47
47
|
* @param east - the `east` value of this extent. Default is 0.
|
|
48
48
|
* @param south - the `south` value of this extent. Default is 0.
|
|
49
49
|
* @param north - the `north` value of this extent. Default is 0.
|
|
50
50
|
*/
|
|
51
|
-
constructor(crs:
|
|
51
|
+
constructor(crs: ProjectionAlias, west?: number, east?: number, south?: number, north?: number);
|
|
52
52
|
/**
|
|
53
53
|
* Returns a new extent with the same bounds and crs as this one.
|
|
54
54
|
*/
|
|
@@ -190,7 +190,7 @@ declare class Extent {
|
|
|
190
190
|
* @param crs - Projection of extent to instancied.
|
|
191
191
|
* @param box - Bounding-box
|
|
192
192
|
*/
|
|
193
|
-
static fromBox3(crs:
|
|
193
|
+
static fromBox3(crs: ProjectionAlias, box: THREE.Box3): Extent;
|
|
194
194
|
/**
|
|
195
195
|
* Return values of extent in string, separated by the separator input.
|
|
196
196
|
* @param sep - string separator
|
package/lib/Extent.js
CHANGED
|
@@ -31,7 +31,7 @@ class Extent {
|
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* A default or user-defined CRS (see {@link
|
|
34
|
+
* A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
37
|
/**
|
|
@@ -51,7 +51,7 @@ class Extent {
|
|
|
51
51
|
*/
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* @param crs - A default or user-defined CRS (see {@link
|
|
54
|
+
* @param crs - A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
55
55
|
* @param west - the `west` value of this extent. Default is 0.
|
|
56
56
|
* @param east - the `east` value of this extent. Default is 0.
|
|
57
57
|
* @param south - the `south` value of this extent. Default is 0.
|
package/lib/OrientationUtils.js
CHANGED
|
@@ -325,13 +325,14 @@ export function quaternionFromEnuToCRS(crsOrProj, coordinates) {
|
|
|
325
325
|
if (coordinates) {
|
|
326
326
|
return quaternionFromEnuToCRS(crsOrProj)(coordinates, target);
|
|
327
327
|
}
|
|
328
|
-
const proj = typeof crsOrProj === 'string' ? proj4
|
|
329
|
-
|
|
330
|
-
|
|
328
|
+
const proj = typeof crsOrProj === 'string' ? proj4(crsOrProj).oProj : crsOrProj;
|
|
329
|
+
const names = proj4.Proj.projections.get(proj.projName).names;
|
|
330
|
+
switch (names[0]) {
|
|
331
|
+
case 'Geocentric':
|
|
331
332
|
return quaternionFromEnuToGeocent();
|
|
332
|
-
case '
|
|
333
|
+
case 'Lambert Tangential Conformal Conic Projection':
|
|
333
334
|
return quaternionFromEnuToLCC(proj);
|
|
334
|
-
case '
|
|
335
|
+
case 'Fast_Transverse_Mercator':
|
|
335
336
|
return quaternionFromEnuToTMerc(proj);
|
|
336
337
|
case 'longlat':
|
|
337
338
|
return quaternionFromEnuToLongLat();
|
|
@@ -355,13 +356,14 @@ export function quaternionFromCRSToEnu(crsOrProj, coordinates) {
|
|
|
355
356
|
if (coordinates) {
|
|
356
357
|
return quaternionFromCRSToEnu(crsOrProj)(coordinates, target);
|
|
357
358
|
}
|
|
358
|
-
const proj = typeof crsOrProj === 'string' ? proj4
|
|
359
|
-
|
|
360
|
-
|
|
359
|
+
const proj = typeof crsOrProj === 'string' ? proj4(crsOrProj).oProj : crsOrProj;
|
|
360
|
+
const names = proj4.Proj.projections.get(proj.projName).names;
|
|
361
|
+
switch (names[0]) {
|
|
362
|
+
case 'Geocentric':
|
|
361
363
|
return quaternionFromGeocentToEnu();
|
|
362
|
-
case '
|
|
364
|
+
case 'Lambert Tangential Conformal Conic Projection':
|
|
363
365
|
return quaternionFromLCCToEnu(proj);
|
|
364
|
-
case '
|
|
366
|
+
case 'Fast_Transverse_Mercator':
|
|
365
367
|
return quaternionFromTMercToEnu(proj);
|
|
366
368
|
case 'longlat':
|
|
367
369
|
return quaternionFromLongLatToEnu();
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itowns/geographic",
|
|
3
|
-
"version": "2.45.1",
|
|
3
|
+
"version": "2.45.2-next.1",
|
|
4
4
|
"description": "Geodesy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/Main.js",
|
|
7
|
-
"exports":
|
|
8
|
-
|
|
7
|
+
"exports": {
|
|
8
|
+
"types": "./src/Main.ts",
|
|
9
|
+
"default": "./lib/Main.js"
|
|
10
|
+
},
|
|
11
|
+
"types": "./src/Main.ts",
|
|
9
12
|
"scripts": {
|
|
10
13
|
"build": "",
|
|
11
14
|
"lint": "eslint \"src/**/*.{js,ts,tsx}\" \"test/**/*.js\"",
|
|
@@ -16,7 +19,6 @@
|
|
|
16
19
|
"test-with-coverage_lcov": "c8 -n src --reporter=lcov cross-env npm run test-unit",
|
|
17
20
|
"watch": "npm run transpile -- --watch",
|
|
18
21
|
"publish-latest": "npm publish --access public --tag=latest --provenance",
|
|
19
|
-
"prerelease-next": "npm version prerelease --preid next",
|
|
20
22
|
"publish-next": "npm publish --access public --tag=next --provenance"
|
|
21
23
|
},
|
|
22
24
|
"files": [
|
|
@@ -33,8 +35,8 @@
|
|
|
33
35
|
"url": "https://github.com/itowns/itowns/issues"
|
|
34
36
|
},
|
|
35
37
|
"peerDependencies": {
|
|
36
|
-
"proj4": "^2.
|
|
37
|
-
"three": "^0.
|
|
38
|
+
"proj4": "^2.19.3",
|
|
39
|
+
"three": "^0.174.0"
|
|
38
40
|
},
|
|
39
41
|
"homepage": "https://itowns.github.io/"
|
|
40
42
|
}
|
package/src/Coordinates.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import proj4 from 'proj4';
|
|
3
|
+
import type { Converter } from 'proj4/dist/lib/core';
|
|
3
4
|
import Ellipsoid from './Ellipsoid';
|
|
4
5
|
import * as CRS from './Crs';
|
|
5
6
|
|
|
6
|
-
import type {
|
|
7
|
+
import type { ProjectionAlias } from './Crs';
|
|
7
8
|
|
|
8
9
|
const ellipsoid = new Ellipsoid();
|
|
9
|
-
const projectionCache: Record<string, Record<string,
|
|
10
|
+
const projectionCache: Record<string, Record<string, Converter>> = {};
|
|
10
11
|
|
|
11
12
|
const v0 = new THREE.Vector3();
|
|
12
13
|
const v1 = new THREE.Vector3();
|
|
@@ -21,7 +22,7 @@ export interface CoordinatesLike {
|
|
|
21
22
|
readonly z: number;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
function proj4cache(crsIn:
|
|
25
|
+
function proj4cache(crsIn: ProjectionAlias, crsOut: ProjectionAlias): Converter {
|
|
25
26
|
if (!projectionCache[crsIn]) {
|
|
26
27
|
projectionCache[crsIn] = {};
|
|
27
28
|
}
|
|
@@ -71,9 +72,9 @@ class Coordinates {
|
|
|
71
72
|
*/
|
|
72
73
|
readonly isCoordinates: boolean;
|
|
73
74
|
/**
|
|
74
|
-
* A default or user-defined CRS (see {@link
|
|
75
|
+
* A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
75
76
|
*/
|
|
76
|
-
crs:
|
|
77
|
+
crs: ProjectionAlias;
|
|
77
78
|
|
|
78
79
|
/** The x value (or longitude) of this coordinate. */
|
|
79
80
|
x: number;
|
|
@@ -86,12 +87,12 @@ class Coordinates {
|
|
|
86
87
|
private _normalNeedsUpdate: boolean;
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
|
-
* @param crs - A default or user-defined CRS (see {@link
|
|
90
|
+
* @param crs - A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
90
91
|
* @param x - x or longitude value.
|
|
91
92
|
* @param y - y or latitude value.
|
|
92
93
|
* @param z - z or altitude value.
|
|
93
94
|
*/
|
|
94
|
-
constructor(crs:
|
|
95
|
+
constructor(crs: ProjectionAlias, x: number = 0, y: number = 0, z: number = 0) {
|
|
95
96
|
this.isCoordinates = true;
|
|
96
97
|
|
|
97
98
|
CRS.isValid(crs);
|
|
@@ -133,7 +134,7 @@ class Coordinates {
|
|
|
133
134
|
* Sets the Coordinate Reference System.
|
|
134
135
|
* @param crs - Coordinate Reference System (e.g. 'EPSG:4978')
|
|
135
136
|
*/
|
|
136
|
-
setCrs(crs:
|
|
137
|
+
setCrs(crs: ProjectionAlias): this {
|
|
137
138
|
CRS.isValid(crs);
|
|
138
139
|
this.crs = crs;
|
|
139
140
|
return this;
|
|
@@ -340,7 +341,7 @@ class Coordinates {
|
|
|
340
341
|
* const geographicCoords = geocentricCoords.as('EPSG:4326');
|
|
341
342
|
* ```
|
|
342
343
|
*/
|
|
343
|
-
as(crs:
|
|
344
|
+
as(crs: ProjectionAlias, target = new Coordinates(crs)): Coordinates {
|
|
344
345
|
if (this.crs == crs) {
|
|
345
346
|
target.copy(this);
|
|
346
347
|
} else {
|
package/src/Crs.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import proj4 from 'proj4';
|
|
2
2
|
|
|
3
|
-
import type { ProjectionDefinition } from 'proj4';
|
|
3
|
+
import type { ProjectionDefinition } from 'proj4/dist/lib/defs';
|
|
4
4
|
|
|
5
5
|
proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs');
|
|
6
6
|
|
|
@@ -15,7 +15,7 @@ proj4.defs('WGS84').axis = 'neu';
|
|
|
15
15
|
* projection definition previously defined with
|
|
16
16
|
* [`proj4.defs`](https://github.com/proj4js/proj4js#named-projections).
|
|
17
17
|
*/
|
|
18
|
-
export type
|
|
18
|
+
export type ProjectionAlias = string;
|
|
19
19
|
|
|
20
20
|
function isString(s: unknown): s is string {
|
|
21
21
|
return typeof s === 'string' || s instanceof String;
|
|
@@ -53,7 +53,7 @@ export const UNIT = {
|
|
|
53
53
|
*
|
|
54
54
|
* @param crs - The CRS to test.
|
|
55
55
|
*/
|
|
56
|
-
export function is4326(crs:
|
|
56
|
+
export function is4326(crs: ProjectionAlias) {
|
|
57
57
|
return crs === 'EPSG:4326';
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -79,7 +79,7 @@ function unitFromProj4Unit(proj: ProjectionDefinition) {
|
|
|
79
79
|
* @param crs - The CRS to extract the unit from.
|
|
80
80
|
* @returns Either `UNIT.METER`, `UNIT.DEGREE`, `UNIT.FOOT` or `undefined`.
|
|
81
81
|
*/
|
|
82
|
-
export function getUnit(crs:
|
|
82
|
+
export function getUnit(crs: ProjectionAlias) {
|
|
83
83
|
mustBeString(crs);
|
|
84
84
|
const p = proj4.defs(crs);
|
|
85
85
|
if (!p) {
|
|
@@ -94,7 +94,7 @@ export function getUnit(crs: ProjectionLike) {
|
|
|
94
94
|
* @param crs - The CRS to check.
|
|
95
95
|
* @throws {@link Error} if the CRS is not valid.
|
|
96
96
|
*/
|
|
97
|
-
export function isMetricUnit(crs:
|
|
97
|
+
export function isMetricUnit(crs: ProjectionAlias) {
|
|
98
98
|
return getUnit(crs) === UNIT.METER;
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -104,7 +104,7 @@ export function isMetricUnit(crs: ProjectionLike) {
|
|
|
104
104
|
* @param crs - The CRS to check.
|
|
105
105
|
* @throws {@link Error} if the CRS is not valid.
|
|
106
106
|
*/
|
|
107
|
-
export function isGeographic(crs:
|
|
107
|
+
export function isGeographic(crs: ProjectionAlias) {
|
|
108
108
|
return getUnit(crs) === UNIT.DEGREE;
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -114,7 +114,7 @@ export function isGeographic(crs: ProjectionLike) {
|
|
|
114
114
|
* @param crs - The CRS to test.
|
|
115
115
|
* @returns false if the crs isn't defined.
|
|
116
116
|
*/
|
|
117
|
-
export function isGeocentric(crs:
|
|
117
|
+
export function isGeocentric(crs: ProjectionAlias) {
|
|
118
118
|
mustBeString(crs);
|
|
119
119
|
const projection = proj4.defs(crs);
|
|
120
120
|
return !projection ? false : projection.projName == 'geocent';
|
|
@@ -127,7 +127,7 @@ export function isGeocentric(crs: ProjectionLike) {
|
|
|
127
127
|
* @param crs - The CRS to test.
|
|
128
128
|
* @throws {@link Error} if the crs is not valid.
|
|
129
129
|
*/
|
|
130
|
-
export function isValid(crs:
|
|
130
|
+
export function isValid(crs: ProjectionAlias) {
|
|
131
131
|
const proj = proj4.defs(crs);
|
|
132
132
|
if (!proj) {
|
|
133
133
|
throw new Error(`Undefined crs '${crs}'. Add it with proj4.defs('${crs}', string)`);
|
|
@@ -143,7 +143,7 @@ export function isValid(crs: ProjectionLike) {
|
|
|
143
143
|
* @param crs - The CRS to use.
|
|
144
144
|
* @returns 0.01 if the CRS is EPSG:4326, 0.001 otherwise.
|
|
145
145
|
*/
|
|
146
|
-
export function reasonableEpsilon(crs:
|
|
146
|
+
export function reasonableEpsilon(crs: ProjectionAlias) {
|
|
147
147
|
if (is4326(crs)) {
|
|
148
148
|
return 0.01;
|
|
149
149
|
} else {
|
|
@@ -158,7 +158,7 @@ export function reasonableEpsilon(crs: ProjectionLike) {
|
|
|
158
158
|
* @param crs - The CRS to get axis from.
|
|
159
159
|
* @returns the matching proj4 axis string, 'enu' for instance (east, north, up)
|
|
160
160
|
*/
|
|
161
|
-
export function axisOrder(crs:
|
|
161
|
+
export function axisOrder(crs: ProjectionAlias) {
|
|
162
162
|
mustBeString(crs);
|
|
163
163
|
const projection = proj4.defs(crs);
|
|
164
164
|
return !projection ? undefined : projection.axis;
|
package/src/Extent.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as THREE from 'three';
|
|
|
2
2
|
import Coordinates from './Coordinates';
|
|
3
3
|
import * as CRS from './Crs';
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { ProjectionAlias } from './Crs';
|
|
6
6
|
|
|
7
7
|
const _dim = new THREE.Vector2();
|
|
8
8
|
const _dim2 = new THREE.Vector2();
|
|
@@ -47,9 +47,9 @@ class Extent {
|
|
|
47
47
|
*/
|
|
48
48
|
readonly isExtent: true;
|
|
49
49
|
/**
|
|
50
|
-
* A default or user-defined CRS (see {@link
|
|
50
|
+
* A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
51
51
|
*/
|
|
52
|
-
crs:
|
|
52
|
+
crs: ProjectionAlias;
|
|
53
53
|
/**
|
|
54
54
|
* West longitude bound of this extent.
|
|
55
55
|
*/
|
|
@@ -68,13 +68,13 @@ class Extent {
|
|
|
68
68
|
north: number;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
|
-
* @param crs - A default or user-defined CRS (see {@link
|
|
71
|
+
* @param crs - A default or user-defined CRS (see {@link ProjectionAlias}).
|
|
72
72
|
* @param west - the `west` value of this extent. Default is 0.
|
|
73
73
|
* @param east - the `east` value of this extent. Default is 0.
|
|
74
74
|
* @param south - the `south` value of this extent. Default is 0.
|
|
75
75
|
* @param north - the `north` value of this extent. Default is 0.
|
|
76
76
|
*/
|
|
77
|
-
constructor(crs:
|
|
77
|
+
constructor(crs: ProjectionAlias, west = 0, east = 0, south = 0, north = 0) {
|
|
78
78
|
if (CRS.isGeocentric(crs)) {
|
|
79
79
|
throw new Error(
|
|
80
80
|
`Non-compatible geocentric projection ${crs} to build a geographical extent`,
|
|
@@ -470,7 +470,7 @@ class Extent {
|
|
|
470
470
|
* @param crs - Projection of extent to instancied.
|
|
471
471
|
* @param box - Bounding-box
|
|
472
472
|
*/
|
|
473
|
-
static fromBox3(crs:
|
|
473
|
+
static fromBox3(crs: ProjectionAlias, box: THREE.Box3) {
|
|
474
474
|
if (CRS.isGeocentric(crs)) {
|
|
475
475
|
// if geocentric reproject box on 'EPSG:4326'
|
|
476
476
|
crs = 'EPSG:4326';
|
package/src/OrientationUtils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Euler, MathUtils, Matrix4, Quaternion, Vector3 } from 'three';
|
|
2
2
|
import proj4 from 'proj4';
|
|
3
|
-
import type { ProjectionDefinition } from 'proj4';
|
|
3
|
+
import type { ProjectionDefinition } from 'proj4/dist/lib/defs';
|
|
4
4
|
import Coordinates from './Coordinates';
|
|
5
5
|
|
|
6
6
|
const DEG2RAD = MathUtils.DEG2RAD;
|
|
@@ -410,11 +410,15 @@ export function quaternionFromEnuToCRS(
|
|
|
410
410
|
target = new Quaternion(),
|
|
411
411
|
) {
|
|
412
412
|
if (coordinates) { return quaternionFromEnuToCRS(crsOrProj)(coordinates, target); }
|
|
413
|
-
const proj = typeof crsOrProj === 'string' ?
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
413
|
+
const proj = typeof crsOrProj === 'string' ?
|
|
414
|
+
proj4(crsOrProj).oProj as ProjectionDefinition :
|
|
415
|
+
crsOrProj;
|
|
416
|
+
const names = proj4.Proj.projections.get(proj.projName).names;
|
|
417
|
+
switch (names[0]) {
|
|
418
|
+
case 'Geocentric': return quaternionFromEnuToGeocent();
|
|
419
|
+
case 'Lambert Tangential Conformal Conic Projection':
|
|
420
|
+
return quaternionFromEnuToLCC(proj as LCCProjection);
|
|
421
|
+
case 'Fast_Transverse_Mercator': return quaternionFromEnuToTMerc(proj as TMercProjection);
|
|
418
422
|
case 'longlat': return quaternionFromEnuToLongLat();
|
|
419
423
|
default: return quaternionUnimplemented(proj);
|
|
420
424
|
}
|
|
@@ -443,11 +447,15 @@ export function quaternionFromCRSToEnu(
|
|
|
443
447
|
target = new Quaternion(),
|
|
444
448
|
) {
|
|
445
449
|
if (coordinates) { return quaternionFromCRSToEnu(crsOrProj)(coordinates, target); }
|
|
446
|
-
const proj = typeof crsOrProj === 'string' ?
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
450
|
+
const proj = typeof crsOrProj === 'string' ?
|
|
451
|
+
proj4(crsOrProj).oProj as ProjectionDefinition :
|
|
452
|
+
crsOrProj;
|
|
453
|
+
const names = proj4.Proj.projections.get(proj.projName).names;
|
|
454
|
+
switch (names[0]) {
|
|
455
|
+
case 'Geocentric': return quaternionFromGeocentToEnu();
|
|
456
|
+
case 'Lambert Tangential Conformal Conic Projection':
|
|
457
|
+
return quaternionFromLCCToEnu(proj as LCCProjection);
|
|
458
|
+
case 'Fast_Transverse_Mercator': return quaternionFromTMercToEnu(proj as TMercProjection);
|
|
451
459
|
case 'longlat': return quaternionFromLongLatToEnu();
|
|
452
460
|
default: return quaternionUnimplemented(proj);
|
|
453
461
|
}
|