itowns 2.44.3-next.40 → 2.44.3-next.41

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.
Files changed (199) hide show
  1. package/README.md +3 -129
  2. package/package.json +16 -72
  3. package/CODING.md +0 -120
  4. package/CONTRIBUTING.md +0 -150
  5. package/CONTRIBUTORS.md +0 -56
  6. package/LICENSE.md +0 -44
  7. package/changelog.md +0 -1361
  8. package/dist/455.js +0 -2
  9. package/dist/455.js.map +0 -1
  10. package/dist/debug.js +0 -3
  11. package/dist/debug.js.LICENSE.txt +0 -13
  12. package/dist/debug.js.map +0 -1
  13. package/dist/itowns.js +0 -3
  14. package/dist/itowns.js.LICENSE.txt +0 -5
  15. package/dist/itowns.js.map +0 -1
  16. package/dist/itowns_lasparser.js +0 -2
  17. package/dist/itowns_lasparser.js.map +0 -1
  18. package/dist/itowns_lasworker.js +0 -2
  19. package/dist/itowns_lasworker.js.map +0 -1
  20. package/dist/itowns_potree2worker.js +0 -2
  21. package/dist/itowns_potree2worker.js.map +0 -1
  22. package/dist/itowns_widgets.js +0 -2
  23. package/dist/itowns_widgets.js.map +0 -1
  24. package/examples/.eslintrc.cjs +0 -35
  25. package/examples/jsm/.eslintrc.cjs +0 -38
  26. package/lib/Controls/FirstPersonControls.js +0 -308
  27. package/lib/Controls/FlyControls.js +0 -175
  28. package/lib/Controls/GlobeControls.js +0 -1179
  29. package/lib/Controls/PlanarControls.js +0 -1025
  30. package/lib/Controls/StateControl.js +0 -432
  31. package/lib/Controls/StreetControls.js +0 -392
  32. package/lib/Converter/Feature2Mesh.js +0 -614
  33. package/lib/Converter/Feature2Texture.js +0 -175
  34. package/lib/Converter/convertToTile.js +0 -70
  35. package/lib/Converter/textureConverter.js +0 -43
  36. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  37. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  38. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  39. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  40. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  41. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  42. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  43. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  44. package/lib/Core/AnimationPlayer.js +0 -142
  45. package/lib/Core/CopcNode.js +0 -174
  46. package/lib/Core/Deprecated/Undeprecator.js +0 -74
  47. package/lib/Core/EntwinePointTileNode.js +0 -126
  48. package/lib/Core/Feature.js +0 -489
  49. package/lib/Core/Geographic/CoordStars.js +0 -80
  50. package/lib/Core/Geographic/Coordinates.js +0 -331
  51. package/lib/Core/Geographic/Crs.js +0 -170
  52. package/lib/Core/Geographic/Extent.js +0 -550
  53. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  54. package/lib/Core/Label.js +0 -222
  55. package/lib/Core/MainLoop.js +0 -209
  56. package/lib/Core/Math/Ellipsoid.js +0 -185
  57. package/lib/Core/Picking.js +0 -255
  58. package/lib/Core/PointCloudNode.js +0 -42
  59. package/lib/Core/Potree2Node.js +0 -206
  60. package/lib/Core/Potree2PointAttributes.js +0 -139
  61. package/lib/Core/PotreeNode.js +0 -101
  62. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -295
  63. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -152
  64. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +0 -111
  65. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  66. package/lib/Core/Prefab/GlobeView.js +0 -156
  67. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -59
  68. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  69. package/lib/Core/Prefab/PlanarView.js +0 -62
  70. package/lib/Core/Prefab/TileBuilder.js +0 -82
  71. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -248
  72. package/lib/Core/Scheduler/Cache.js +0 -17
  73. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  74. package/lib/Core/Scheduler/Scheduler.js +0 -294
  75. package/lib/Core/Style.js +0 -660
  76. package/lib/Core/StyleOptions.js +0 -486
  77. package/lib/Core/System/Capabilities.js +0 -63
  78. package/lib/Core/Tile/Tile.js +0 -207
  79. package/lib/Core/Tile/TileGrid.js +0 -49
  80. package/lib/Core/TileGeometry.js +0 -124
  81. package/lib/Core/TileMesh.js +0 -108
  82. package/lib/Core/View.js +0 -1116
  83. package/lib/Layer/C3DTilesLayer.js +0 -459
  84. package/lib/Layer/ColorLayer.js +0 -154
  85. package/lib/Layer/CopcLayer.js +0 -63
  86. package/lib/Layer/ElevationLayer.js +0 -139
  87. package/lib/Layer/EntwinePointTileLayer.js +0 -71
  88. package/lib/Layer/FeatureGeometryLayer.js +0 -77
  89. package/lib/Layer/GeoidLayer.js +0 -80
  90. package/lib/Layer/GeometryLayer.js +0 -233
  91. package/lib/Layer/InfoLayer.js +0 -64
  92. package/lib/Layer/LabelLayer.js +0 -470
  93. package/lib/Layer/Layer.js +0 -335
  94. package/lib/Layer/LayerUpdateState.js +0 -89
  95. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  96. package/lib/Layer/OGC3DTilesLayer.js +0 -543
  97. package/lib/Layer/OrientedImageLayer.js +0 -228
  98. package/lib/Layer/PointCloudLayer.js +0 -405
  99. package/lib/Layer/Potree2Layer.js +0 -171
  100. package/lib/Layer/PotreeLayer.js +0 -72
  101. package/lib/Layer/RasterLayer.js +0 -37
  102. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  103. package/lib/Layer/TiledGeometryLayer.js +0 -459
  104. package/lib/Loader/LASLoader.js +0 -193
  105. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  106. package/lib/Loader/Potree2Loader.js +0 -207
  107. package/lib/Main.js +0 -115
  108. package/lib/MainBundle.js +0 -4
  109. package/lib/Parser/B3dmParser.js +0 -174
  110. package/lib/Parser/CameraCalibrationParser.js +0 -94
  111. package/lib/Parser/GDFParser.js +0 -72
  112. package/lib/Parser/GTXParser.js +0 -75
  113. package/lib/Parser/GeoJsonParser.js +0 -212
  114. package/lib/Parser/GpxParser.js +0 -25
  115. package/lib/Parser/ISGParser.js +0 -71
  116. package/lib/Parser/KMLParser.js +0 -25
  117. package/lib/Parser/LASParser.js +0 -137
  118. package/lib/Parser/MapBoxUrlParser.js +0 -83
  119. package/lib/Parser/PntsParser.js +0 -131
  120. package/lib/Parser/Potree2BinParser.js +0 -92
  121. package/lib/Parser/PotreeBinParser.js +0 -106
  122. package/lib/Parser/PotreeCinParser.js +0 -29
  123. package/lib/Parser/ShapefileParser.js +0 -78
  124. package/lib/Parser/VectorTileParser.js +0 -215
  125. package/lib/Parser/XbilParser.js +0 -120
  126. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  127. package/lib/Parser/iGLTFLoader.js +0 -168
  128. package/lib/Process/3dTilesProcessing.js +0 -304
  129. package/lib/Process/FeatureProcessing.js +0 -76
  130. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  131. package/lib/Process/ObjectRemovalHelper.js +0 -97
  132. package/lib/Process/handlerNodeError.js +0 -23
  133. package/lib/Provider/3dTilesProvider.js +0 -149
  134. package/lib/Provider/DataSourceProvider.js +0 -8
  135. package/lib/Provider/Fetcher.js +0 -233
  136. package/lib/Provider/PointCloudProvider.js +0 -45
  137. package/lib/Provider/TileProvider.js +0 -16
  138. package/lib/Provider/URLBuilder.js +0 -116
  139. package/lib/Renderer/Camera.js +0 -281
  140. package/lib/Renderer/Color.js +0 -56
  141. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  142. package/lib/Renderer/CommonMaterial.js +0 -31
  143. package/lib/Renderer/Label2DRenderer.js +0 -192
  144. package/lib/Renderer/LayeredMaterial.js +0 -243
  145. package/lib/Renderer/OBB.js +0 -151
  146. package/lib/Renderer/OrientedImageCamera.js +0 -118
  147. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  148. package/lib/Renderer/PointsMaterial.js +0 -485
  149. package/lib/Renderer/RasterTile.js +0 -208
  150. package/lib/Renderer/RenderMode.js +0 -31
  151. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  152. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  153. package/lib/Renderer/SphereHelper.js +0 -17
  154. package/lib/Renderer/WebXR.js +0 -51
  155. package/lib/Renderer/c3DEngine.js +0 -214
  156. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  157. package/lib/Source/C3DTilesIonSource.js +0 -54
  158. package/lib/Source/C3DTilesSource.js +0 -30
  159. package/lib/Source/CopcSource.js +0 -126
  160. package/lib/Source/EntwinePointTileSource.js +0 -72
  161. package/lib/Source/FileSource.js +0 -188
  162. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  163. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  164. package/lib/Source/OGC3DTilesSource.js +0 -21
  165. package/lib/Source/OrientedImageSource.js +0 -59
  166. package/lib/Source/Potree2Source.js +0 -167
  167. package/lib/Source/PotreeSource.js +0 -82
  168. package/lib/Source/Source.js +0 -203
  169. package/lib/Source/TMSSource.js +0 -144
  170. package/lib/Source/VectorTilesSource.js +0 -182
  171. package/lib/Source/WFSSource.js +0 -170
  172. package/lib/Source/WMSSource.js +0 -168
  173. package/lib/Source/WMTSSource.js +0 -92
  174. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  175. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -506
  176. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  177. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  178. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -400
  179. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2879
  180. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -709
  181. package/lib/ThreeExtended/math/ColorSpaces.js +0 -59
  182. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  183. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  184. package/lib/Utils/CameraUtils.js +0 -555
  185. package/lib/Utils/DEMUtils.js +0 -350
  186. package/lib/Utils/FeaturesUtils.js +0 -156
  187. package/lib/Utils/Gradients.js +0 -16
  188. package/lib/Utils/OrientationUtils.js +0 -457
  189. package/lib/Utils/ThreeUtils.js +0 -115
  190. package/lib/Utils/gui/C3DTilesStyle.js +0 -215
  191. package/lib/Utils/gui/Main.js +0 -7
  192. package/lib/Utils/gui/Minimap.js +0 -154
  193. package/lib/Utils/gui/Navigation.js +0 -245
  194. package/lib/Utils/gui/Scale.js +0 -107
  195. package/lib/Utils/gui/Searchbar.js +0 -234
  196. package/lib/Utils/gui/Widget.js +0 -80
  197. package/lib/Utils/placeObjectOnGround.js +0 -136
  198. package/lib/Worker/LASLoaderWorker.js +0 -19
  199. package/lib/Worker/Potree2Worker.js +0 -21
