itowns 2.44.3-next.8 → 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 +123 -48
- package/examples/config.json +3 -10
- 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/3dtiles_25d.html +0 -120
- package/examples/3dtiles_basic.html +0 -94
- package/examples/3dtiles_batch_table.html +0 -86
- package/examples/3dtiles_ion.html +0 -126
- package/examples/3dtiles_pointcloud.html +0 -95
- 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 -455
- 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 -387
- 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
package/lib/Parser/B3dmParser.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import C3DTBatchTable from "../Core/3DTiles/C3DTBatchTable.js";
|
|
3
|
-
import Capabilities from "../Core/System/Capabilities.js";
|
|
4
|
-
import { MeshBasicMaterial } from 'three';
|
|
5
|
-
import disposeThreeMaterial from "../Utils/ThreeUtils.js";
|
|
6
|
-
import shaderUtils from "../Renderer/Shader/ShaderUtils.js";
|
|
7
|
-
import ReferLayerProperties from "../Layer/ReferencingLayerProperties.js";
|
|
8
|
-
// A bit weird but temporary until we remove this deprecated parser. Mainly to benefit from the enableDracoLoader and enableKtx2Loader
|
|
9
|
-
// methods.
|
|
10
|
-
import { itownsGLTFLoader } from "../Layer/OGC3DTilesLayer.js";
|
|
11
|
-
const matrixChangeUpVectorYtoZ = new THREE.Matrix4().makeRotationX(Math.PI / 2);
|
|
12
|
-
const matrixChangeUpVectorXtoZ = new THREE.Matrix4().makeRotationZ(-Math.PI / 2);
|
|
13
|
-
const utf8Decoder = new TextDecoder();
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 3D Tiles pre-1.0 contain not standardized and specific uniforms that we filter out to avoid shader compilation errors
|
|
17
|
-
* This method is passed to scene.traverse and applied to all 3D objects of the loaded gltf.
|
|
18
|
-
* @param {THREE.Object3D} obj - 3D object of the gltf hierarchy
|
|
19
|
-
*/
|
|
20
|
-
function filterUnsupportedSemantics(obj) {
|
|
21
|
-
// see GLTFLoader GLTFShader.prototype.update function
|
|
22
|
-
const supported = ['MODELVIEW', 'MODELVIEWINVERSETRANSPOSE', 'PROJECTION', 'JOINTMATRIX'];
|
|
23
|
-
if (obj.gltfShader) {
|
|
24
|
-
const names = [];
|
|
25
|
-
// eslint-disable-next-line guard-for-in
|
|
26
|
-
for (const name in obj.gltfShader.boundUniforms) {
|
|
27
|
-
names.push(name);
|
|
28
|
-
}
|
|
29
|
-
for (const name of names) {
|
|
30
|
-
const semantic = obj.gltfShader.boundUniforms[name].semantic;
|
|
31
|
-
if (!supported.includes(semantic)) {
|
|
32
|
-
delete obj.gltfShader.boundUniforms[name];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Transforms loaded gltf model to z-up (either from y-up or from the up axis defined in gltfUpAxis). Note that
|
|
40
|
-
* gltfUpAxis was an attribut of pre-1.0 3D Tiles and is now deprecated.
|
|
41
|
-
* @param {THREE.Object3D} gltfScene - the parsed glTF scene
|
|
42
|
-
* @param {String} gltfUpAxis - the gltfUpAxis parameter
|
|
43
|
-
*/
|
|
44
|
-
function transformToZUp(gltfScene, gltfUpAxis) {
|
|
45
|
-
if (!gltfUpAxis || gltfUpAxis === 'Y') {
|
|
46
|
-
gltfScene.applyMatrix4(matrixChangeUpVectorYtoZ);
|
|
47
|
-
} else if (gltfUpAxis === 'X') {
|
|
48
|
-
gltfScene.applyMatrix4(matrixChangeUpVectorXtoZ);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @module B3dmParser
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
export default {
|
|
57
|
-
/** Parse b3dm buffer and extract THREE.Scene and batch table
|
|
58
|
-
* @param {ArrayBuffer} buffer - the b3dm buffer.
|
|
59
|
-
* @param {Object} options - additional properties.
|
|
60
|
-
* @param {string=} [options.gltfUpAxis='Y'] - embedded glTF model up axis.
|
|
61
|
-
* @param {string} options.urlBase - the base url of the b3dm file (used to fetch textures for the embedded glTF model).
|
|
62
|
-
* @param {boolean=} [options.doNotPatchMaterial=false] - disable patching material with logarithmic depth buffer support.
|
|
63
|
-
* @param {float} [options.opacity=1.0] - the b3dm opacity.
|
|
64
|
-
* @param {boolean=} [options.frustumCulled=false] - enable frustum culling.
|
|
65
|
-
* @param {boolean|Material=} [options.overrideMaterials=false] - override b3dm's embedded glTF materials. If
|
|
66
|
-
* true, a threejs [MeshBasicMaterial](https://threejs.org/docs/index.html?q=meshbasic#api/en/materials/MeshBasicMaterial)
|
|
67
|
-
* is set up. config.overrideMaterials can also be a threejs [Material](https://threejs.org/docs/index.html?q=material#api/en/materials/Material)
|
|
68
|
-
* in which case it will be the material used to override.
|
|
69
|
-
* @return {Promise} - a promise that resolves with an object containig a THREE.Scene (gltf) and a batch table (batchTable).
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
|
-
parse(buffer, options) {
|
|
73
|
-
const frustumCulled = options.frustumCulled === true;
|
|
74
|
-
if (!buffer) {
|
|
75
|
-
throw new Error('No array buffer provided.');
|
|
76
|
-
}
|
|
77
|
-
const view = new DataView(buffer, 4); // starts after magic
|
|
78
|
-
|
|
79
|
-
let byteOffset = 0;
|
|
80
|
-
const b3dmHeader = {};
|
|
81
|
-
|
|
82
|
-
// Magic type is unsigned char [4]
|
|
83
|
-
const magicNumberByteLength = 4;
|
|
84
|
-
b3dmHeader.magic = utf8Decoder.decode(new Uint8Array(buffer, 0, magicNumberByteLength));
|
|
85
|
-
if (b3dmHeader.magic) {
|
|
86
|
-
// Version, byteLength, batchTableJSONByteLength, batchTableBinaryByteLength and batchTable types are uint32
|
|
87
|
-
b3dmHeader.version = view.getUint32(byteOffset, true);
|
|
88
|
-
byteOffset += Uint32Array.BYTES_PER_ELEMENT;
|
|
89
|
-
b3dmHeader.byteLength = view.getUint32(byteOffset, true);
|
|
90
|
-
byteOffset += Uint32Array.BYTES_PER_ELEMENT;
|
|
91
|
-
b3dmHeader.FTJSONLength = view.getUint32(byteOffset, true);
|
|
92
|
-
byteOffset += Uint32Array.BYTES_PER_ELEMENT;
|
|
93
|
-
b3dmHeader.FTBinaryLength = view.getUint32(byteOffset, true);
|
|
94
|
-
byteOffset += Uint32Array.BYTES_PER_ELEMENT;
|
|
95
|
-
b3dmHeader.BTJSONLength = view.getUint32(byteOffset, true);
|
|
96
|
-
byteOffset += Uint32Array.BYTES_PER_ELEMENT;
|
|
97
|
-
b3dmHeader.BTBinaryLength = view.getUint32(byteOffset, true);
|
|
98
|
-
byteOffset += Uint32Array.BYTES_PER_ELEMENT;
|
|
99
|
-
const headerByteLength = byteOffset + magicNumberByteLength;
|
|
100
|
-
const promises = [];
|
|
101
|
-
let FTJSON = {};
|
|
102
|
-
const FT_RTC = new THREE.Vector3();
|
|
103
|
-
if (b3dmHeader.FTJSONLength > 0) {
|
|
104
|
-
const sizeBegin = headerByteLength;
|
|
105
|
-
const jsonBuffer = buffer.slice(sizeBegin, b3dmHeader.FTJSONLength + sizeBegin);
|
|
106
|
-
const content = utf8Decoder.decode(new Uint8Array(jsonBuffer));
|
|
107
|
-
FTJSON = JSON.parse(content);
|
|
108
|
-
if (FTJSON.RTC_CENTER) {
|
|
109
|
-
FT_RTC.fromArray(FTJSON.RTC_CENTER);
|
|
110
|
-
} else {
|
|
111
|
-
FT_RTC.set(0, 0, 0);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (b3dmHeader.FTBinaryLength > 0) {
|
|
115
|
-
console.warn('3D Tiles feature table binary not supported yet.');
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Parse batch table
|
|
119
|
-
if (b3dmHeader.BTJSONLength > 0) {
|
|
120
|
-
// sizeBegin is an index to the beginning of the batch table
|
|
121
|
-
const sizeBegin = headerByteLength + b3dmHeader.FTJSONLength + b3dmHeader.FTBinaryLength;
|
|
122
|
-
const BTBuffer = buffer.slice(sizeBegin, sizeBegin + b3dmHeader.BTJSONLength + b3dmHeader.BTBinaryLength);
|
|
123
|
-
promises.push(Promise.resolve(new C3DTBatchTable(BTBuffer, b3dmHeader.BTJSONLength, b3dmHeader.BTBinaryLength, FTJSON.BATCH_LENGTH, options.registeredExtensions)));
|
|
124
|
-
} else {
|
|
125
|
-
promises.push(Promise.resolve(new C3DTBatchTable()));
|
|
126
|
-
}
|
|
127
|
-
const posGltf = headerByteLength + b3dmHeader.FTJSONLength + b3dmHeader.FTBinaryLength + b3dmHeader.BTJSONLength + b3dmHeader.BTBinaryLength;
|
|
128
|
-
const gltfBuffer = buffer.slice(posGltf);
|
|
129
|
-
const init_mesh = function (mesh) {
|
|
130
|
-
mesh.frustumCulled = frustumCulled;
|
|
131
|
-
if (mesh.material) {
|
|
132
|
-
if (options.overrideMaterials) {
|
|
133
|
-
const oldMat = mesh.material;
|
|
134
|
-
// Set up new material
|
|
135
|
-
if (typeof options.overrideMaterials === 'object' && options.overrideMaterials.isMaterial) {
|
|
136
|
-
mesh.material = options.overrideMaterials;
|
|
137
|
-
} else {
|
|
138
|
-
mesh.material = new MeshBasicMaterial();
|
|
139
|
-
}
|
|
140
|
-
disposeThreeMaterial(oldMat);
|
|
141
|
-
} else if (Capabilities.isLogDepthBufferSupported() && mesh.material.isRawShaderMaterial && !options.doNotPatchMaterial) {
|
|
142
|
-
shaderUtils.patchMaterialForLogDepthSupport(mesh.material);
|
|
143
|
-
console.warn('glTF shader has been patched to add log depth buffer support');
|
|
144
|
-
}
|
|
145
|
-
ReferLayerProperties(mesh.material, options.layer);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
promises.push(itownsGLTFLoader.parseAsync(gltfBuffer, options).then(gltf => {
|
|
149
|
-
for (const scene of gltf.scenes) {
|
|
150
|
-
scene.traverse(filterUnsupportedSemantics);
|
|
151
|
-
}
|
|
152
|
-
transformToZUp(gltf.scene, options.gltfUpAxis);
|
|
153
|
-
const shouldBePatchedForLogDepthSupport = Capabilities.isLogDepthBufferSupported() && !options.doNotPatchMaterial;
|
|
154
|
-
if (options.frustumCulling === false || options.overrideMaterials || shouldBePatchedForLogDepthSupport || options.layer) {
|
|
155
|
-
gltf.scene.traverse(init_mesh);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Apply relative center from Feature table.
|
|
159
|
-
gltf.scene.position.copy(FT_RTC);
|
|
160
|
-
return gltf;
|
|
161
|
-
}).catch(e => {
|
|
162
|
-
throw new Error(e);
|
|
163
|
-
}));
|
|
164
|
-
return Promise.all(promises).then(values => ({
|
|
165
|
-
gltf: values[1],
|
|
166
|
-
batchTable: values[0]
|
|
167
|
-
})).catch(e => {
|
|
168
|
-
throw new Error(e);
|
|
169
|
-
});
|
|
170
|
-
} else {
|
|
171
|
-
throw new Error('Invalid b3dm file.');
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
};
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import OrientedImageCamera from "../Renderer/OrientedImageCamera.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The CameraCalibrationParser module provide a [parse]{@link module:CameraCalibrationParser.parse}
|
|
6
|
-
* method that takes a JSON array of camera calibrations in and yields an array of {@link OrientedImageCamera}
|
|
7
|
-
*
|
|
8
|
-
* @module CameraCalibrationParser
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const textureLoader = new THREE.TextureLoader();
|
|
12
|
-
const matrix3 = new THREE.Matrix3();
|
|
13
|
-
|
|
14
|
-
// the json format encodes the following transformation:
|
|
15
|
-
// extrinsics: p_local = rotation * (p_world - position)
|
|
16
|
-
// intrinsics: p_pixel = projection * p_local
|
|
17
|
-
// distortion: p_raw = distortion(p_pixel)
|
|
18
|
-
function parseCalibration(calibration) {
|
|
19
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
20
|
-
const useMask = options.useMask == undefined ? true : options.useMask;
|
|
21
|
-
const imageYDown = options.imageYDown == undefined ? true : options.imageYDown;
|
|
22
|
-
// parse intrinsics
|
|
23
|
-
const proj = calibration.projection;
|
|
24
|
-
const size = new THREE.Vector2().fromArray(calibration.size);
|
|
25
|
-
const focal = new THREE.Vector2(proj[0], proj[4]);
|
|
26
|
-
// Center of image, convention in digital image is Y dow
|
|
27
|
-
// To transform image space to webGl texture. It could inverse Y axis.
|
|
28
|
-
const center = new THREE.Vector2(proj[2], imageYDown ? size.y - proj[5] : proj[5]);
|
|
29
|
-
const skew = proj[1];
|
|
30
|
-
const camera = new OrientedImageCamera(size, focal, center, options.near, options.far, skew);
|
|
31
|
-
|
|
32
|
-
// parse extrinsics: Object3d.matrix is from local to world
|
|
33
|
-
// p_world = position + transpose(rotation) * p_local
|
|
34
|
-
camera.position.fromArray(calibration.position);
|
|
35
|
-
// calibration.rotation is row-major but fromArray expects a column-major array, yielding the transposed matrix
|
|
36
|
-
const rotationInverse = matrix3.fromArray(calibration.rotation);
|
|
37
|
-
camera.matrix.setFromMatrix3(rotationInverse);
|
|
38
|
-
camera.quaternion.setFromRotationMatrix(camera.matrix);
|
|
39
|
-
|
|
40
|
-
// local axes for cameras is (X right, Y up, Z back) rather than (X right, Y down, Z front)
|
|
41
|
-
camera.rotateX(Math.PI);
|
|
42
|
-
if (calibration.distortion) {
|
|
43
|
-
camera.distortion.setFromMicmacCalibration(calibration.distortion, imageYDown);
|
|
44
|
-
}
|
|
45
|
-
camera.maskPath = calibration.mask;
|
|
46
|
-
camera.name = calibration.id;
|
|
47
|
-
let resolve;
|
|
48
|
-
const deferred = new Promise(r => {
|
|
49
|
-
resolve = r;
|
|
50
|
-
});
|
|
51
|
-
if (useMask && camera.maskPath) {
|
|
52
|
-
textureLoader.load(camera.maskPath, mask => {
|
|
53
|
-
camera.maskTexture = mask;
|
|
54
|
-
resolve(camera);
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
resolve(camera);
|
|
58
|
-
}
|
|
59
|
-
return deferred;
|
|
60
|
-
}
|
|
61
|
-
export default {
|
|
62
|
-
/**
|
|
63
|
-
* Description of a camera calibration in a JSON file.
|
|
64
|
-
*
|
|
65
|
-
* @typedef CameraCalibrationJson
|
|
66
|
-
* @type {Object}
|
|
67
|
-
*
|
|
68
|
-
* @property {number[]} projection - projection matrix,
|
|
69
|
-
* @property {number[]} size - image size in pixel.
|
|
70
|
-
* @property {number[]} position - position of the camera.
|
|
71
|
-
* @property {number[]} rotation - rotation matrix
|
|
72
|
-
* @property {Object} [distorsion={}] - distorsion
|
|
73
|
-
* @property {number[]} [distorsion.pps]
|
|
74
|
-
* @property {number[]} [distorsion.poly357]
|
|
75
|
-
* @property {number[]} [distorsion.limit]
|
|
76
|
-
* @property {number[]} [distorsion.l1l2]
|
|
77
|
-
* @property {number[]} [distorsion.etat]
|
|
78
|
-
*/
|
|
79
|
-
/**
|
|
80
|
-
* Parser a JSON array of camera calibrations and return an array of {@link OrientedImageCamera}.
|
|
81
|
-
* @param {string|JSON} json - the json content of the calibration file.
|
|
82
|
-
* @param {Object} [options={}] - Options controlling the parsing.
|
|
83
|
-
* @param {string} [options.near=0.1] - Near of the created cameras. Default value comes from created {@link OrientedImageCamera}
|
|
84
|
-
* @param {string} [options.far=1000] - Far of the created cameras. Default value comes from created {@link OrientedImageCamera}
|
|
85
|
-
* @return {Promise} - A promise resolving with an array of {@link OrientedImageCamera}.
|
|
86
|
-
*/
|
|
87
|
-
parse(json) {
|
|
88
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
89
|
-
if (typeof json === 'string') {
|
|
90
|
-
json = JSON.parse(json);
|
|
91
|
-
}
|
|
92
|
-
return Promise.all(json.map(calibration => parseCalibration(calibration, options)));
|
|
93
|
-
}
|
|
94
|
-
};
|
package/lib/Parser/GDFParser.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import GeoidGrid from "../Core/Geographic/GeoidGrid.js";
|
|
3
|
-
import Extent from "../Core/Geographic/Extent.js";
|
|
4
|
-
import { BYTES_PER_DOUBLE } from "./GTXParser.js";
|
|
5
|
-
export function getHeaderAttribute(header, attributeName) {
|
|
6
|
-
const attributeRow = header[header.indexOf(header.find(element => element.includes(attributeName)))].split(' ').filter(value => value !== '');
|
|
7
|
-
return parseFloat(attributeRow[attributeRow.length - 1]);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The `GDFParser` module provides a `[parse]{@link module:GDFParser.parse}` method. This method takes the content of a
|
|
12
|
-
* GDF file in, and returns a `{@link GeoidGrid}`. the `{@link GeoidGrid}` contains all the necessary attributes and
|
|
13
|
-
* methods to access the GDF data in iTowns.
|
|
14
|
-
*
|
|
15
|
-
* @module GDFParser
|
|
16
|
-
*/
|
|
17
|
-
export default {
|
|
18
|
-
/**
|
|
19
|
-
* Parses a GDF file content and returns a corresponding {@link GeoidGrid}.
|
|
20
|
-
*
|
|
21
|
-
* @param {string} gdf The content of the GDF file to parse.
|
|
22
|
-
* @param {Object} options An object gathering the optional parameters to pass to
|
|
23
|
-
* the parser.
|
|
24
|
-
* @param {Object} [options.in={}] Information on the GDF data.
|
|
25
|
-
* @param {string} [options.in.crs='EPSG:4326'] The Coordinates Reference System (CRS) of the GDF data.
|
|
26
|
-
* It must be a geographic CRS, and must be given as an EPSG
|
|
27
|
-
* code.
|
|
28
|
-
*
|
|
29
|
-
* @returns {Promise<GeoidGrid>} A promise resolving with a {@link GeoidGrid}, which contains all the necessary
|
|
30
|
-
* attributes and methods to access GDF file data.
|
|
31
|
-
*/
|
|
32
|
-
parse(gdf) {
|
|
33
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
34
|
-
in: {}
|
|
35
|
-
};
|
|
36
|
-
const rows = gdf.split('\n');
|
|
37
|
-
const firstMeasureLine = rows.indexOf(rows.find(row => row.includes('end_of_head'))) + 1;
|
|
38
|
-
const rawHeaderData = rows.slice(0, firstMeasureLine);
|
|
39
|
-
|
|
40
|
-
// ---------- GET METADATA FROM THE FILE : ----------
|
|
41
|
-
|
|
42
|
-
const metadata = {
|
|
43
|
-
minX: getHeaderAttribute(rawHeaderData, 'longlimit_west'),
|
|
44
|
-
maxX: getHeaderAttribute(rawHeaderData, 'longlimit_east'),
|
|
45
|
-
minY: getHeaderAttribute(rawHeaderData, 'latlimit_south'),
|
|
46
|
-
maxY: getHeaderAttribute(rawHeaderData, 'latlimit_north'),
|
|
47
|
-
stepX: getHeaderAttribute(rawHeaderData, 'gridstep'),
|
|
48
|
-
stepY: getHeaderAttribute(rawHeaderData, 'gridstep'),
|
|
49
|
-
nRows: getHeaderAttribute(rawHeaderData, 'latitude_parallels'),
|
|
50
|
-
nColumns: getHeaderAttribute(rawHeaderData, 'longitude_parallels')
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// ---------- BUILD A DATA VIEWER FROM THE TEXT DATA : ----------
|
|
54
|
-
|
|
55
|
-
const data = new DataView(new ArrayBuffer(BYTES_PER_DOUBLE * metadata.nRows * metadata.nColumns));
|
|
56
|
-
let index = 0;
|
|
57
|
-
for (let row of rows.slice(firstMeasureLine, rows.length)) {
|
|
58
|
-
row = row.split(' ').filter(value => value !== '');
|
|
59
|
-
if (!row.length) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
data.setFloat64(index * BYTES_PER_DOUBLE, parseFloat(row[2]));
|
|
63
|
-
index++;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// ---------- CREATE A GeoidGrid FOR THE GIVEN FILE DATA : ----------
|
|
67
|
-
|
|
68
|
-
const dataExtent = new Extent(options.in.crs || 'EPSG:4326', metadata.minX, metadata.maxX, metadata.minY, metadata.maxY);
|
|
69
|
-
const dataStep = new THREE.Vector2(metadata.stepX, metadata.stepY);
|
|
70
|
-
return Promise.resolve(new GeoidGrid(dataExtent, dataStep, (verticalIndex, horizontalIndex) => data.getFloat64((metadata.nColumns * (metadata.nRows - verticalIndex - 1) + horizontalIndex) * BYTES_PER_DOUBLE)));
|
|
71
|
-
}
|
|
72
|
-
};
|
package/lib/Parser/GTXParser.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import GeoidGrid from "../Core/Geographic/GeoidGrid.js";
|
|
3
|
-
import Extent from "../Core/Geographic/Extent.js";
|
|
4
|
-
export const BYTES_PER_DOUBLE = 8;
|
|
5
|
-
export const BYTES_PER_FLOAT = 4;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The `GTXParser` module provides a `[parse]{@link module:GTXParser.parse}` method. This method takes the content of a
|
|
9
|
-
* GTX file in, and returns a {@link GeoidGrid}. The {@link GeoidGrid} contains all the necessary attributes and
|
|
10
|
-
* methods to access the GTX data in iTowns.
|
|
11
|
-
*
|
|
12
|
-
* @module GTXParser
|
|
13
|
-
*/
|
|
14
|
-
export default {
|
|
15
|
-
/**
|
|
16
|
-
* Parses a GTX file content and returns a corresponding {@link GeoidGrid}.
|
|
17
|
-
*
|
|
18
|
-
* @param {ArrayBuffer} gtx The content of the GTX file to parse.
|
|
19
|
-
* @param {Object} options An object gathering the optional parameters to pass to
|
|
20
|
-
* the parser.
|
|
21
|
-
* @param {Object} [options.in={}] Information on the GTX data.
|
|
22
|
-
* @param {string} [options.in.crs='EPSG:4326'] The Coordinates Reference System (CRS) of the GTX data.
|
|
23
|
-
* It must be a geographic CRS, and must be given as an
|
|
24
|
-
* EPSG code.
|
|
25
|
-
* @param {string} [options.in.dataType='float'] The encoding of geoid height data within the GTX file.
|
|
26
|
-
* Must be `'float'` or `'double'`.
|
|
27
|
-
*
|
|
28
|
-
* @returns {Promise<GeoidGrid>} A promise resolving with a {@link GeoidGrid}, which contains all the necessary
|
|
29
|
-
* attributes and methods to access GTX file data.
|
|
30
|
-
*/
|
|
31
|
-
parse(gtx) {
|
|
32
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
33
|
-
in: {}
|
|
34
|
-
};
|
|
35
|
-
const dataType = options.in.dataType || 'float';
|
|
36
|
-
if (!['float', 'double'].includes(dataType)) {
|
|
37
|
-
throw new Error('`dataType` parameter is incorrect for GTXParser.parse method. ' + 'This parameter must be either `double` or `float`.');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// ---------- GET METADATA FROM THE FILE : ----------
|
|
41
|
-
|
|
42
|
-
const headerView = new DataView(gtx, 0, 40);
|
|
43
|
-
const metadata = {
|
|
44
|
-
minX: headerView.getFloat64(8),
|
|
45
|
-
minY: headerView.getFloat64(0),
|
|
46
|
-
stepX: headerView.getFloat64(24),
|
|
47
|
-
stepY: headerView.getFloat64(16),
|
|
48
|
-
nColumns: headerView.getInt32(36),
|
|
49
|
-
nRows: headerView.getInt32(32)
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// ---------- BUILD A DATA VIEWER : ----------
|
|
53
|
-
|
|
54
|
-
const dataView = new DataView(gtx, 40);
|
|
55
|
-
|
|
56
|
-
// ---------- CREATE A GeoidGrid FOR THE GIVEN FILE DATA : ----------
|
|
57
|
-
|
|
58
|
-
// formula for the max longitude : maxLongitude = minLongitude + deltaLongitude * (nColumns - 1)
|
|
59
|
-
const maxX = metadata.minX + metadata.stepX * (metadata.nColumns - 1);
|
|
60
|
-
// formula for the max latitude : maxLatitude = minLatitude + deltaLatitude * (nRows - 1)
|
|
61
|
-
const maxY = metadata.minY + metadata.stepY * (metadata.nRows - 1);
|
|
62
|
-
const dataExtent = new Extent(options.in.crs || 'EPSG:4326', metadata.minX, maxX, metadata.minY, maxY);
|
|
63
|
-
const dataStep = new THREE.Vector2(metadata.stepX, metadata.stepY);
|
|
64
|
-
return Promise.resolve(new GeoidGrid(dataExtent, dataStep, (verticalIndex, horizontalIndex) => {
|
|
65
|
-
// formula to get the index of a geoid height from a latitude and longitude indexes is :
|
|
66
|
-
// ``(nColumns * latIndex + lonIndex) * nBytes``, where nBytes stands for the number of bytes geoid
|
|
67
|
-
// height data are encoded on.
|
|
68
|
-
if (dataType === 'float') {
|
|
69
|
-
return dataView.getFloat32((metadata.nColumns * verticalIndex + horizontalIndex) * BYTES_PER_FLOAT);
|
|
70
|
-
} else if (dataType === 'double') {
|
|
71
|
-
return dataView.getFloat64((metadata.nColumns * verticalIndex + horizontalIndex) * BYTES_PER_DOUBLE);
|
|
72
|
-
}
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
};
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import Coordinates from "../Core/Geographic/Coordinates.js";
|
|
2
|
-
import { FeatureCollection, FEATURE_TYPES } from "../Core/Feature.js";
|
|
3
|
-
import { deprecatedParsingOptionsToNewOne } from "../Core/Deprecated/Undeprecator.js";
|
|
4
|
-
function readCRS(json) {
|
|
5
|
-
if (json.crs) {
|
|
6
|
-
if (json.crs.type.toLowerCase() == 'epsg') {
|
|
7
|
-
return `EPSG:${json.crs.properties.code}`;
|
|
8
|
-
} else if (json.crs.type.toLowerCase() == 'name') {
|
|
9
|
-
if (json.crs.properties.name.toLowerCase().includes('epsg:')) {
|
|
10
|
-
// OGC CRS URN: urn:ogc:def:crs:authority:version:code => EPSG:[...]:code
|
|
11
|
-
// legacy identifier: authority:code => EPSG:code
|
|
12
|
-
const codeStart = json.crs.properties.name.lastIndexOf(':');
|
|
13
|
-
if (codeStart > 0) {
|
|
14
|
-
return `EPSG:${json.crs.properties.name.substr(codeStart + 1)}`;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
throw new Error(`Unsupported CRS authority '${json.crs.properties.name}'`);
|
|
18
|
-
}
|
|
19
|
-
throw new Error(`Unsupported CRS type '${json.crs}'`);
|
|
20
|
-
}
|
|
21
|
-
// assume default crs
|
|
22
|
-
return 'EPSG:4326';
|
|
23
|
-
}
|
|
24
|
-
const coord = new Coordinates('EPSG:4978', 0, 0, 0);
|
|
25
|
-
const last = new Coordinates('EPSG:4978', 0, 0, 0);
|
|
26
|
-
const first = new Coordinates('EPSG:4978', 0, 0, 0);
|
|
27
|
-
|
|
28
|
-
// filter with the first point
|
|
29
|
-
const firstPtIsOut = (extent, aCoords, crs) => {
|
|
30
|
-
coord.crs = crs;
|
|
31
|
-
coord.setFromArray(aCoords[0]);
|
|
32
|
-
return !extent.isPointInside(coord);
|
|
33
|
-
};
|
|
34
|
-
const toFeature = {
|
|
35
|
-
populateGeometry(crsIn, coordinates, geometry, feature) {
|
|
36
|
-
geometry.startSubGeometry(coordinates.length, feature);
|
|
37
|
-
coord.crs = crsIn;
|
|
38
|
-
// coordinates is a list of pair [[x1, y1], [x2, y2], ..., [xn, yn]]
|
|
39
|
-
// or list of triplet [[x1, y1, z1], [x2, y2, z2], ..., [xn, yn, zn]]
|
|
40
|
-
for (const triplet of coordinates) {
|
|
41
|
-
coord.setFromValues(triplet[0], triplet[1], triplet[2]);
|
|
42
|
-
geometry.pushCoordinates(feature, coord);
|
|
43
|
-
}
|
|
44
|
-
geometry.updateExtent();
|
|
45
|
-
},
|
|
46
|
-
// compute clockwise polygon
|
|
47
|
-
populateGeometryWithCCW(crsIn, coordinates, geometry, feature) {
|
|
48
|
-
geometry.startSubGeometry(coordinates.length, feature);
|
|
49
|
-
coord.crs = crsIn;
|
|
50
|
-
let sum = 0;
|
|
51
|
-
first.setFromValues(coordinates[0][0], coordinates[0][1], coordinates[0][2]);
|
|
52
|
-
last.copy(first);
|
|
53
|
-
for (let i = 0; i < coordinates.length; i++) {
|
|
54
|
-
coord.setFromValues(coordinates[i][0], coordinates[i][1], coordinates[i][2]);
|
|
55
|
-
sum += (last.x - coord.x) * (last.y + coord.y);
|
|
56
|
-
last.copy(coord);
|
|
57
|
-
geometry.pushCoordinates(feature, coord);
|
|
58
|
-
}
|
|
59
|
-
sum += (last.x - first.x) * (last.y + first.y);
|
|
60
|
-
geometry.getLastSubGeometry().ccw = sum < 0;
|
|
61
|
-
geometry.updateExtent();
|
|
62
|
-
},
|
|
63
|
-
point(feature, crsIn, coordsIn, collection, properties) {
|
|
64
|
-
this.default(feature, crsIn, [coordsIn], collection, properties);
|
|
65
|
-
},
|
|
66
|
-
default(feature, crsIn, coordsIn, collection, properties) {
|
|
67
|
-
if (collection.filterExtent && firstPtIsOut(collection.filterExtent, coordsIn, crsIn)) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const geometry = feature.bindNewGeometry();
|
|
71
|
-
geometry.properties = properties;
|
|
72
|
-
this.populateGeometry(crsIn, coordsIn, geometry, feature);
|
|
73
|
-
feature.updateExtent(geometry);
|
|
74
|
-
},
|
|
75
|
-
polygon(feature, crsIn, coordsIn, collection, properties) {
|
|
76
|
-
// filtering
|
|
77
|
-
if (collection.filterExtent && firstPtIsOut(collection.filterExtent, coordsIn[0], crsIn)) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const geometry = feature.bindNewGeometry();
|
|
81
|
-
geometry.properties = properties;
|
|
82
|
-
|
|
83
|
-
// Then read contour and holes
|
|
84
|
-
for (let i = 0; i < coordsIn.length; i++) {
|
|
85
|
-
this.populateGeometryWithCCW(crsIn, coordsIn[i], geometry, feature);
|
|
86
|
-
}
|
|
87
|
-
feature.updateExtent(geometry);
|
|
88
|
-
},
|
|
89
|
-
multi(type, feature, crsIn, coordsIn, collection, properties) {
|
|
90
|
-
for (const coords of coordsIn) {
|
|
91
|
-
this[type](feature, crsIn, coords, collection, properties);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
function coordinatesToFeature(type, feature, crsIn, coordinates, collection, properties) {
|
|
96
|
-
if (coordinates.length == 0) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
switch (type) {
|
|
100
|
-
case 'point':
|
|
101
|
-
case 'linestring':
|
|
102
|
-
return toFeature.default(feature, crsIn, coordinates, collection, properties);
|
|
103
|
-
case 'multipoint':
|
|
104
|
-
return toFeature.multi('point', feature, crsIn, coordinates, collection, properties);
|
|
105
|
-
case 'multilinestring':
|
|
106
|
-
return toFeature.multi('default', feature, crsIn, coordinates, collection, properties);
|
|
107
|
-
case 'polygon':
|
|
108
|
-
return toFeature.polygon(feature, crsIn, coordinates, collection, properties);
|
|
109
|
-
case 'multipolygon':
|
|
110
|
-
return toFeature.multi('polygon', feature, crsIn, coordinates, collection, properties);
|
|
111
|
-
case 'geometrycollection':
|
|
112
|
-
default:
|
|
113
|
-
throw new Error(`Unhandled geojson type ${feature.type}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function toFeatureType(jsonType) {
|
|
117
|
-
switch (jsonType) {
|
|
118
|
-
case 'point':
|
|
119
|
-
case 'multipoint':
|
|
120
|
-
return FEATURE_TYPES.POINT;
|
|
121
|
-
case 'linestring':
|
|
122
|
-
case 'multilinestring':
|
|
123
|
-
return FEATURE_TYPES.LINE;
|
|
124
|
-
case 'polygon':
|
|
125
|
-
case 'multipolygon':
|
|
126
|
-
return FEATURE_TYPES.POLYGON;
|
|
127
|
-
case 'geometrycollection':
|
|
128
|
-
default:
|
|
129
|
-
throw new Error(`Unhandled geometry type ${jsonType}`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
const keyProperties = ['type', 'geometry', 'properties'];
|
|
133
|
-
const firstCoordinates = a => a === undefined || Array.isArray(a) && !isNaN(a[0]) ? a : firstCoordinates(a[0]);
|
|
134
|
-
function jsonFeatureToFeature(crsIn, json, collection) {
|
|
135
|
-
if (!json.geometry?.type) {
|
|
136
|
-
console.warn('No geometry provided');
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
const jsonType = json.geometry.type.toLowerCase();
|
|
140
|
-
const featureType = toFeatureType(jsonType);
|
|
141
|
-
const feature = collection.requestFeatureByType(featureType);
|
|
142
|
-
const coordinates = jsonType != 'point' ? json.geometry.coordinates : [json.geometry.coordinates];
|
|
143
|
-
const properties = json.properties || {};
|
|
144
|
-
feature.hasRawElevationData = firstCoordinates(coordinates)?.length === 3;
|
|
145
|
-
|
|
146
|
-
// copy other properties
|
|
147
|
-
for (const key of Object.keys(json)) {
|
|
148
|
-
if (!keyProperties.includes(key.toLowerCase())) {
|
|
149
|
-
// create `geojson` key if it does not exist yet
|
|
150
|
-
properties.geojson = properties.geojson || {};
|
|
151
|
-
// add key defined property to `geojson` property
|
|
152
|
-
properties.geojson[key] = json[key];
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
coordinatesToFeature(jsonType, feature, crsIn, coordinates, collection, properties);
|
|
156
|
-
return feature;
|
|
157
|
-
}
|
|
158
|
-
function jsonFeaturesToFeatures(crsIn, jsonFeatures, options) {
|
|
159
|
-
const collection = new FeatureCollection(options);
|
|
160
|
-
const filter = options.filter || (() => true);
|
|
161
|
-
for (const jsonFeature of jsonFeatures) {
|
|
162
|
-
if (filter(jsonFeature.properties, jsonFeature.geometry)) {
|
|
163
|
-
jsonFeatureToFeature(crsIn, jsonFeature, collection);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
collection.removeEmptyFeature();
|
|
167
|
-
collection.updateExtent();
|
|
168
|
-
return collection;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* The GeoJsonParser module provide a [parse]{@link module:GeoJsonParser.parse}
|
|
173
|
-
* method that takes a GeoJSON in and gives an object formatted for iTowns
|
|
174
|
-
* containing all necessary informations to display this GeoJSON.
|
|
175
|
-
*
|
|
176
|
-
* @module GeoJsonParser
|
|
177
|
-
*/
|
|
178
|
-
export default {
|
|
179
|
-
/**
|
|
180
|
-
* Parse a GeoJSON file content and return a {@link FeatureCollection}.
|
|
181
|
-
*
|
|
182
|
-
* @param {string} json - The GeoJSON file content to parse.
|
|
183
|
-
* @param {ParsingOptions} options - Options controlling the parsing.
|
|
184
|
-
* @return {Promise} A promise resolving with a {@link FeatureCollection}.
|
|
185
|
-
*/
|
|
186
|
-
parse(json) {
|
|
187
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
188
|
-
options = deprecatedParsingOptionsToNewOne(options);
|
|
189
|
-
options.in = options.in || {};
|
|
190
|
-
const out = options.out;
|
|
191
|
-
const _in = options.in;
|
|
192
|
-
if (typeof json === 'string') {
|
|
193
|
-
json = JSON.parse(json);
|
|
194
|
-
}
|
|
195
|
-
_in.crs = _in.crs || readCRS(json);
|
|
196
|
-
if (out.filteringExtent) {
|
|
197
|
-
if (typeof out.filteringExtent == 'boolean') {
|
|
198
|
-
out.filterExtent = options.extent.isExtent ? options.extent.as(_in.crs) : options.extent.toExtent(_in.crs);
|
|
199
|
-
} else if (out.filteringExtent.isExtent) {
|
|
200
|
-
out.filterExtent = out.filteringExtent;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
switch (json.type.toLowerCase()) {
|
|
204
|
-
case 'featurecollection':
|
|
205
|
-
return Promise.resolve(jsonFeaturesToFeatures(_in.crs, json.features, out));
|
|
206
|
-
case 'feature':
|
|
207
|
-
return Promise.resolve(jsonFeaturesToFeatures(_in.crs, [json], out));
|
|
208
|
-
default:
|
|
209
|
-
throw new Error(`Unsupported GeoJSON type: '${json.type}`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
};
|
package/lib/Parser/GpxParser.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { gpx } from '@tmcw/togeojson';
|
|
2
|
-
import GeoJsonParser from "./GeoJsonParser.js";
|
|
3
|
-
import { deprecatedParsingOptionsToNewOne } from "../Core/Deprecated/Undeprecator.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The GpxParser module provides a [parse]{@link module:GpxParser.parse}
|
|
7
|
-
* method that takes a GPX in and gives an object formatted for iTowns
|
|
8
|
-
* containing all necessary informations to display this GPX.
|
|
9
|
-
*
|
|
10
|
-
* @module GpxParser
|
|
11
|
-
*/
|
|
12
|
-
export default {
|
|
13
|
-
/**
|
|
14
|
-
* Parse a GPX file content and return a {@link FeatureCollection}.
|
|
15
|
-
*
|
|
16
|
-
* @param {XMLDocument} gpxFile - The GPX file content to parse.
|
|
17
|
-
* @param {ParsingOptions} options - Options controlling the parsing.
|
|
18
|
-
*
|
|
19
|
-
* @return {Promise} A promise resolving with a {@link FeatureCollection}.
|
|
20
|
-
*/
|
|
21
|
-
parse(gpxFile, options) {
|
|
22
|
-
options = deprecatedParsingOptionsToNewOne(options);
|
|
23
|
-
return GeoJsonParser.parse(gpx(gpxFile), options);
|
|
24
|
-
}
|
|
25
|
-
};
|