itowns 2.45.1-next.0 → 2.45.1-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/dist/455.js +2 -0
  2. package/dist/455.js.map +1 -0
  3. package/dist/debug.js +3 -0
  4. package/dist/debug.js.LICENSE.txt +13 -0
  5. package/dist/debug.js.map +1 -0
  6. package/dist/itowns.js +3 -0
  7. package/dist/itowns.js.LICENSE.txt +5 -0
  8. package/dist/itowns.js.map +1 -0
  9. package/dist/itowns_lasparser.js +2 -0
  10. package/dist/itowns_lasparser.js.map +1 -0
  11. package/dist/itowns_lasworker.js +2 -0
  12. package/dist/itowns_lasworker.js.map +1 -0
  13. package/dist/itowns_potree2worker.js +2 -0
  14. package/dist/itowns_potree2worker.js.map +1 -0
  15. package/dist/itowns_widgets.js +2 -0
  16. package/dist/itowns_widgets.js.map +1 -0
  17. package/lib/Controls/FirstPersonControls.js +308 -0
  18. package/lib/Controls/FlyControls.js +175 -0
  19. package/lib/Controls/GlobeControls.js +1178 -0
  20. package/lib/Controls/PlanarControls.js +1025 -0
  21. package/lib/Controls/StateControl.js +432 -0
  22. package/lib/Controls/StreetControls.js +392 -0
  23. package/lib/Converter/Feature2Mesh.js +612 -0
  24. package/lib/Converter/Feature2Texture.js +174 -0
  25. package/lib/Converter/convertToTile.js +70 -0
  26. package/lib/Converter/textureConverter.js +43 -0
  27. package/lib/Core/3DTiles/C3DTBatchTable.js +131 -0
  28. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +96 -0
  29. package/lib/Core/3DTiles/C3DTBoundingVolume.js +156 -0
  30. package/lib/Core/3DTiles/C3DTExtensions.js +97 -0
  31. package/lib/Core/3DTiles/C3DTFeature.js +110 -0
  32. package/lib/Core/3DTiles/C3DTilesEnums.js +20 -0
  33. package/lib/Core/3DTiles/C3DTileset.js +99 -0
  34. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +100 -0
  35. package/lib/Core/AnimationPlayer.js +142 -0
  36. package/lib/Core/CopcNode.js +174 -0
  37. package/lib/Core/Deprecated/Undeprecator.js +74 -0
  38. package/lib/Core/EntwinePointTileNode.js +126 -0
  39. package/lib/Core/Feature.js +488 -0
  40. package/lib/Core/Geographic/GeoidGrid.js +108 -0
  41. package/lib/Core/Label.js +222 -0
  42. package/lib/Core/MainLoop.js +209 -0
  43. package/lib/Core/Picking.js +255 -0
  44. package/lib/Core/PointCloudNode.js +42 -0
  45. package/lib/Core/Potree2Node.js +206 -0
  46. package/lib/Core/Potree2PointAttributes.js +139 -0
  47. package/lib/Core/PotreeNode.js +101 -0
  48. package/lib/Core/Prefab/Globe/Atmosphere.js +293 -0
  49. package/lib/Core/Prefab/Globe/GlobeLayer.js +152 -0
  50. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +110 -0
  51. package/lib/Core/Prefab/Globe/SkyShader.js +78 -0
  52. package/lib/Core/Prefab/GlobeView.js +155 -0
  53. package/lib/Core/Prefab/Planar/PlanarLayer.js +59 -0
  54. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +71 -0
  55. package/lib/Core/Prefab/PlanarView.js +62 -0
  56. package/lib/Core/Prefab/TileBuilder.js +82 -0
  57. package/lib/Core/Prefab/computeBufferTileGeometry.js +248 -0
  58. package/lib/Core/Scheduler/Cache.js +17 -0
  59. package/lib/Core/Scheduler/CancelledCommandException.js +15 -0
  60. package/lib/Core/Scheduler/Scheduler.js +294 -0
  61. package/lib/Core/Style.js +660 -0
  62. package/lib/Core/StyleOptions.js +486 -0
  63. package/lib/Core/System/Capabilities.js +63 -0
  64. package/lib/Core/Tile/Tile.js +205 -0
  65. package/lib/Core/Tile/TileGrid.js +49 -0
  66. package/lib/Core/TileGeometry.js +124 -0
  67. package/lib/Core/TileMesh.js +108 -0
  68. package/lib/Core/View.js +1115 -0
  69. package/lib/Layer/C3DTilesLayer.js +459 -0
  70. package/lib/Layer/ColorLayer.js +154 -0
  71. package/lib/Layer/CopcLayer.js +63 -0
  72. package/lib/Layer/ElevationLayer.js +139 -0
  73. package/lib/Layer/EntwinePointTileLayer.js +71 -0
  74. package/lib/Layer/FeatureGeometryLayer.js +77 -0
  75. package/lib/Layer/GeoidLayer.js +80 -0
  76. package/lib/Layer/GeometryLayer.js +233 -0
  77. package/lib/Layer/InfoLayer.js +64 -0
  78. package/lib/Layer/LabelLayer.js +469 -0
  79. package/lib/Layer/Layer.js +335 -0
  80. package/lib/Layer/LayerUpdateState.js +89 -0
  81. package/lib/Layer/LayerUpdateStrategy.js +80 -0
  82. package/lib/Layer/OGC3DTilesLayer.js +543 -0
  83. package/lib/Layer/OrientedImageLayer.js +227 -0
  84. package/lib/Layer/PointCloudLayer.js +405 -0
  85. package/lib/Layer/Potree2Layer.js +171 -0
  86. package/lib/Layer/PotreeLayer.js +72 -0
  87. package/lib/Layer/RasterLayer.js +37 -0
  88. package/lib/Layer/ReferencingLayerProperties.js +62 -0
  89. package/lib/Layer/TiledGeometryLayer.js +459 -0
  90. package/lib/Loader/LASLoader.js +193 -0
  91. package/lib/Loader/Potree2BrotliLoader.js +261 -0
  92. package/lib/Loader/Potree2Loader.js +207 -0
  93. package/lib/Main.js +113 -0
  94. package/lib/MainBundle.js +4 -0
  95. package/lib/Parser/B3dmParser.js +174 -0
  96. package/lib/Parser/CameraCalibrationParser.js +94 -0
  97. package/lib/Parser/GDFParser.js +72 -0
  98. package/lib/Parser/GTXParser.js +75 -0
  99. package/lib/Parser/GeoJsonParser.js +212 -0
  100. package/lib/Parser/GpxParser.js +25 -0
  101. package/lib/Parser/ISGParser.js +71 -0
  102. package/lib/Parser/KMLParser.js +25 -0
  103. package/lib/Parser/LASParser.js +137 -0
  104. package/lib/Parser/MapBoxUrlParser.js +83 -0
  105. package/lib/Parser/PntsParser.js +131 -0
  106. package/lib/Parser/Potree2BinParser.js +92 -0
  107. package/lib/Parser/PotreeBinParser.js +106 -0
  108. package/lib/Parser/PotreeCinParser.js +29 -0
  109. package/lib/Parser/ShapefileParser.js +78 -0
  110. package/lib/Parser/VectorTileParser.js +215 -0
  111. package/lib/Parser/XbilParser.js +120 -0
  112. package/lib/Parser/deprecated/LegacyGLTFLoader.js +1386 -0
  113. package/lib/Parser/iGLTFLoader.js +168 -0
  114. package/lib/Process/3dTilesProcessing.js +304 -0
  115. package/lib/Process/FeatureProcessing.js +76 -0
  116. package/lib/Process/LayeredMaterialNodeProcessing.js +229 -0
  117. package/lib/Process/ObjectRemovalHelper.js +97 -0
  118. package/lib/Process/handlerNodeError.js +23 -0
  119. package/lib/Provider/3dTilesProvider.js +149 -0
  120. package/lib/Provider/DataSourceProvider.js +24 -0
  121. package/lib/Provider/Fetcher.js +233 -0
  122. package/lib/Provider/PointCloudProvider.js +45 -0
  123. package/lib/Provider/TileProvider.js +16 -0
  124. package/lib/Provider/URLBuilder.js +116 -0
  125. package/lib/Renderer/Camera.js +281 -0
  126. package/lib/Renderer/Color.js +56 -0
  127. package/lib/Renderer/ColorLayersOrdering.js +115 -0
  128. package/lib/Renderer/CommonMaterial.js +31 -0
  129. package/lib/Renderer/Label2DRenderer.js +192 -0
  130. package/lib/Renderer/LayeredMaterial.js +243 -0
  131. package/lib/Renderer/OBB.js +150 -0
  132. package/lib/Renderer/OrientedImageCamera.js +118 -0
  133. package/lib/Renderer/OrientedImageMaterial.js +167 -0
  134. package/lib/Renderer/PointsMaterial.js +485 -0
  135. package/lib/Renderer/RasterTile.js +243 -0
  136. package/lib/Renderer/RenderMode.js +31 -0
  137. package/lib/Renderer/Shader/ShaderChunk.js +160 -0
  138. package/lib/Renderer/Shader/ShaderUtils.js +47 -0
  139. package/lib/Renderer/SphereHelper.js +17 -0
  140. package/lib/Renderer/WebXR.js +51 -0
  141. package/lib/Renderer/c3DEngine.js +214 -0
  142. package/lib/Source/C3DTilesGoogleSource.js +74 -0
  143. package/lib/Source/C3DTilesIonSource.js +54 -0
  144. package/lib/Source/C3DTilesSource.js +30 -0
  145. package/lib/Source/CopcSource.js +126 -0
  146. package/lib/Source/EntwinePointTileSource.js +72 -0
  147. package/lib/Source/FileSource.js +188 -0
  148. package/lib/Source/OGC3DTilesGoogleSource.js +29 -0
  149. package/lib/Source/OGC3DTilesIonSource.js +34 -0
  150. package/lib/Source/OGC3DTilesSource.js +21 -0
  151. package/lib/Source/OrientedImageSource.js +59 -0
  152. package/lib/Source/Potree2Source.js +167 -0
  153. package/lib/Source/PotreeSource.js +82 -0
  154. package/lib/Source/Source.js +202 -0
  155. package/lib/Source/TMSSource.js +144 -0
  156. package/lib/Source/VectorTilesSource.js +182 -0
  157. package/lib/Source/WFSSource.js +170 -0
  158. package/lib/Source/WMSSource.js +167 -0
  159. package/lib/Source/WMTSSource.js +92 -0
  160. package/lib/ThreeExtended/capabilities/WebGL.js +69 -0
  161. package/lib/ThreeExtended/libs/ktx-parse.module.js +506 -0
  162. package/lib/ThreeExtended/libs/zstddec.module.js +29 -0
  163. package/lib/ThreeExtended/loaders/DDSLoader.js +200 -0
  164. package/lib/ThreeExtended/loaders/DRACOLoader.js +400 -0
  165. package/lib/ThreeExtended/loaders/GLTFLoader.js +2879 -0
  166. package/lib/ThreeExtended/loaders/KTX2Loader.js +709 -0
  167. package/lib/ThreeExtended/math/ColorSpaces.js +59 -0
  168. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +846 -0
  169. package/lib/ThreeExtended/utils/WorkerPool.js +70 -0
  170. package/lib/Utils/CameraUtils.js +554 -0
  171. package/lib/Utils/DEMUtils.js +350 -0
  172. package/lib/Utils/FeaturesUtils.js +156 -0
  173. package/lib/Utils/Gradients.js +16 -0
  174. package/lib/Utils/ThreeUtils.js +115 -0
  175. package/lib/Utils/gui/C3DTilesStyle.js +218 -0
  176. package/lib/Utils/gui/Main.js +7 -0
  177. package/lib/Utils/gui/Minimap.js +152 -0
  178. package/lib/Utils/gui/Navigation.js +245 -0
  179. package/lib/Utils/gui/Scale.js +104 -0
  180. package/lib/Utils/gui/Searchbar.js +234 -0
  181. package/lib/Utils/gui/Widget.js +80 -0
  182. package/lib/Utils/placeObjectOnGround.js +136 -0
  183. package/lib/Worker/LASLoaderWorker.js +19 -0
  184. package/lib/Worker/Potree2Worker.js +21 -0
  185. package/package.json +2 -2
