@itowns/geographic 2.45.0 → 2.45.1-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/CoordStars.d.ts +13 -0
- package/lib/CoordStars.js +89 -0
- package/lib/Coordinates.d.ts +196 -0
- package/lib/Coordinates.js +331 -0
- package/lib/Crs.d.ts +93 -0
- package/lib/Crs.js +170 -0
- package/lib/Ellipsoid.d.ts +74 -0
- package/lib/Ellipsoid.js +186 -0
- package/lib/Extent.d.ts +246 -0
- package/lib/Extent.js +550 -0
- package/lib/Main.d.ts +6 -0
- package/lib/Main.js +7 -0
- package/lib/OrientationUtils.d.ts +105 -0
- package/lib/OrientationUtils.js +402 -0
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const CoordStars: {
|
|
2
|
+
getSunPosition(): (date: Date | number, lat: number, lon: number) => {
|
|
3
|
+
EclipticLongitude: number;
|
|
4
|
+
declinaison: number;
|
|
5
|
+
ascension: number;
|
|
6
|
+
H: number;
|
|
7
|
+
SiderealTime: number;
|
|
8
|
+
altitude: number;
|
|
9
|
+
azimuth: number;
|
|
10
|
+
};
|
|
11
|
+
getSunPositionInScene(date: Date | number, lat: number, lon: number): import("three").Vector3;
|
|
12
|
+
};
|
|
13
|
+
export default CoordStars;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated On: 2016-02-25
|
|
3
|
+
* Class: CoordStars
|
|
4
|
+
* Description: get coord of stars like earth...
|
|
5
|
+
*/
|
|
6
|
+
import Coordinates from "./Coordinates.js";
|
|
7
|
+
const CoordStars = {
|
|
8
|
+
getSunPosition() {
|
|
9
|
+
const m = Math;
|
|
10
|
+
const PI = m.PI;
|
|
11
|
+
const sin = m.sin;
|
|
12
|
+
const cos = m.cos;
|
|
13
|
+
const tan = m.tan;
|
|
14
|
+
const asin = m.asin;
|
|
15
|
+
const atan = m.atan2;
|
|
16
|
+
const rad = PI / 180;
|
|
17
|
+
const dayMs = 1000 * 60 * 60 * 24;
|
|
18
|
+
const J1970 = 2440588;
|
|
19
|
+
const J2000 = 2451545;
|
|
20
|
+
const e = rad * 23.4397; // obliquity of the Earth
|
|
21
|
+
|
|
22
|
+
function toJulian(date) {
|
|
23
|
+
return date.valueOf() / dayMs - 0.5 + J1970;
|
|
24
|
+
}
|
|
25
|
+
function toDays(date) {
|
|
26
|
+
return toJulian(date) - J2000;
|
|
27
|
+
}
|
|
28
|
+
function getRightAscension(l, b) {
|
|
29
|
+
return atan(sin(l) * cos(e) - tan(b) * sin(e), cos(l));
|
|
30
|
+
}
|
|
31
|
+
function getDeclination(l, b) {
|
|
32
|
+
return asin(sin(b) * cos(e) + cos(b) * sin(e) * sin(l));
|
|
33
|
+
}
|
|
34
|
+
function getAzimuth(H, phi, dec) {
|
|
35
|
+
return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi));
|
|
36
|
+
}
|
|
37
|
+
function getAltitude(H, phi, dec) {
|
|
38
|
+
return asin(sin(phi) * sin(dec) + cos(phi) * cos(dec) * cos(H));
|
|
39
|
+
}
|
|
40
|
+
function getSiderealTime(d, lw) {
|
|
41
|
+
return rad * (280.16 + 360.9856235 * d) - lw;
|
|
42
|
+
}
|
|
43
|
+
function getSolarMeanAnomaly(d) {
|
|
44
|
+
return rad * (357.5291 + 0.98560028 * d);
|
|
45
|
+
}
|
|
46
|
+
function getEquationOfCenter(M) {
|
|
47
|
+
return rad * (1.9148 * sin(M) + 0.0200 * sin(2 * M) + 0.0003 * sin(3 * M));
|
|
48
|
+
}
|
|
49
|
+
function getEclipticLongitude(M, C) {
|
|
50
|
+
const P = rad * 102.9372; // perihelion of the Earth
|
|
51
|
+
return M + C + P + PI;
|
|
52
|
+
}
|
|
53
|
+
return function getSunPosition(date, lat, lon) {
|
|
54
|
+
const lw = rad * -lon;
|
|
55
|
+
const phi = rad * lat;
|
|
56
|
+
const d = toDays(date);
|
|
57
|
+
const M = getSolarMeanAnomaly(d);
|
|
58
|
+
const C = getEquationOfCenter(M);
|
|
59
|
+
const L = getEclipticLongitude(M, C);
|
|
60
|
+
const D = getDeclination(L, 0);
|
|
61
|
+
const A = getRightAscension(L, 0);
|
|
62
|
+
const t = getSiderealTime(d, lw);
|
|
63
|
+
const H = t - A;
|
|
64
|
+
return {
|
|
65
|
+
EclipticLongitude: L,
|
|
66
|
+
declinaison: D,
|
|
67
|
+
ascension: A,
|
|
68
|
+
H,
|
|
69
|
+
SiderealTime: t,
|
|
70
|
+
altitude: getAltitude(H, phi, D),
|
|
71
|
+
azimuth: getAzimuth(H, phi, D) + PI / 2 // + PI// - PI/2
|
|
72
|
+
// origin: north !!! not like original Mourner code but more
|
|
73
|
+
// classical ref
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
// Return scene coordinate ({x,y,z}) of sun
|
|
78
|
+
getSunPositionInScene(date, lat, lon) {
|
|
79
|
+
if (typeof date !== 'number') {
|
|
80
|
+
date = date.valueOf();
|
|
81
|
+
}
|
|
82
|
+
const sun = CoordStars.getSunPosition()(date, lat, lon);
|
|
83
|
+
const dayMilliSec = 24 * 3600000;
|
|
84
|
+
const longitude = sun.ascension + date % dayMilliSec / dayMilliSec * -360 + 180; // cause midday
|
|
85
|
+
const coSunCarto = new Coordinates('EPSG:4326', longitude, lat, 50000000).as('EPSG:4978').toVector3();
|
|
86
|
+
return coSunCarto;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export default CoordStars;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import type { ProjectionLike } from './Crs';
|
|
3
|
+
export interface CoordinatesLike {
|
|
4
|
+
readonly crs: string;
|
|
5
|
+
readonly x: number;
|
|
6
|
+
readonly y: number;
|
|
7
|
+
readonly z: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A class representing a geographic or geocentric coordinate.
|
|
11
|
+
*
|
|
12
|
+
* A coordinate is defined by a [CRS](http://inspire.ec.europa.eu/theme/rs)
|
|
13
|
+
* (Coordinate Reference System) and a 3-dimensional vector `(x, y, z)`.
|
|
14
|
+
* For geocentric projections, it is recommended to use the `latitude`,
|
|
15
|
+
* `longitude` and `altitude` aliases to refer to vector components.
|
|
16
|
+
*
|
|
17
|
+
* To change a value, prefer the use of the `set*` methods.
|
|
18
|
+
*
|
|
19
|
+
* By default, the `EPSG:4978` and `EPSG:4326` projections are supported. To use
|
|
20
|
+
* a different projection, it must have been declared previously with `proj4`.
|
|
21
|
+
* A comprehensive list of projections and their corresponding proj4 string can
|
|
22
|
+
* be found at [epsg.io](https://epsg.io/).
|
|
23
|
+
*
|
|
24
|
+
* @example Geocentric coordinates
|
|
25
|
+
* ```js
|
|
26
|
+
* new Coordinates('EPSG:4978', 20885167, 849862, 23385912);
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example Geographic coordinates
|
|
30
|
+
* ```js
|
|
31
|
+
* new Coordinates('EPSG:4326', 2.33, 48.24, 24999549);
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example Defining the EPSG:2154 projection with proj4
|
|
35
|
+
* ```js
|
|
36
|
+
* proj4.defs('EPSG:2154', `+proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44
|
|
37
|
+
* +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m
|
|
38
|
+
* +no_defs +type=crs`);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare class Coordinates {
|
|
42
|
+
/**
|
|
43
|
+
* Read-only flag to check if a given object is of type `Coordinates`.
|
|
44
|
+
*/
|
|
45
|
+
readonly isCoordinates: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* A default or user-defined CRS (see {@link ProjectionLike}).
|
|
48
|
+
*/
|
|
49
|
+
crs: ProjectionLike;
|
|
50
|
+
/** The x value (or longitude) of this coordinate. */
|
|
51
|
+
x: number;
|
|
52
|
+
/** The y value (or latitude) of this coordinate. */
|
|
53
|
+
y: number;
|
|
54
|
+
/** The z value (or altitude) of this coordinate. */
|
|
55
|
+
z: number;
|
|
56
|
+
private _normal;
|
|
57
|
+
private _normalNeedsUpdate;
|
|
58
|
+
/**
|
|
59
|
+
* @param crs - A default or user-defined CRS (see {@link ProjectionLike}).
|
|
60
|
+
* @param x - x or longitude value.
|
|
61
|
+
* @param y - y or latitude value.
|
|
62
|
+
* @param z - z or altitude value.
|
|
63
|
+
*/
|
|
64
|
+
constructor(crs: ProjectionLike, x?: number, y?: number, z?: number);
|
|
65
|
+
/**
|
|
66
|
+
* Sets the Coordinate Reference System.
|
|
67
|
+
* @param crs - Coordinate Reference System (e.g. 'EPSG:4978')
|
|
68
|
+
*/
|
|
69
|
+
setCrs(crs: ProjectionLike): this;
|
|
70
|
+
/**
|
|
71
|
+
* Sets the x, y and z components of this coordinate.
|
|
72
|
+
*
|
|
73
|
+
* @param x - x or longitude value.
|
|
74
|
+
* @param y - y or latitude value.
|
|
75
|
+
* @param z - z or altitude value.
|
|
76
|
+
*/
|
|
77
|
+
setFromValues(x?: number, y?: number, z?: number): this;
|
|
78
|
+
/**
|
|
79
|
+
* Sets the coordinates's {@link Coordinates#x | x} component to
|
|
80
|
+
* `array[offset + 0]`, {@link Coordinates#y | y} component to
|
|
81
|
+
* `array[offset + 1]` and {@link Coordinates#z | z} component to
|
|
82
|
+
* `array[offset + 2]`.
|
|
83
|
+
*
|
|
84
|
+
* @param array - The source array.
|
|
85
|
+
* @param offset - Optional offset into the array. Default is 0.
|
|
86
|
+
*/
|
|
87
|
+
setFromArray(array: number[], offset?: number): this;
|
|
88
|
+
/**
|
|
89
|
+
* Sets the `(x, y, z)` vector of this coordinate from a 3-dimensional
|
|
90
|
+
* vector-like object. This object shall have both `x`, `y` and `z`
|
|
91
|
+
* properties.
|
|
92
|
+
*
|
|
93
|
+
* @param v - The source object.
|
|
94
|
+
*/
|
|
95
|
+
setFromVector3(v: THREE.Vector3Like): this;
|
|
96
|
+
/**
|
|
97
|
+
* Returns a new coordinate with the same `(x, y, z)` vector and crs as this
|
|
98
|
+
* one.
|
|
99
|
+
*/
|
|
100
|
+
clone(): Coordinates;
|
|
101
|
+
/**
|
|
102
|
+
* Copies the `(x, y, z)` vector components and crs of the passed coordinate
|
|
103
|
+
* to this coordinate.
|
|
104
|
+
*
|
|
105
|
+
* @param src - The source coordinate to copy from.
|
|
106
|
+
*/
|
|
107
|
+
copy(src: CoordinatesLike): this;
|
|
108
|
+
get longitude(): number;
|
|
109
|
+
get latitude(): number;
|
|
110
|
+
get altitude(): number;
|
|
111
|
+
set altitude(value: number);
|
|
112
|
+
/**
|
|
113
|
+
* The geodesic normal of the coordinate.
|
|
114
|
+
*/
|
|
115
|
+
get geodesicNormal(): THREE.Vector3;
|
|
116
|
+
/**
|
|
117
|
+
* Copies the `x`, `y` and `z` components into the provided `THREE.Vector3`.
|
|
118
|
+
*
|
|
119
|
+
* @param target - An object to store this vector to. If this is not
|
|
120
|
+
* specified, a new vector will be created.
|
|
121
|
+
*
|
|
122
|
+
* @returns A vector `(x, y, z)`, or copies x, y and z into the provided
|
|
123
|
+
* vector.
|
|
124
|
+
*/
|
|
125
|
+
toVector3(target?: THREE.Vector3): THREE.Vector3;
|
|
126
|
+
/**
|
|
127
|
+
* Copies the `x`, `y` and `z` components into the provided array.
|
|
128
|
+
*
|
|
129
|
+
* @param array - An array to store this vector to. If this is not
|
|
130
|
+
* provided a new array will be created.
|
|
131
|
+
* @param offset - An optional offset into the array.
|
|
132
|
+
*
|
|
133
|
+
* @returns An array [x, y, z], or copies x, y and z into the provided
|
|
134
|
+
* array.
|
|
135
|
+
*/
|
|
136
|
+
toArray(array?: number[], offset?: number): ArrayLike<number>;
|
|
137
|
+
/**
|
|
138
|
+
* Computes the planar distance from this coordinates to `coord`.
|
|
139
|
+
* **Planar distance** is the straight-line euclidean distance calculated in
|
|
140
|
+
* a 2D cartesian coordinate system.
|
|
141
|
+
*/
|
|
142
|
+
planarDistanceTo(coord: Coordinates): number;
|
|
143
|
+
/**
|
|
144
|
+
* Computes the geodetic distance from this coordinates to `coord`.
|
|
145
|
+
* **Geodetic distance** is calculated in an ellipsoid space as the shortest
|
|
146
|
+
* distance across the curved surface of the ellipsoid.
|
|
147
|
+
*/
|
|
148
|
+
geodeticDistanceTo(coord: Coordinates): number;
|
|
149
|
+
/**
|
|
150
|
+
* Computes the euclidean distance from this coordinates to `coord` in a
|
|
151
|
+
* WGS84 projection.
|
|
152
|
+
*
|
|
153
|
+
* @param coord - The coordinate
|
|
154
|
+
* @returns earth euclidean distance
|
|
155
|
+
*/
|
|
156
|
+
spatialEuclideanDistanceTo(coord: Coordinates): number;
|
|
157
|
+
/**
|
|
158
|
+
* Multiplies this coordinate (with an implicit 1 in the 4th dimension)
|
|
159
|
+
* by `mat`, and divides by perspective.
|
|
160
|
+
*
|
|
161
|
+
* @param mat - The matrix.
|
|
162
|
+
*/
|
|
163
|
+
applyMatrix4(mat: THREE.Matrix4): this;
|
|
164
|
+
/**
|
|
165
|
+
* Projects this coordinate to the specified
|
|
166
|
+
* [CRS](http://inspire.ec.europa.eu/theme/rs).
|
|
167
|
+
*
|
|
168
|
+
* @param crs - The target CRS to which the coordinate will be converted.
|
|
169
|
+
* @param target - The target to store the projected coordinate. If this not
|
|
170
|
+
* provided a new coordinate will be created.
|
|
171
|
+
*
|
|
172
|
+
* @returns The coordinate projected into the specified CRS.
|
|
173
|
+
*
|
|
174
|
+
* @example Conversion from a geographic to a geocentric reference system
|
|
175
|
+
* ```js
|
|
176
|
+
* const geographicCoords = new Coordinates('EPSG:4326',
|
|
177
|
+
* 2.33, // longitude
|
|
178
|
+
* 48.24, // latitude
|
|
179
|
+
* 24999549, // altitude
|
|
180
|
+
* );
|
|
181
|
+
* const geocentricCoords = geographicCoords.as('EPSG:4978');
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @example Conversion from a geocentric to a geographic reference system
|
|
185
|
+
* ```js
|
|
186
|
+
* const geocentricCoords = new Coordinates('EPSG:4978',
|
|
187
|
+
* 20885167, // x
|
|
188
|
+
* 849862, // y
|
|
189
|
+
* 23385912, // z
|
|
190
|
+
* );
|
|
191
|
+
* const geographicCoords = geocentricCoords.as('EPSG:4326');
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
as(crs: ProjectionLike, target?: Coordinates): Coordinates;
|
|
195
|
+
}
|
|
196
|
+
export default Coordinates;
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import proj4 from 'proj4';
|
|
3
|
+
import Ellipsoid from "./Ellipsoid.js";
|
|
4
|
+
import * as CRS from "./Crs.js";
|
|
5
|
+
const ellipsoid = new Ellipsoid();
|
|
6
|
+
const projectionCache = {};
|
|
7
|
+
const v0 = new THREE.Vector3();
|
|
8
|
+
const v1 = new THREE.Vector3();
|
|
9
|
+
let coord0;
|
|
10
|
+
let coord1;
|
|
11
|
+
function proj4cache(crsIn, crsOut) {
|
|
12
|
+
if (!projectionCache[crsIn]) {
|
|
13
|
+
projectionCache[crsIn] = {};
|
|
14
|
+
}
|
|
15
|
+
if (!projectionCache[crsIn][crsOut]) {
|
|
16
|
+
projectionCache[crsIn][crsOut] = proj4(crsIn, crsOut);
|
|
17
|
+
}
|
|
18
|
+
return projectionCache[crsIn][crsOut];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A class representing a geographic or geocentric coordinate.
|
|
23
|
+
*
|
|
24
|
+
* A coordinate is defined by a [CRS](http://inspire.ec.europa.eu/theme/rs)
|
|
25
|
+
* (Coordinate Reference System) and a 3-dimensional vector `(x, y, z)`.
|
|
26
|
+
* For geocentric projections, it is recommended to use the `latitude`,
|
|
27
|
+
* `longitude` and `altitude` aliases to refer to vector components.
|
|
28
|
+
*
|
|
29
|
+
* To change a value, prefer the use of the `set*` methods.
|
|
30
|
+
*
|
|
31
|
+
* By default, the `EPSG:4978` and `EPSG:4326` projections are supported. To use
|
|
32
|
+
* a different projection, it must have been declared previously with `proj4`.
|
|
33
|
+
* A comprehensive list of projections and their corresponding proj4 string can
|
|
34
|
+
* be found at [epsg.io](https://epsg.io/).
|
|
35
|
+
*
|
|
36
|
+
* @example Geocentric coordinates
|
|
37
|
+
* ```js
|
|
38
|
+
* new Coordinates('EPSG:4978', 20885167, 849862, 23385912);
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example Geographic coordinates
|
|
42
|
+
* ```js
|
|
43
|
+
* new Coordinates('EPSG:4326', 2.33, 48.24, 24999549);
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example Defining the EPSG:2154 projection with proj4
|
|
47
|
+
* ```js
|
|
48
|
+
* proj4.defs('EPSG:2154', `+proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44
|
|
49
|
+
* +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m
|
|
50
|
+
* +no_defs +type=crs`);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
class Coordinates {
|
|
54
|
+
/**
|
|
55
|
+
* Read-only flag to check if a given object is of type `Coordinates`.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A default or user-defined CRS (see {@link ProjectionLike}).
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/** The x value (or longitude) of this coordinate. */
|
|
63
|
+
|
|
64
|
+
/** The y value (or latitude) of this coordinate. */
|
|
65
|
+
|
|
66
|
+
/** The z value (or altitude) of this coordinate. */
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param crs - A default or user-defined CRS (see {@link ProjectionLike}).
|
|
70
|
+
* @param x - x or longitude value.
|
|
71
|
+
* @param y - y or latitude value.
|
|
72
|
+
* @param z - z or altitude value.
|
|
73
|
+
*/
|
|
74
|
+
constructor(crs) {
|
|
75
|
+
let x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
76
|
+
let y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
77
|
+
let z = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
78
|
+
this.isCoordinates = true;
|
|
79
|
+
CRS.isValid(crs);
|
|
80
|
+
this.crs = crs;
|
|
81
|
+
|
|
82
|
+
// Storing the coordinates as is, not in arrays, as it is
|
|
83
|
+
// slower (see https://jsbench.me/40jumfag6g/1)
|
|
84
|
+
this.x = 0;
|
|
85
|
+
this.y = 0;
|
|
86
|
+
this.z = 0;
|
|
87
|
+
|
|
88
|
+
// Normal
|
|
89
|
+
this._normal = new THREE.Vector3();
|
|
90
|
+
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
+
if (x.length > 0) {
|
|
93
|
+
// deepscan-disable-line
|
|
94
|
+
console.warn('Deprecated Coordinates#constructor(string, number[]),', 'use `new Coordinates(string).setFromArray(number[])` instead.');
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
+
this.setFromArray(x);
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
+
} else if (x.isVector3 || x.isCoordinates) {
|
|
99
|
+
console.warn('Deprecated Coordinates#constructor(string, Vector3),', 'use `new Coordinates(string).setFromVector3(Vector3)` instead.');
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
|
+
this.setFromVector3(x);
|
|
102
|
+
} else {
|
|
103
|
+
this.setFromValues(x, y, z);
|
|
104
|
+
}
|
|
105
|
+
this._normalNeedsUpdate = true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Sets the Coordinate Reference System.
|
|
110
|
+
* @param crs - Coordinate Reference System (e.g. 'EPSG:4978')
|
|
111
|
+
*/
|
|
112
|
+
setCrs(crs) {
|
|
113
|
+
CRS.isValid(crs);
|
|
114
|
+
this.crs = crs;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Sets the x, y and z components of this coordinate.
|
|
120
|
+
*
|
|
121
|
+
* @param x - x or longitude value.
|
|
122
|
+
* @param y - y or latitude value.
|
|
123
|
+
* @param z - z or altitude value.
|
|
124
|
+
*/
|
|
125
|
+
setFromValues() {
|
|
126
|
+
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
127
|
+
let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
128
|
+
let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
129
|
+
this.x = x;
|
|
130
|
+
this.y = y;
|
|
131
|
+
this.z = z;
|
|
132
|
+
this._normalNeedsUpdate = true;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Sets the coordinates's {@link Coordinates#x | x} component to
|
|
138
|
+
* `array[offset + 0]`, {@link Coordinates#y | y} component to
|
|
139
|
+
* `array[offset + 1]` and {@link Coordinates#z | z} component to
|
|
140
|
+
* `array[offset + 2]`.
|
|
141
|
+
*
|
|
142
|
+
* @param array - The source array.
|
|
143
|
+
* @param offset - Optional offset into the array. Default is 0.
|
|
144
|
+
*/
|
|
145
|
+
setFromArray(array) {
|
|
146
|
+
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
147
|
+
return this.setFromValues(array[offset], array[offset + 1], array[offset + 2]);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Sets the `(x, y, z)` vector of this coordinate from a 3-dimensional
|
|
152
|
+
* vector-like object. This object shall have both `x`, `y` and `z`
|
|
153
|
+
* properties.
|
|
154
|
+
*
|
|
155
|
+
* @param v - The source object.
|
|
156
|
+
*/
|
|
157
|
+
setFromVector3(v) {
|
|
158
|
+
return this.setFromValues(v.x, v.y, v.z);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Returns a new coordinate with the same `(x, y, z)` vector and crs as this
|
|
163
|
+
* one.
|
|
164
|
+
*/
|
|
165
|
+
clone() {
|
|
166
|
+
return new Coordinates(this.crs, this.x, this.y, this.z);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Copies the `(x, y, z)` vector components and crs of the passed coordinate
|
|
171
|
+
* to this coordinate.
|
|
172
|
+
*
|
|
173
|
+
* @param src - The source coordinate to copy from.
|
|
174
|
+
*/
|
|
175
|
+
copy(src) {
|
|
176
|
+
this.crs = src.crs;
|
|
177
|
+
return this.setFromVector3(src);
|
|
178
|
+
}
|
|
179
|
+
get longitude() {
|
|
180
|
+
return this.x;
|
|
181
|
+
}
|
|
182
|
+
get latitude() {
|
|
183
|
+
return this.y;
|
|
184
|
+
}
|
|
185
|
+
get altitude() {
|
|
186
|
+
return this.z;
|
|
187
|
+
}
|
|
188
|
+
set altitude(value) {
|
|
189
|
+
this.z = value;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The geodesic normal of the coordinate.
|
|
194
|
+
*/
|
|
195
|
+
get geodesicNormal() {
|
|
196
|
+
if (this._normalNeedsUpdate) {
|
|
197
|
+
this._normalNeedsUpdate = false;
|
|
198
|
+
if (CRS.is4326(this.crs)) {
|
|
199
|
+
ellipsoid.geodeticSurfaceNormalCartographic(this, this._normal);
|
|
200
|
+
} else if (this.crs == 'EPSG:4978') {
|
|
201
|
+
ellipsoid.geodeticSurfaceNormal(this, this._normal);
|
|
202
|
+
} else {
|
|
203
|
+
this._normal.set(0, 0, 1);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return this._normal;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Copies the `x`, `y` and `z` components into the provided `THREE.Vector3`.
|
|
211
|
+
*
|
|
212
|
+
* @param target - An object to store this vector to. If this is not
|
|
213
|
+
* specified, a new vector will be created.
|
|
214
|
+
*
|
|
215
|
+
* @returns A vector `(x, y, z)`, or copies x, y and z into the provided
|
|
216
|
+
* vector.
|
|
217
|
+
*/
|
|
218
|
+
toVector3() {
|
|
219
|
+
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new THREE.Vector3();
|
|
220
|
+
return target.copy(this);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Copies the `x`, `y` and `z` components into the provided array.
|
|
225
|
+
*
|
|
226
|
+
* @param array - An array to store this vector to. If this is not
|
|
227
|
+
* provided a new array will be created.
|
|
228
|
+
* @param offset - An optional offset into the array.
|
|
229
|
+
*
|
|
230
|
+
* @returns An array [x, y, z], or copies x, y and z into the provided
|
|
231
|
+
* array.
|
|
232
|
+
*/
|
|
233
|
+
toArray() {
|
|
234
|
+
let array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
235
|
+
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
236
|
+
return THREE.Vector3.prototype.toArray.call(this, array, offset);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Computes the planar distance from this coordinates to `coord`.
|
|
241
|
+
* **Planar distance** is the straight-line euclidean distance calculated in
|
|
242
|
+
* a 2D cartesian coordinate system.
|
|
243
|
+
*/
|
|
244
|
+
planarDistanceTo(coord) {
|
|
245
|
+
this.toVector3(v0).setZ(0);
|
|
246
|
+
coord.toVector3(v1).setZ(0);
|
|
247
|
+
return v0.distanceTo(v1);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Computes the geodetic distance from this coordinates to `coord`.
|
|
252
|
+
* **Geodetic distance** is calculated in an ellipsoid space as the shortest
|
|
253
|
+
* distance across the curved surface of the ellipsoid.
|
|
254
|
+
*/
|
|
255
|
+
geodeticDistanceTo(coord) {
|
|
256
|
+
this.as('EPSG:4326', coord0);
|
|
257
|
+
coord.as('EPSG:4326', coord1);
|
|
258
|
+
return ellipsoid.geodesicDistance(coord0, coord1);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Computes the euclidean distance from this coordinates to `coord` in a
|
|
263
|
+
* WGS84 projection.
|
|
264
|
+
*
|
|
265
|
+
* @param coord - The coordinate
|
|
266
|
+
* @returns earth euclidean distance
|
|
267
|
+
*/
|
|
268
|
+
spatialEuclideanDistanceTo(coord) {
|
|
269
|
+
this.as('EPSG:4978', coord0).toVector3(v0);
|
|
270
|
+
coord.as('EPSG:4978', coord1).toVector3(v1);
|
|
271
|
+
return v0.distanceTo(v1);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Multiplies this coordinate (with an implicit 1 in the 4th dimension)
|
|
276
|
+
* by `mat`, and divides by perspective.
|
|
277
|
+
*
|
|
278
|
+
* @param mat - The matrix.
|
|
279
|
+
*/
|
|
280
|
+
applyMatrix4(mat) {
|
|
281
|
+
THREE.Vector3.prototype.applyMatrix4.call(this, mat);
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Projects this coordinate to the specified
|
|
287
|
+
* [CRS](http://inspire.ec.europa.eu/theme/rs).
|
|
288
|
+
*
|
|
289
|
+
* @param crs - The target CRS to which the coordinate will be converted.
|
|
290
|
+
* @param target - The target to store the projected coordinate. If this not
|
|
291
|
+
* provided a new coordinate will be created.
|
|
292
|
+
*
|
|
293
|
+
* @returns The coordinate projected into the specified CRS.
|
|
294
|
+
*
|
|
295
|
+
* @example Conversion from a geographic to a geocentric reference system
|
|
296
|
+
* ```js
|
|
297
|
+
* const geographicCoords = new Coordinates('EPSG:4326',
|
|
298
|
+
* 2.33, // longitude
|
|
299
|
+
* 48.24, // latitude
|
|
300
|
+
* 24999549, // altitude
|
|
301
|
+
* );
|
|
302
|
+
* const geocentricCoords = geographicCoords.as('EPSG:4978');
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* @example Conversion from a geocentric to a geographic reference system
|
|
306
|
+
* ```js
|
|
307
|
+
* const geocentricCoords = new Coordinates('EPSG:4978',
|
|
308
|
+
* 20885167, // x
|
|
309
|
+
* 849862, // y
|
|
310
|
+
* 23385912, // z
|
|
311
|
+
* );
|
|
312
|
+
* const geographicCoords = geocentricCoords.as('EPSG:4326');
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
as(crs) {
|
|
316
|
+
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Coordinates(crs);
|
|
317
|
+
if (this.crs == crs) {
|
|
318
|
+
target.copy(this);
|
|
319
|
+
} else {
|
|
320
|
+
if (CRS.is4326(this.crs) && crs == 'EPSG:3857') {
|
|
321
|
+
this.y = THREE.MathUtils.clamp(this.y, -89.999999, 89.999999);
|
|
322
|
+
}
|
|
323
|
+
target.setFromArray(proj4cache(this.crs, crs).forward([this.x, this.y, this.z]));
|
|
324
|
+
}
|
|
325
|
+
target.crs = crs;
|
|
326
|
+
return target;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
coord0 = new Coordinates('EPSG:4326', 0, 0, 0);
|
|
330
|
+
coord1 = new Coordinates('EPSG:4326', 0, 0, 0);
|
|
331
|
+
export default Coordinates;
|