@@ -1,331 +0,0 @@
1
- import * as THREE from 'three';
2
- import proj4 from 'proj4';
3
- import * as CRS from "./Crs.js";
4
- import Ellipsoid from "../Math/Ellipsoid.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;
@@ -1,170 +0,0 @@
1
- import proj4 from 'proj4';
2
- proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs');
3
-
4
- // Redefining proj4 global projections to match epsg.org database axis order.
5
- // See https://github.com/iTowns/itowns/pull/2465#issuecomment-2517024859
6
- proj4.defs('EPSG:4326').axis = 'neu';
7
- proj4.defs('EPSG:4269').axis = 'neu';
8
- proj4.defs('WGS84').axis = 'neu';
9
-
10
- /**
11
- * A projection as a CRS identifier string. This identifier references a
12
- * projection definition previously defined with
13
- * [`proj4.defs`](https://github.com/proj4js/proj4js#named-projections).
14
- */
15
-
16
- function isString(s) {
17
- return typeof s === 'string' || s instanceof String;
18
- }
19
- function mustBeString(crs) {
20
- if (!isString(crs)) {
21
- throw new Error(`Crs parameter value must be a string: '${crs}'`);
22
- }
23
- }
24
-
25
- /**
26
- * System units supported for a coordinate system. See
27
- * [proj](https://proj4.org/en/9.5/operations/conversions/unitconvert.html#angular-units).
28
- * Note that only degree and meters units are supported for now.
29
- */
30
- export const UNIT = {
31
- /**
32
- * Angular unit in degree.
33
- */
34
- DEGREE: 1,
35
- /**
36
- * Distance unit in meter.
37
- */
38
- METER: 2,
39
- /**
40
- * Distance unit in foot.
41
- */
42
- FOOT: 3
43
- };
44
-
45
- /**
46
- * Checks that the CRS is EPSG:4326.
47
- * @internal
48
- *
49
- * @param crs - The CRS to test.
50
- */
51
- export function is4326(crs) {
52
- return crs === 'EPSG:4326';
53
- }
54
- function unitFromProj4Unit(proj) {
55
- if (proj.units === 'degrees') {
56
- return UNIT.DEGREE;
57
- } else if (proj.units === 'm' || proj.units === 'meter') {
58
- return UNIT.METER;
59
- } else if (proj.units === 'foot') {
60
- return UNIT.FOOT;
61
- } else if (proj.units === undefined && proj.to_meter === undefined) {
62
- // See https://proj.org/en/9.4/usage/projections.html [17/10/2024]
63
- // > The default unit for projected coordinates is the meter.
64
- return UNIT.METER;
65
- } else {
66
- return undefined;
67
- }
68
- }
69
-
70
- /**
71
- * Returns the horizontal coordinates system units associated with this CRS.
72
- *
73
- * @param crs - The CRS to extract the unit from.
74
- * @returns Either `UNIT.METER`, `UNIT.DEGREE`, `UNIT.FOOT` or `undefined`.
75
- */
76
- export function getUnit(crs) {
77
- mustBeString(crs);
78
- const p = proj4.defs(crs);
79
- if (!p) {
80
- return undefined;
81
- }
82
- return unitFromProj4Unit(p);
83
- }
84
-
85
- /**
86
- * Asserts that the CRS is using metric units.
87
- *
88
- * @param crs - The CRS to check.
89
- * @throws {@link Error} if the CRS is not valid.
90
- */
91
- export function isMetricUnit(crs) {
92
- return getUnit(crs) === UNIT.METER;
93
- }
94
-
95
- /**
96
- * Asserts that the CRS is geographic.
97
- *
98
- * @param crs - The CRS to check.
99
- * @throws {@link Error} if the CRS is not valid.
100
- */
101
- export function isGeographic(crs) {
102
- return getUnit(crs) === UNIT.DEGREE;
103
- }
104
-
105
- /**
106
- * Asserts that the CRS is geocentric.
107
- *
108
- * @param crs - The CRS to test.
109
- * @returns false if the crs isn't defined.
110
- */
111
- export function isGeocentric(crs) {
112
- mustBeString(crs);
113
- const projection = proj4.defs(crs);
114
- return !projection ? false : projection.projName == 'geocent';
115
- }
116
-
117
- /**
118
- * Asserts that the CRS is valid, meaning it has been previously defined and
119
- * includes an unit.
120
- *
121
- * @param crs - The CRS to test.
122
- * @throws {@link Error} if the crs is not valid.
123
- */
124
- export function isValid(crs) {
125
- const proj = proj4.defs(crs);
126
- if (!proj) {
127
- throw new Error(`Undefined crs '${crs}'. Add it with proj4.defs('${crs}', string)`);
128
- }
129
- if (!unitFromProj4Unit(proj)) {
130
- throw new Error(`No valid unit found for crs '${crs}', found ${proj.units}`);
131
- }
132
- }
133
-
134
- /**
135
- * Gives a reasonable epsilon for this CRS.
136
- *
137
- * @param crs - The CRS to use.
138
- * @returns 0.01 if the CRS is EPSG:4326, 0.001 otherwise.
139
- */
140
- export function reasonableEpsilon(crs) {
141
- if (is4326(crs)) {
142
- return 0.01;
143
- } else {
144
- return 0.001;
145
- }
146
- }
147
-
148
- /**
149
- * Returns the axis parameter defined in proj4 for the provided crs.
150
- * Might be undefined depending on crs definition.
151
- *
152
- * @param crs - The CRS to get axis from.
153
- * @returns the matching proj4 axis string, 'enu' for instance (east, north, up)
154
- */
155
- export function axisOrder(crs) {
156
- mustBeString(crs);
157
- const projection = proj4.defs(crs);
158
- return !projection ? undefined : projection.axis;
159
- }
160
-
161
- /**
162
- * Defines a proj4 projection as a named alias.
163
- * This function is a specialized wrapper over the
164
- * [`proj4.defs`](https://github.com/proj4js/proj4js#named-projections)
165
- * function.
166
- *
167
- * @param code - Named alias of the currently defined projection.
168
- * @param proj4def - Proj4 or WKT string of the defined projection.
169
- */
170
- export const defs = (code, proj4def) => proj4.defs(code, proj4def);