@@ -0,0 +1,78 @@
1
+ import proj4 from 'proj4';
2
+ import shp from 'shpjs';
3
+ import GeoJsonParser from "./GeoJsonParser.js";
4
+ import { deprecatedParsingOptionsToNewOne } from "../Core/Deprecated/Undeprecator.js";
5
+
6
+ /**
7
+ * The ShapefileParser module provides a [parse]{@link
8
+ * module:ShapefileParser.parse} method that takes a bunch of files constituing
9
+ * a shapefile in and gives an object formateted for iTowns, containing all
10
+ * necessary informations to display this shapefile.
11
+ *
12
+ * It uses the [shpjs](https://www.npmjs.com/package/shpjs) library to
13
+ * parse all the files.
14
+ *
15
+ * @example
16
+ * // Load all the necessary files for a shapefile, parse them and
17
+ * // display them using a FileSource.
18
+ * Promise.all([
19
+ * Fetcher.arrayBuffer('shapefile.shp'),
20
+ * Fetcher.arrayBuffer('shapefile.dbf'),
21
+ * Fetcher.arrayBuffer('shapefile.shx'),
22
+ * Fetcher.text('shapefile.prj'),
23
+ * ]).then(function _(res) {
24
+ * return ShapefileParser.parse({
25
+ * shp: res[0],
26
+ * dbf: res[1],
27
+ * shx: res[2],
28
+ * prj: res[3],
29
+ * }, {
30
+ * in: {
31
+ * crs: 'EPSG:4326',
32
+ * },
33
+ * out: {
34
+ * crs: view.tileLayer.extent.crs,
35
+ * }
36
+ * });
37
+ * }).then(function _(geojson) {
38
+ * var source = new FileSource({ features: geojson });
39
+ * var layer = new ColorLayer('velib', { source });
40
+ * view.addLayer(layer);
41
+ * });
42
+ *
43
+ *
44
+ * @module ShapefileParser
45
+ */
46
+ export default {
47
+ /**
48
+ * Parse a bunch of Shapefile files and return a {@link FeatureCollection}.
49
+ *
50
+ * @param {Object} data - All the data that can be specified in a shapefile.
51
+ * @param {ArrayBuffer} data.shp - Data from the shapefile itself,
52
+ * containing the feature geometry itself.
53
+ * @param {ArrayBuffer} data.shx - A positional index of the feature
54
+ * geometry.
55
+ * @param {ArrayBuffer} data.dbf - Columnar attributes for each shape, in
56
+ * [dBase](https://en.wikipedia.org/wiki/DBase) IV format.
57
+ * @param {string} [data.prj] - The coordinate system and crs projection
58
+ * information.
59
+ * @param {ParsingOptions} [options]
60
+ *
61
+ * @return {Promise} A promise resolving with a {@link FeatureCollection}.
62
+ */
63
+ parse(data) {
64
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
65
+ options = deprecatedParsingOptionsToNewOne(options);
66
+ let result;
67
+
68
+ // If a zip is present, don't read anything else
69
+ if (data.zip) {
70
+ result = shp(data.zip);
71
+ } else if (data.shp && data.shx && data.dbf) {
72
+ result = shp(data);
73
+ }
74
+ options.in = options.in || {};
75
+ options.in.crs = data.prj ? proj4(data.prj).oProj.datumName : options.in.crs;
76
+ return Promise.resolve(result).then(res => GeoJsonParser.parse(res, options));
77
+ }
78
+ };
@@ -0,0 +1,215 @@
1
+ import { Vector2, Vector3 } from 'three';
2
+ import Protobuf from 'pbf';
3
+ import { VectorTile } from '@mapbox/vector-tile';
4
+ import { FeatureCollection, FEATURE_TYPES } from "../Core/Feature.js";
5
+ import { globalExtentTMS } from "../Core/Tile/TileGrid.js";
6
+ import { deprecatedParsingOptionsToNewOne } from "../Core/Deprecated/Undeprecator.js";
7
+ import { Coordinates } from '@itowns/geographic';
8
+ const worldDimension3857 = globalExtentTMS.get('EPSG:3857').planarDimensions();
9
+ const globalExtent = new Vector3(worldDimension3857.x, worldDimension3857.y, 1);
10
+ const lastPoint = new Vector2();
11
+ const firstPoint = new Vector2();
12
+
13
+ // Calculate the projected coordinates in EPSG:4326 of a given point in the VT local system
14
+ // adapted from @mapbox/vector-tile
15
+ function project(x, y, tileNumbers, tileExtent) {
16
+ const size = tileExtent * 2 ** tileNumbers.z;
17
+ const x0 = tileExtent * tileNumbers.x;
18
+ const y0 = tileExtent * tileNumbers.y;
19
+ return new Coordinates('EPSG:4326', (x + x0) * 360 / size - 180, 360 / Math.PI * Math.atan(Math.exp((180 - (y + y0) * 360 / size) * Math.PI / 180)) - 90);
20
+ }
21
+
22
+ // Classify option, it allows to classify a full polygon and its holes.
23
+ // Each polygon with its holes are in one FeatureGeometry.
24
+ // A polygon is determined by its clockwise direction and the holes are in the opposite direction.
25
+ // Clockwise direction is determined by Shoelace formula https://en.wikipedia.org/wiki/Shoelace_formula
26
+ // Draw polygon with canvas doesn't need to classify however it is necessary for meshs.
27
+ function vtFeatureToFeatureGeometry(vtFeature, feature) {
28
+ let classify = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
29
+ let geometry = feature.bindNewGeometry();
30
+ const isPolygon = feature.type === FEATURE_TYPES.POLYGON;
31
+ classify = classify && isPolygon;
32
+ geometry.properties = vtFeature.properties;
33
+ const pbf = vtFeature._pbf;
34
+ pbf.pos = vtFeature._geometry;
35
+ const end = pbf.readVarint() + pbf.pos;
36
+ let cmd = 1;
37
+ let length = 0;
38
+ let x = 0;
39
+ let y = 0;
40
+ let count = 0;
41
+ let sum = 0;
42
+ while (pbf.pos < end) {
43
+ if (length <= 0) {
44
+ const cmdLen = pbf.readVarint();
45
+ cmd = cmdLen & 0x7;
46
+ length = cmdLen >> 3;
47
+ }
48
+ length--;
49
+ if (cmd === 1 || cmd === 2) {
50
+ x += pbf.readSVarint();
51
+ y += pbf.readSVarint();
52
+ if (cmd === 1) {
53
+ if (count) {
54
+ if (classify && sum > 0 && geometry.indices.length > 0) {
55
+ feature.updateExtent(geometry);
56
+ geometry = feature.bindNewGeometry();
57
+ geometry.properties = vtFeature.properties;
58
+ }
59
+ geometry.closeSubGeometry(count, feature);
60
+ geometry.getLastSubGeometry().ccw = sum < 0;
61
+ }
62
+ count = 0;
63
+ sum = 0;
64
+ }
65
+ count++;
66
+ const coordProj = project(x, y, vtFeature.tileNumbers, vtFeature.extent);
67
+ geometry.pushCoordinatesValues(feature, {
68
+ x,
69
+ y
70
+ }, coordProj);
71
+ if (count == 1) {
72
+ firstPoint.set(x, y);
73
+ firstPoint.coordProj = coordProj;
74
+ lastPoint.set(x, y);
75
+ } else if (isPolygon && count > 1) {
76
+ sum += (lastPoint.x - x) * (lastPoint.y + y);
77
+ lastPoint.set(x, y);
78
+ }
79
+ } else if (cmd === 7) {
80
+ if (count) {
81
+ count++;
82
+ geometry.pushCoordinatesValues(feature, {
83
+ x: firstPoint.x,
84
+ y: firstPoint.y
85
+ }, firstPoint.coordProj);
86
+ if (isPolygon) {
87
+ sum += (lastPoint.x - firstPoint.x) * (lastPoint.y + firstPoint.y);
88
+ }
89
+ }
90
+ } else {
91
+ throw new Error(`unknown command ${cmd}`);
92
+ }
93
+ }
94
+ if (count) {
95
+ if (classify && sum > 0 && geometry.indices.length > 0) {
96
+ feature.updateExtent(geometry);
97
+ geometry = feature.bindNewGeometry();
98
+ geometry.properties = vtFeature.properties;
99
+ }
100
+ geometry.closeSubGeometry(count, feature);
101
+ geometry.getLastSubGeometry().ccw = sum < 0;
102
+ }
103
+ feature.updateExtent(geometry);
104
+ }
105
+ function readPBF(file, options) {
106
+ options.out = options.out || {};
107
+ const vectorTile = new VectorTile(new Protobuf(file));
108
+ const vtLayerNames = Object.keys(vectorTile.layers);
109
+ const collection = new FeatureCollection(options.out);
110
+ if (vtLayerNames.length < 1) {
111
+ return Promise.resolve(collection);
112
+ }
113
+
114
+ // x,y,z tile coordinates
115
+ const x = options.extent.col;
116
+ const z = options.extent.zoom;
117
+ // We need to move from TMS to Google/Bing/OSM coordinates
118
+ // https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/
119
+ // Only if the layer.origin is top
120
+ const y = options.in.isInverted ? options.extent.row : (1 << z) - options.extent.row - 1;
121
+ const vFeature0 = vectorTile.layers[vtLayerNames[0]];
122
+ // TODO: verify if size is correct because is computed with only one feature (vFeature0).
123
+ const size = vFeature0.extent * 2 ** z;
124
+ const center = -0.5 * size;
125
+ collection.scale.set(globalExtent.x / size, -globalExtent.y / size, 1);
126
+ collection.position.set(vFeature0.extent * x + center, vFeature0.extent * y + center, 0).multiply(collection.scale);
127
+ collection.updateMatrixWorld();
128
+ vtLayerNames.forEach(vtLayerName => {
129
+ if (!options.in.layers[vtLayerName]) {
130
+ return Promise.resolve(collection);
131
+ }
132
+ const vectorTileLayer = vectorTile.layers[vtLayerName];
133
+ for (let i = vectorTileLayer.length - 1; i >= 0; i--) {
134
+ const vtFeature = vectorTileLayer.feature(i);
135
+ vtFeature.tileNumbers = {
136
+ x,
137
+ y: options.extent.row,
138
+ z
139
+ };
140
+ // Find layers where this vtFeature is used
141
+ const layers = options.in.layers[vtLayerName].filter(l => l.filterExpression.filter({
142
+ zoom: z
143
+ }, vtFeature));
144
+ for (const layer of layers) {
145
+ const feature = collection.requestFeatureById(layer.id, vtFeature.type - 1);
146
+ feature.id = layer.id;
147
+ feature.order = layer.order;
148
+ feature.style = options.in.styles[feature.id];
149
+ vtFeatureToFeatureGeometry(vtFeature, feature);
150
+ }
151
+
152
+ /*
153
+ // This optimization is not fully working and need to be reassessed
154
+ // (see https://github.com/iTowns/itowns/pull/2469/files#r1861802136)
155
+ let feature;
156
+ for (const layer of layers) {
157
+ if (!feature) {
158
+ feature = collection.requestFeatureById(layer.id, vtFeature.type - 1);
159
+ feature.id = layer.id;
160
+ feature.order = layer.order;
161
+ feature.style = options.in.styles[feature.id];
162
+ vtFeatureToFeatureGeometry(vtFeature, feature);
163
+ } else if (!collection.features.find(f => f.id === layer.id)) {
164
+ feature = collection.newFeatureByReference(feature);
165
+ feature.id = layer.id;
166
+ feature.order = layer.order;
167
+ feature.style = options.in.styles[feature.id];
168
+ }
169
+ }
170
+ */
171
+ }
172
+ });
173
+ collection.removeEmptyFeature();
174
+ // TODO Some vector tiles are already sorted
175
+ collection.features.sort((a, b) => a.order - b.order);
176
+ // TODO verify if is needed to updateExtent for previous features.
177
+ collection.updateExtent();
178
+ collection.extent = options.extent;
179
+ collection.isInverted = options.in.isInverted;
180
+ return Promise.resolve(collection);
181
+ }
182
+
183
+ /**
184
+ * @module VectorTileParser
185
+ */
186
+ export default {
187
+ /**
188
+ * Parse a vector tile file and return a [Feature]{@link module:GeoJsonParser.Feature}
189
+ * or an array of Features. While multiple formats of vector tile are
190
+ * available, the only one supported for the moment is the
191
+ * [Mapbox Vector Tile](https://www.mapbox.com/vector-tiles/specification/).
192
+ *
193
+ * @param {ArrayBuffer} file - The vector tile file to parse.
194
+ *
195
+ * @param {Object} options - Options controlling the parsing {@link ParsingOptions}.
196
+ *
197
+ * @param {Object} options.in - Object containing all styles,
198
+ * layers and informations data, see {@link InformationsData}.
199
+ *
200
+ * @param {Object} options.in.styles - Object containing subobject with
201
+ * informations on a specific style layer. Styles available is by `layer.id` and by zoom.
202
+ *
203
+ * @param {Object} options.in.layers - Object containing subobject with
204
+ *
205
+ * @param {FeatureBuildingOptions} options.out - options indicates how the features should be built,
206
+ * see {@link FeatureBuildingOptions}.
207
+ *
208
+ * @return {Promise} A Promise resolving with a Feature or an array a
209
+ * Features.
210
+ */
211
+ parse(file, options) {
212
+ options = deprecatedParsingOptionsToNewOne(options);
213
+ return Promise.resolve(readPBF(file, options));
214
+ }
215
+ };
@@ -0,0 +1,120 @@
1
+ import { readTextureValueWithBilinearFiltering } from "../Utils/DEMUtils.js";
2
+ function minMax4Corners(texture, pitch, options) {
3
+ const u = pitch.x;
4
+ const v = pitch.y;
5
+ const w = pitch.z;
6
+ const z = [readTextureValueWithBilinearFiltering(options, texture, u, v), readTextureValueWithBilinearFiltering(options, texture, u + w, v), readTextureValueWithBilinearFiltering(options, texture, u + w, v + w), readTextureValueWithBilinearFiltering(options, texture, u, v + w)].filter(val => val != undefined);
7
+ if (z.length) {
8
+ return {
9
+ min: Math.min(...z),
10
+ max: Math.max(...z)
11
+ };
12
+ } else {
13
+ return {
14
+ min: Infinity,
15
+ max: -Infinity
16
+ };
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Calculates the minimum maximum texture elevation with xbil data
22
+ *
23
+ * @param {THREE.Texture} texture The texture to parse
24
+ * @param {THREE.Vector4} pitch The pitch, restrict zone to parse
25
+ * @param {Object} options No data value and clamp values
26
+ * @param {number} options.noDataValue No data value
27
+ * @param {number} [options.zmin] The minimum elevation value after which it will be clamped
28
+ * @param {number} [options.zmax] The maximum elevation value after which it will be clamped
29
+ * @return {Object} The minimum and maximum elevation.
30
+ */
31
+ export function computeMinMaxElevation(texture, pitch, options) {
32
+ const {
33
+ width,
34
+ height,
35
+ data
36
+ } = texture.image;
37
+ if (!data) {
38
+ // Return null values means there's no elevation values.
39
+ // They can't be determined.
40
+ // Don't return 0 because the result will be wrong
41
+ return {
42
+ min: null,
43
+ max: null
44
+ };
45
+ }
46
+
47
+ // compute the minimum and maximum elevation on the 4 corners texture.
48
+ let {
49
+ min,
50
+ max
51
+ } = minMax4Corners(texture, pitch, options);
52
+ const sizeX = Math.floor(pitch.z * width);
53
+ if (sizeX > 2) {
54
+ const sizeY = Math.floor(pitch.z * height);
55
+ const xs = Math.floor(pitch.x * width);
56
+ const ys = Math.floor(pitch.y * height);
57
+ const inc = Math.max(Math.floor(sizeX / 32), 2);
58
+ for (let y = ys; y < ys + sizeY; y += inc) {
59
+ const pit = y * (width || 0);
60
+ let x = pit + xs;
61
+ const limX = x + sizeX;
62
+ for (x; x < limX; x += inc) {
63
+ const val = data[x];
64
+ if (val !== options.noDataValue) {
65
+ max = Math.max(max, val);
66
+ min = Math.min(min, val);
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+ // Clamp values to zmin and zmax values configured in ElevationLayer
73
+ if (options.zmin != null) {
74
+ if (min < options.zmin) {
75
+ min = options.zmin;
76
+ }
77
+ if (max < options.zmin) {
78
+ max = options.zmin;
79
+ }
80
+ }
81
+ if (options.zmax != null) {
82
+ if (min > options.zmax) {
83
+ min = options.zmax;
84
+ }
85
+ if (max > options.zmax) {
86
+ max = options.zmax;
87
+ }
88
+ }
89
+ if (max === -Infinity || min === Infinity) {
90
+ // Return null values means the elevation values are incoherent
91
+ // They can't be determined.
92
+ // Don't return 0, -Infinity or Infinity because the result will be wrong
93
+ return {
94
+ min: null,
95
+ max: null
96
+ };
97
+ } else {
98
+ return {
99
+ min,
100
+ max
101
+ };
102
+ }
103
+ }
104
+
105
+ // We check if the elevation texture has some significant values through corners
106
+ export function checkNodeElevationTextureValidity(data, noDataValue) {
107
+ const l = data.length;
108
+ return data[0] > noDataValue && data[l - 1] > noDataValue && data[Math.sqrt(l) - 1] > noDataValue && data[l - Math.sqrt(l)] > noDataValue;
109
+ }
110
+
111
+ // This function replaces noDataValue by significant values from parent texture (or 0)
112
+ export function insertSignificantValuesFromParent(data) {
113
+ let dataParent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => 0;
114
+ let noDataValue = arguments.length > 2 ? arguments[2] : undefined;
115
+ for (let i = 0, l = data.length; i < l; ++i) {
116
+ if (data[i] === noDataValue) {
117
+ data[i] = dataParent(i);
118
+ }
119
+ }
120
+ }