itowns 2.44.3-next.9 → 2.45.0
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/README.md +3 -129
- package/examples/3dtiles_loader.html +20 -6
- package/examples/config.json +1 -0
- package/examples/copc_simple_loader.html +15 -5
- package/examples/effects_stereo.html +2 -2
- package/examples/entwine_3d_loader.html +3 -1
- package/examples/entwine_simple_loader.html +1 -1
- package/examples/images/itowns_logo.svg +123 -0
- package/examples/js/plugins/COGParser.js +1 -1
- package/examples/jsm/OGC3DTilesHelper.js +6 -1
- package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
- package/examples/misc_collada.html +2 -2
- package/examples/source_file_geojson_3d.html +0 -1
- package/examples/source_file_kml_raster_usgs.html +0 -1
- package/examples/source_stream_wfs_raster.html +0 -7
- package/examples/vector_tile_mapbox_raster.html +91 -0
- package/examples/view_3d_map_webxr.html +3 -1
- package/examples/view_multi_25d.html +2 -2
- package/package.json +21 -75
- package/CODING.md +0 -120
- package/CONTRIBUTING.md +0 -150
- package/CONTRIBUTORS.md +0 -55
- package/LICENSE.md +0 -44
- package/changelog.md +0 -1361
- package/dist/455.js +0 -2
- package/dist/455.js.map +0 -1
- package/dist/debug.js +0 -3
- package/dist/debug.js.LICENSE.txt +0 -13
- package/dist/debug.js.map +0 -1
- package/dist/itowns.js +0 -3
- package/dist/itowns.js.LICENSE.txt +0 -7
- package/dist/itowns.js.map +0 -1
- package/dist/itowns_lasparser.js +0 -2
- package/dist/itowns_lasparser.js.map +0 -1
- package/dist/itowns_lasworker.js +0 -2
- package/dist/itowns_lasworker.js.map +0 -1
- package/dist/itowns_potree2worker.js +0 -2
- package/dist/itowns_potree2worker.js.map +0 -1
- package/dist/itowns_widgets.js +0 -2
- package/dist/itowns_widgets.js.map +0 -1
- package/examples/.eslintrc.cjs +0 -35
- package/examples/jsm/.eslintrc.cjs +0 -38
- package/lib/Controls/FirstPersonControls.js +0 -308
- package/lib/Controls/FlyControls.js +0 -175
- package/lib/Controls/GlobeControls.js +0 -1162
- package/lib/Controls/PlanarControls.js +0 -1025
- package/lib/Controls/StateControl.js +0 -429
- package/lib/Controls/StreetControls.js +0 -392
- package/lib/Converter/Feature2Mesh.js +0 -615
- package/lib/Converter/Feature2Texture.js +0 -170
- package/lib/Converter/convertToTile.js +0 -75
- package/lib/Converter/textureConverter.js +0 -44
- package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
- package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
- package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
- package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
- package/lib/Core/3DTiles/C3DTFeature.js +0 -110
- package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
- package/lib/Core/3DTiles/C3DTileset.js +0 -99
- package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
- package/lib/Core/AnimationPlayer.js +0 -142
- package/lib/Core/CopcNode.js +0 -174
- package/lib/Core/Deprecated/Undeprecator.js +0 -75
- package/lib/Core/EntwinePointTileNode.js +0 -126
- package/lib/Core/Feature.js +0 -490
- package/lib/Core/Geographic/CoordStars.js +0 -80
- package/lib/Core/Geographic/Coordinates.js +0 -320
- package/lib/Core/Geographic/Crs.js +0 -175
- package/lib/Core/Geographic/Extent.js +0 -534
- package/lib/Core/Geographic/GeoidGrid.js +0 -109
- package/lib/Core/Label.js +0 -222
- package/lib/Core/MainLoop.js +0 -211
- package/lib/Core/Math/Ellipsoid.js +0 -144
- package/lib/Core/Picking.js +0 -255
- package/lib/Core/PointCloudNode.js +0 -42
- package/lib/Core/Potree2Node.js +0 -206
- package/lib/Core/Potree2PointAttributes.js +0 -139
- package/lib/Core/PotreeNode.js +0 -101
- package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
- package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
- package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
- package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
- package/lib/Core/Prefab/GlobeView.js +0 -161
- package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
- package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
- package/lib/Core/Prefab/PlanarView.js +0 -62
- package/lib/Core/Prefab/TileBuilder.js +0 -80
- package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
- package/lib/Core/Scheduler/Cache.js +0 -256
- package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
- package/lib/Core/Scheduler/Scheduler.js +0 -294
- package/lib/Core/Style.js +0 -1121
- package/lib/Core/System/Capabilities.js +0 -63
- package/lib/Core/Tile/Tile.js +0 -219
- package/lib/Core/Tile/TileGrid.js +0 -46
- package/lib/Core/TileGeometry.js +0 -40
- package/lib/Core/TileMesh.js +0 -109
- package/lib/Core/View.js +0 -1109
- package/lib/Layer/C3DTilesLayer.js +0 -456
- package/lib/Layer/ColorLayer.js +0 -128
- package/lib/Layer/CopcLayer.js +0 -58
- package/lib/Layer/ElevationLayer.js +0 -107
- package/lib/Layer/EntwinePointTileLayer.js +0 -64
- package/lib/Layer/FeatureGeometryLayer.js +0 -63
- package/lib/Layer/GeoidLayer.js +0 -80
- package/lib/Layer/GeometryLayer.js +0 -202
- package/lib/Layer/InfoLayer.js +0 -64
- package/lib/Layer/LabelLayer.js +0 -456
- package/lib/Layer/Layer.js +0 -304
- package/lib/Layer/LayerUpdateState.js +0 -89
- package/lib/Layer/LayerUpdateStrategy.js +0 -80
- package/lib/Layer/OGC3DTilesLayer.js +0 -412
- package/lib/Layer/OrientedImageLayer.js +0 -222
- package/lib/Layer/PointCloudLayer.js +0 -359
- package/lib/Layer/Potree2Layer.js +0 -164
- package/lib/Layer/PotreeLayer.js +0 -65
- package/lib/Layer/RasterLayer.js +0 -27
- package/lib/Layer/ReferencingLayerProperties.js +0 -62
- package/lib/Layer/TiledGeometryLayer.js +0 -403
- package/lib/Loader/LASLoader.js +0 -193
- package/lib/Loader/Potree2BrotliLoader.js +0 -261
- package/lib/Loader/Potree2Loader.js +0 -207
- package/lib/Main.js +0 -115
- package/lib/MainBundle.js +0 -4
- package/lib/Parser/B3dmParser.js +0 -174
- package/lib/Parser/CameraCalibrationParser.js +0 -94
- package/lib/Parser/GDFParser.js +0 -72
- package/lib/Parser/GTXParser.js +0 -75
- package/lib/Parser/GeoJsonParser.js +0 -212
- package/lib/Parser/GpxParser.js +0 -25
- package/lib/Parser/ISGParser.js +0 -71
- package/lib/Parser/KMLParser.js +0 -25
- package/lib/Parser/LASParser.js +0 -137
- package/lib/Parser/MapBoxUrlParser.js +0 -83
- package/lib/Parser/PntsParser.js +0 -131
- package/lib/Parser/Potree2BinParser.js +0 -92
- package/lib/Parser/PotreeBinParser.js +0 -106
- package/lib/Parser/PotreeCinParser.js +0 -29
- package/lib/Parser/ShapefileParser.js +0 -78
- package/lib/Parser/VectorTileParser.js +0 -202
- package/lib/Parser/XbilParser.js +0 -119
- package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
- package/lib/Parser/iGLTFLoader.js +0 -168
- package/lib/Process/3dTilesProcessing.js +0 -304
- package/lib/Process/FeatureProcessing.js +0 -76
- package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
- package/lib/Process/ObjectRemovalHelper.js +0 -97
- package/lib/Process/handlerNodeError.js +0 -23
- package/lib/Provider/3dTilesProvider.js +0 -149
- package/lib/Provider/DataSourceProvider.js +0 -8
- package/lib/Provider/Fetcher.js +0 -229
- package/lib/Provider/PointCloudProvider.js +0 -45
- package/lib/Provider/TileProvider.js +0 -16
- package/lib/Provider/URLBuilder.js +0 -116
- package/lib/Renderer/Camera.js +0 -281
- package/lib/Renderer/Color.js +0 -56
- package/lib/Renderer/ColorLayersOrdering.js +0 -115
- package/lib/Renderer/CommonMaterial.js +0 -31
- package/lib/Renderer/Label2DRenderer.js +0 -190
- package/lib/Renderer/LayeredMaterial.js +0 -243
- package/lib/Renderer/OBB.js +0 -153
- package/lib/Renderer/OrientedImageCamera.js +0 -118
- package/lib/Renderer/OrientedImageMaterial.js +0 -167
- package/lib/Renderer/PointsMaterial.js +0 -485
- package/lib/Renderer/RasterTile.js +0 -209
- package/lib/Renderer/RenderMode.js +0 -31
- package/lib/Renderer/Shader/ShaderChunk.js +0 -160
- package/lib/Renderer/Shader/ShaderUtils.js +0 -47
- package/lib/Renderer/SphereHelper.js +0 -23
- package/lib/Renderer/WebXR.js +0 -51
- package/lib/Renderer/c3DEngine.js +0 -214
- package/lib/Source/C3DTilesGoogleSource.js +0 -74
- package/lib/Source/C3DTilesIonSource.js +0 -54
- package/lib/Source/C3DTilesSource.js +0 -30
- package/lib/Source/CopcSource.js +0 -115
- package/lib/Source/EntwinePointTileSource.js +0 -62
- package/lib/Source/FileSource.js +0 -189
- package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
- package/lib/Source/OGC3DTilesIonSource.js +0 -34
- package/lib/Source/OGC3DTilesSource.js +0 -21
- package/lib/Source/OrientedImageSource.js +0 -59
- package/lib/Source/Potree2Source.js +0 -167
- package/lib/Source/PotreeSource.js +0 -82
- package/lib/Source/Source.js +0 -223
- package/lib/Source/TMSSource.js +0 -145
- package/lib/Source/VectorTilesSource.js +0 -178
- package/lib/Source/WFSSource.js +0 -168
- package/lib/Source/WMSSource.js +0 -133
- package/lib/Source/WMTSSource.js +0 -86
- package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
- package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
- package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
- package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
- package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
- package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
- package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
- package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
- package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
- package/lib/Utils/CameraUtils.js +0 -555
- package/lib/Utils/DEMUtils.js +0 -350
- package/lib/Utils/FeaturesUtils.js +0 -156
- package/lib/Utils/Gradients.js +0 -16
- package/lib/Utils/OrientationUtils.js +0 -457
- package/lib/Utils/ThreeUtils.js +0 -115
- package/lib/Utils/gui/C3DTilesStyle.js +0 -215
- package/lib/Utils/gui/Main.js +0 -7
- package/lib/Utils/gui/Minimap.js +0 -154
- package/lib/Utils/gui/Navigation.js +0 -245
- package/lib/Utils/gui/Scale.js +0 -107
- package/lib/Utils/gui/Searchbar.js +0 -234
- package/lib/Utils/gui/Widget.js +0 -80
- package/lib/Utils/placeObjectOnGround.js +0 -137
- package/lib/Worker/LASLoaderWorker.js +0 -19
- package/lib/Worker/Potree2Worker.js +0 -21
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import proj4 from 'proj4';
|
|
3
|
-
import CRS from "./Crs.js";
|
|
4
|
-
import Ellipsoid from "../Math/Ellipsoid.js";
|
|
5
|
-
proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs');
|
|
6
|
-
const ellipsoid = new Ellipsoid();
|
|
7
|
-
const projectionCache = {};
|
|
8
|
-
const v0 = new THREE.Vector3();
|
|
9
|
-
const v1 = new THREE.Vector3();
|
|
10
|
-
let coord0;
|
|
11
|
-
let coord1;
|
|
12
|
-
function proj4cache(crsIn, crsOut) {
|
|
13
|
-
if (!projectionCache[crsIn]) {
|
|
14
|
-
projectionCache[crsIn] = {};
|
|
15
|
-
}
|
|
16
|
-
if (!projectionCache[crsIn][crsOut]) {
|
|
17
|
-
projectionCache[crsIn][crsOut] = proj4(crsIn, crsOut);
|
|
18
|
-
}
|
|
19
|
-
return projectionCache[crsIn][crsOut];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A Coordinates object, defined by a [crs](http://inspire.ec.europa.eu/theme/rs)
|
|
24
|
-
* and three values. These values are accessible through `x`, `y` and `z`,
|
|
25
|
-
* although it can also be accessible through `latitude`, `longitude` and
|
|
26
|
-
* `altitude`. To change a value, prefer the `set()` method below.
|
|
27
|
-
*
|
|
28
|
-
* `EPSG:4978` and `EPSG:4326` are supported by default. To use another CRS,
|
|
29
|
-
* you have to declare it with `proj4`. You can find most projections and their
|
|
30
|
-
* proj4 code at [epsg.io](https://epsg.io/).
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* new Coordinates('EPSG:4978', 20885167, 849862, 23385912); //Geocentric coordinates
|
|
34
|
-
* new Coordinates('EPSG:4326', 2.33, 48.24, 24999549); //Geographic coordinates
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* // Declare EPSG:3946 with proj4
|
|
38
|
-
* itowns.proj4.defs('EPSG:3946', '+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
|
|
39
|
-
*
|
|
40
|
-
* @property {boolean} isCoordinates - Used to checkout whether this coordinates
|
|
41
|
-
* is a Coordinates. Default is true. You should not change this, as it is used
|
|
42
|
-
* internally for optimisation.
|
|
43
|
-
* @property {string} crs - A supported crs by default in
|
|
44
|
-
* [`proj4js`](https://github.com/proj4js/proj4js#named-projections), or an
|
|
45
|
-
* added crs to `proj4js` (using `proj4.defs`). Note that `EPSG:4978` is also
|
|
46
|
-
* supported by default in itowns.
|
|
47
|
-
* @property {number} x - The first value of the coordinate.
|
|
48
|
-
* @property {number} y - The second value of the coordinate.
|
|
49
|
-
* @property {number} z - The third value of the coordinate.
|
|
50
|
-
* @property {number} latitude - The first value of the coordinate.
|
|
51
|
-
* @property {number} longitude - The second value of the coordinate.
|
|
52
|
-
* @property {number} altitude - The third value of the coordinate.
|
|
53
|
-
* @property {THREE.Vector3} geodesicNormal - The geodesic normal of the
|
|
54
|
-
* coordinate.
|
|
55
|
-
*/
|
|
56
|
-
class Coordinates {
|
|
57
|
-
/**
|
|
58
|
-
* @param {string} crs - A supported Coordinate Reference System.
|
|
59
|
-
* @param {number|Array<number>|Coordinates|THREE.Vector3} [v0=0] -
|
|
60
|
-
* x or longitude value, or a more complex one: it can be an array of three
|
|
61
|
-
* numbers, being x/lon, y/lat, z/alt, or it can be `THREE.Vector3`. It can
|
|
62
|
-
* also simply be a Coordinates.
|
|
63
|
-
* @param {number} [v1=0] - y or latitude value.
|
|
64
|
-
* @param {number} [v2=0] - z or altitude value.
|
|
65
|
-
*/
|
|
66
|
-
constructor(crs) {
|
|
67
|
-
let v0 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
68
|
-
let v1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
69
|
-
let v2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
70
|
-
this.isCoordinates = true;
|
|
71
|
-
CRS.isValid(crs);
|
|
72
|
-
this.crs = crs;
|
|
73
|
-
|
|
74
|
-
// Storing the coordinates as is, not in arrays, as it is
|
|
75
|
-
// slower (see https://jsbench.me/40jumfag6g/1)
|
|
76
|
-
this.x = 0;
|
|
77
|
-
this.y = 0;
|
|
78
|
-
this.z = 0;
|
|
79
|
-
|
|
80
|
-
// Normal
|
|
81
|
-
this._normal = new THREE.Vector3();
|
|
82
|
-
if (v0.length > 0) {
|
|
83
|
-
this.setFromArray(v0);
|
|
84
|
-
} else if (v0.isVector3 || v0.isCoordinates) {
|
|
85
|
-
this.setFromVector3(v0);
|
|
86
|
-
} else {
|
|
87
|
-
this.setFromValues(v0, v1, v2);
|
|
88
|
-
}
|
|
89
|
-
this._normalNeedsUpdate = true;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Sets the Coordinate Reference System.
|
|
94
|
-
* @param {String} crs Coordinate Reference System (e.g. 'EPSG:4978')
|
|
95
|
-
*/
|
|
96
|
-
setCrs(crs) {
|
|
97
|
-
CRS.isValid(crs);
|
|
98
|
-
this.crs = crs;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Set the values of this Coordinates.
|
|
103
|
-
*
|
|
104
|
-
* @param {number} [v0=0] - x or longitude value.
|
|
105
|
-
* @param {number} [v1=0] - y or latitude value.
|
|
106
|
-
* @param {number} [v2=0] - z or altitude value.
|
|
107
|
-
*
|
|
108
|
-
* @return {Coordinates} This Coordinates.
|
|
109
|
-
*/
|
|
110
|
-
setFromValues() {
|
|
111
|
-
let v0 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
112
|
-
let v1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
113
|
-
let v2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
114
|
-
this.x = v0 == undefined ? 0 : v0;
|
|
115
|
-
this.y = v1 == undefined ? 0 : v1;
|
|
116
|
-
this.z = v2 == undefined ? 0 : v2;
|
|
117
|
-
this._normalNeedsUpdate = true;
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Set the values of this Coordinates from an array.
|
|
123
|
-
*
|
|
124
|
-
* @param {Array<number>} array - An array of number to assign to the
|
|
125
|
-
* Coordinates.
|
|
126
|
-
* @param {number} [offset] - Optional offset into the array.
|
|
127
|
-
*
|
|
128
|
-
* @return {Coordinates} This Coordinates.
|
|
129
|
-
*/
|
|
130
|
-
setFromArray(array) {
|
|
131
|
-
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
132
|
-
return this.setFromValues(array[offset], array[offset + 1], array[offset + 2]);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Set the values of this Coordinates from a `THREE.Vector3` or an `Object`
|
|
137
|
-
* having `x/y/z` properties, like a `Coordinates`.
|
|
138
|
-
*
|
|
139
|
-
* @param {THREE.Vector3|Coordinates} v0 - The object to read the values
|
|
140
|
-
* from.
|
|
141
|
-
*
|
|
142
|
-
* @return {Coordinates} This Coordinates.
|
|
143
|
-
*/
|
|
144
|
-
setFromVector3(v0) {
|
|
145
|
-
return this.setFromValues(v0.x, v0.y, v0.z);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Returns a new Coordinates with the same values as this one. It will
|
|
150
|
-
* instantiate a new Coordinates with the same CRS as this one.
|
|
151
|
-
*
|
|
152
|
-
* @return {Coordinates} The target with its new coordinates.
|
|
153
|
-
*/
|
|
154
|
-
clone() {
|
|
155
|
-
return new Coordinates(this.crs, this);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Copies the values of the passed Coordinates to this one. The CRS is
|
|
160
|
-
* however not copied.
|
|
161
|
-
*
|
|
162
|
-
* @param {Coordinates} src - The source to copy from.
|
|
163
|
-
*
|
|
164
|
-
* @return {Coordinates} This Coordinates.
|
|
165
|
-
*/
|
|
166
|
-
copy(src) {
|
|
167
|
-
this.crs = src.crs;
|
|
168
|
-
return this.setFromVector3(src);
|
|
169
|
-
}
|
|
170
|
-
get longitude() {
|
|
171
|
-
return this.x;
|
|
172
|
-
}
|
|
173
|
-
get latitude() {
|
|
174
|
-
return this.y;
|
|
175
|
-
}
|
|
176
|
-
get altitude() {
|
|
177
|
-
return this.z;
|
|
178
|
-
}
|
|
179
|
-
set altitude(value) {
|
|
180
|
-
this.z = value;
|
|
181
|
-
}
|
|
182
|
-
get geodesicNormal() {
|
|
183
|
-
if (this._normalNeedsUpdate) {
|
|
184
|
-
this._normalNeedsUpdate = false;
|
|
185
|
-
if (CRS.is4326(this.crs)) {
|
|
186
|
-
ellipsoid.geodeticSurfaceNormalCartographic(this, this._normal);
|
|
187
|
-
} else if (this.crs == 'EPSG:4978') {
|
|
188
|
-
ellipsoid.geodeticSurfaceNormal(this, this._normal);
|
|
189
|
-
} else {
|
|
190
|
-
this._normal.set(0, 0, 1);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return this._normal;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Return this Coordinates values into a `THREE.Vector3`.
|
|
198
|
-
*
|
|
199
|
-
* @param {THREE.Vector3} [target] - The target to put the values in. If not
|
|
200
|
-
* specified, a new vector will be created.
|
|
201
|
-
*
|
|
202
|
-
* @return {THREE.Vector3}
|
|
203
|
-
*/
|
|
204
|
-
toVector3() {
|
|
205
|
-
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new THREE.Vector3();
|
|
206
|
-
return target.copy(this);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Copy values coordinates to array
|
|
211
|
-
*
|
|
212
|
-
* @param {number[]} array - array to store this vector to. If this is not
|
|
213
|
-
* provided a new array will be created.
|
|
214
|
-
* @param {number} [offset=0] - optional offset into the array.
|
|
215
|
-
*
|
|
216
|
-
* @return {number[]} Returns an array [x, y, z], or copies x, y and z into
|
|
217
|
-
* the provided array.
|
|
218
|
-
*/
|
|
219
|
-
toArray() {
|
|
220
|
-
let array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
221
|
-
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
222
|
-
return THREE.Vector3.prototype.toArray.call(this, array, offset);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Calculate planar distance between this coordinates and `coord`.
|
|
227
|
-
* Planar distance is the straight-line euclidean distance calculated in a 2D cartesian coordinate system.
|
|
228
|
-
*
|
|
229
|
-
* @param {Coordinates} coord The coordinate
|
|
230
|
-
* @return {number} planar distance
|
|
231
|
-
*
|
|
232
|
-
*/
|
|
233
|
-
planarDistanceTo(coord) {
|
|
234
|
-
this.toVector3(v0).setZ(0);
|
|
235
|
-
coord.toVector3(v1).setZ(0);
|
|
236
|
-
return v0.distanceTo(v1);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Calculate geodetic distance between this coordinates and `coord`.
|
|
241
|
-
* **Geodetic distance** is calculated in an ellispoid space as the shortest distance
|
|
242
|
-
* across the curved surface of the world.
|
|
243
|
-
*
|
|
244
|
-
* => As the crow flies/ Orthodromy
|
|
245
|
-
*
|
|
246
|
-
* @param {Coordinates} coord The coordinate
|
|
247
|
-
* @return {number} geodetic distance
|
|
248
|
-
*
|
|
249
|
-
*/
|
|
250
|
-
geodeticDistanceTo(coord) {
|
|
251
|
-
this.as('EPSG:4326', coord0);
|
|
252
|
-
coord.as('EPSG:4326', coord1);
|
|
253
|
-
return ellipsoid.geodesicDistance(coord0, coord1);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Calculate earth euclidean distance between this coordinates and `coord`.
|
|
258
|
-
*
|
|
259
|
-
* @param {Coordinates} coord The coordinate
|
|
260
|
-
* @return {number} earth euclidean distance
|
|
261
|
-
*
|
|
262
|
-
*/
|
|
263
|
-
spatialEuclideanDistanceTo(coord) {
|
|
264
|
-
this.as('EPSG:4978', coord0).toVector3(v0);
|
|
265
|
-
coord.as('EPSG:4978', coord1).toVector3(v1);
|
|
266
|
-
return v0.distanceTo(v1);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Multiplies this `coordinates` (with an implicit 1 in the 4th dimension) and `mat`.
|
|
271
|
-
*
|
|
272
|
-
* @param {THREE.Matrix4} mat The matrix.
|
|
273
|
-
* @return {Coordinates} return this object.
|
|
274
|
-
*/
|
|
275
|
-
applyMatrix4(mat) {
|
|
276
|
-
return THREE.Vector3.prototype.applyMatrix4.call(this, mat);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Returns coordinates in the wanted [CRS](http://inspire.ec.europa.eu/theme/rs).
|
|
281
|
-
*
|
|
282
|
-
* @param {string} crs - The CRS to convert the Coordinates into.
|
|
283
|
-
* @param {Coordinates} [target] - The target to put the converted
|
|
284
|
-
* Coordinates into. If not specified a new one will be created.
|
|
285
|
-
*
|
|
286
|
-
* @return {Coordinates} - The resulting Coordinates after the conversion.
|
|
287
|
-
*
|
|
288
|
-
* @example
|
|
289
|
-
* const position = { longitude: 2.33, latitude: 48.24, altitude: 24999549 };
|
|
290
|
-
* const coords = new Coordinates('EPSG:4326', position.longitude, position.latitude, position.altitude); // Geographic system
|
|
291
|
-
* const coordinates = coords.as('EPSG:4978'); // Geocentric system
|
|
292
|
-
*
|
|
293
|
-
* @example
|
|
294
|
-
* const position = { x: 20885167, y: 849862, z: 23385912 };
|
|
295
|
-
* const coords = new Coordinates('EPSG:4978', position.x, position.y, position.z); // Geocentric system
|
|
296
|
-
* const coordinates = coords.as('EPSG:4326'); // Geographic system
|
|
297
|
-
*
|
|
298
|
-
* @example
|
|
299
|
-
* new Coordinates('EPSG:4326', longitude: 2.33, latitude: 48.24, altitude: 24999549).as('EPSG:4978'); // Geocentric system
|
|
300
|
-
*
|
|
301
|
-
* @example
|
|
302
|
-
* new Coordinates('EPSG:4978', x: 20885167, y: 849862, z: 23385912).as('EPSG:4326'); // Geographic system
|
|
303
|
-
*/
|
|
304
|
-
as(crs) {
|
|
305
|
-
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Coordinates(crs);
|
|
306
|
-
if (this.crs == crs) {
|
|
307
|
-
target.copy(this);
|
|
308
|
-
} else {
|
|
309
|
-
if (CRS.is4326(this.crs) && crs == 'EPSG:3857') {
|
|
310
|
-
this.y = THREE.MathUtils.clamp(this.y, -89.999999, 89.999999);
|
|
311
|
-
}
|
|
312
|
-
target.setFromArray(proj4cache(this.crs, crs).forward([this.x, this.y, this.z]));
|
|
313
|
-
}
|
|
314
|
-
target.crs = crs;
|
|
315
|
-
return target;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
coord0 = new Coordinates('EPSG:4326', 0, 0, 0);
|
|
319
|
-
coord1 = new Coordinates('EPSG:4326', 0, 0, 0);
|
|
320
|
-
export default Coordinates;
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import proj4 from 'proj4';
|
|
2
|
-
proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs');
|
|
3
|
-
function isString(s) {
|
|
4
|
-
return typeof s === 'string' || s instanceof String;
|
|
5
|
-
}
|
|
6
|
-
function mustBeString(crs) {
|
|
7
|
-
if (!isString(crs)) {
|
|
8
|
-
throw new Error(`Crs parameter value must be a string: '${crs}'`);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function isTms(crs) {
|
|
12
|
-
return isString(crs) && crs.startsWith('TMS');
|
|
13
|
-
}
|
|
14
|
-
function isEpsg(crs) {
|
|
15
|
-
return isString(crs) && crs.startsWith('EPSG');
|
|
16
|
-
}
|
|
17
|
-
function formatToTms(crs) {
|
|
18
|
-
mustBeString(crs);
|
|
19
|
-
return isTms(crs) ? crs : `TMS:${crs.match(/\d+/)[0]}`;
|
|
20
|
-
}
|
|
21
|
-
function formatToEPSG(crs) {
|
|
22
|
-
mustBeString(crs);
|
|
23
|
-
return isEpsg(crs) ? crs : `EPSG:${crs.match(/\d+/)[0]}`;
|
|
24
|
-
}
|
|
25
|
-
const UNIT = {
|
|
26
|
-
DEGREE: 1,
|
|
27
|
-
METER: 2
|
|
28
|
-
};
|
|
29
|
-
function is4326(crs) {
|
|
30
|
-
return crs === 'EPSG:4326';
|
|
31
|
-
}
|
|
32
|
-
function isGeocentric(crs) {
|
|
33
|
-
mustBeString(crs);
|
|
34
|
-
const projection = proj4.defs(crs);
|
|
35
|
-
return !projection ? false : projection.projName == 'geocent';
|
|
36
|
-
}
|
|
37
|
-
function _unitFromProj4Unit(projunit) {
|
|
38
|
-
if (projunit === 'degrees') {
|
|
39
|
-
return UNIT.DEGREE;
|
|
40
|
-
} else if (projunit === 'm') {
|
|
41
|
-
return UNIT.METER;
|
|
42
|
-
} else {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function toUnit(crs) {
|
|
47
|
-
mustBeString(crs);
|
|
48
|
-
switch (crs) {
|
|
49
|
-
case 'EPSG:4326':
|
|
50
|
-
return UNIT.DEGREE;
|
|
51
|
-
case 'EPSG:4978':
|
|
52
|
-
return UNIT.METER;
|
|
53
|
-
default:
|
|
54
|
-
{
|
|
55
|
-
const p = proj4.defs(formatToEPSG(crs));
|
|
56
|
-
if (!p) {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
return _unitFromProj4Unit(p.units);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function toUnitWithError(crs) {
|
|
64
|
-
mustBeString(crs);
|
|
65
|
-
const u = toUnit(crs);
|
|
66
|
-
if (u === undefined) {
|
|
67
|
-
throw new Error(`No unit found for crs: '${crs}'`);
|
|
68
|
-
}
|
|
69
|
-
return u;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* This module provides basic methods to manipulate a CRS (as a string).
|
|
74
|
-
*
|
|
75
|
-
* @module CRS
|
|
76
|
-
*/
|
|
77
|
-
export default {
|
|
78
|
-
/**
|
|
79
|
-
* Units that can be used for a CRS.
|
|
80
|
-
*
|
|
81
|
-
* @enum {number}
|
|
82
|
-
*/
|
|
83
|
-
UNIT,
|
|
84
|
-
/**
|
|
85
|
-
* Assert that the CRS is valid one.
|
|
86
|
-
*
|
|
87
|
-
* @param {string} crs - The CRS to validate.
|
|
88
|
-
*
|
|
89
|
-
* @throws {Error} if the CRS is not valid.
|
|
90
|
-
*/
|
|
91
|
-
isValid(crs) {
|
|
92
|
-
toUnitWithError(crs);
|
|
93
|
-
},
|
|
94
|
-
/**
|
|
95
|
-
* Assert that the CRS is geographic.
|
|
96
|
-
*
|
|
97
|
-
* @param {string} crs - The CRS to validate.
|
|
98
|
-
* @return {boolean}
|
|
99
|
-
* @throws {Error} if the CRS is not valid.
|
|
100
|
-
*/
|
|
101
|
-
isGeographic(crs) {
|
|
102
|
-
return toUnitWithError(crs) == UNIT.DEGREE;
|
|
103
|
-
},
|
|
104
|
-
/**
|
|
105
|
-
* Assert that the CRS is using metric units.
|
|
106
|
-
*
|
|
107
|
-
* @param {string} crs - The CRS to validate.
|
|
108
|
-
* @return {boolean}
|
|
109
|
-
* @throws {Error} if the CRS is not valid.
|
|
110
|
-
*/
|
|
111
|
-
isMetricUnit(crs) {
|
|
112
|
-
return toUnit(crs) == UNIT.METER;
|
|
113
|
-
},
|
|
114
|
-
/**
|
|
115
|
-
* Get the unit to use with the CRS.
|
|
116
|
-
*
|
|
117
|
-
* @param {string} crs - The CRS to get the unit from.
|
|
118
|
-
* @return {number} Either `UNIT.METER`, `UNIT.DEGREE` or `undefined`.
|
|
119
|
-
*/
|
|
120
|
-
toUnit,
|
|
121
|
-
/**
|
|
122
|
-
* Is the CRS EPSG:4326 ?
|
|
123
|
-
*
|
|
124
|
-
* @param {string} crs - The CRS to test.
|
|
125
|
-
* @return {boolean}
|
|
126
|
-
*/
|
|
127
|
-
is4326,
|
|
128
|
-
/**
|
|
129
|
-
* Is the CRS geocentric ?
|
|
130
|
-
* if crs isn't defined the method returns false.
|
|
131
|
-
*
|
|
132
|
-
* @param {string} crs - The CRS to test.
|
|
133
|
-
* @return {boolean}
|
|
134
|
-
*/
|
|
135
|
-
isGeocentric,
|
|
136
|
-
/**
|
|
137
|
-
* Give a reasonnable epsilon to use with this CRS.
|
|
138
|
-
*
|
|
139
|
-
* @param {string} crs - The CRS to use.
|
|
140
|
-
* @return {number} 0.01 if the CRS is EPSG:4326, 0.001 otherwise.
|
|
141
|
-
*/
|
|
142
|
-
reasonnableEpsilon(crs) {
|
|
143
|
-
if (is4326(crs)) {
|
|
144
|
-
return 0.01;
|
|
145
|
-
} else {
|
|
146
|
-
return 0.001;
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
/**
|
|
150
|
-
* format crs to European Petroleum Survey Group notation : EPSG:XXXX.
|
|
151
|
-
*
|
|
152
|
-
* @param {string} crs The crs to format
|
|
153
|
-
* @return {string} formated crs
|
|
154
|
-
*/
|
|
155
|
-
formatToEPSG,
|
|
156
|
-
/**
|
|
157
|
-
* format crs to tile matrix set notation : TMS:XXXX.
|
|
158
|
-
*
|
|
159
|
-
* @param {string} crs The crs to format
|
|
160
|
-
* @return {string} formated crs
|
|
161
|
-
*/
|
|
162
|
-
formatToTms,
|
|
163
|
-
isTms,
|
|
164
|
-
isEpsg,
|
|
165
|
-
tms_3857: 'TMS:3857',
|
|
166
|
-
tms_4326: 'TMS:4326',
|
|
167
|
-
/**
|
|
168
|
-
* Define a proj4 projection as a string and reference.
|
|
169
|
-
*
|
|
170
|
-
* @param {string} code code is the projection's SRS code (only used internally by the Proj4js library)
|
|
171
|
-
* @param {string} proj4def is the Proj4 definition string for the projection to use
|
|
172
|
-
* @return {undefined}
|
|
173
|
-
*/
|
|
174
|
-
defs: (code, proj4def) => proj4.defs(code, proj4def)
|
|
175
|
-
};
|