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,104 @@
1
+ import { CONTROL_EVENTS, GLOBE_VIEW_EVENTS, PLANAR_CONTROL_EVENT, VIEW_EVENTS } from 'itowns';
2
+ import Widget from "./Widget.js";
3
+ const DEFAULT_OPTIONS = {
4
+ width: 200,
5
+ height: 30,
6
+ position: 'bottom-left'
7
+ };
8
+
9
+ /**
10
+ * A widget for scale
11
+ *
12
+ * To use it, you need to link the widgets' stylesheet to your html webpage. This stylesheet is included in
13
+ * [itowns bundles](https://github.com/iTowns/itowns/releases) if you downloaded them, or it can be found in
14
+ * `node_modules/itowns/examples/css` if you installed iTowns with npm. Otherwise, it can be found at
15
+ * [this link](https://raw.githubusercontent.com/iTowns/itowns/master/examples/css/widgets.css). See
16
+ * [this example](http://www.itowns-project.org/itowns/examples/#widgets_scale) for more details.
17
+ *
18
+ * @extends Widget
19
+ *
20
+ * @property {HTMLElement} domElement An html div containing the scale.
21
+ * @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
22
+ */
23
+ class Scale extends Widget {
24
+ /**
25
+ * @param {View} view The iTowns view the scale should be
26
+ * linked to. If it is a
27
+ * {@link PlanarView} or a
28
+ * {@link GlobeView}, the scale will be
29
+ * automatically updated. Otherwise, user
30
+ * will need to implement the update
31
+ * automation using the `Scale.update`
32
+ * method.
33
+ * @param {Object} [options] The scale optional configuration.
34
+ * @param {HTMLElement} [options.parentElement=view.domElement] The parent HTML container of the div
35
+ * which contains scale widgets.
36
+ * @param {number} [options.width=200] The width in pixels of the scale.
37
+ * @param {number} [options.height=30] The height in pixels of the scale.
38
+ * @param {string} [options.position='bottom-left'] Defines which position within the
39
+ * `parentElement` the scale should be
40
+ * displayed to. Possible values are
41
+ * `top`, `bottom`, `left`, `right`,
42
+ * `top-left`, `top-right`, `bottom-left`
43
+ * and `bottom-right`. If the input value
44
+ * does not match one of these, it will
45
+ * be defaulted to `bottom-left`.
46
+ * @param {Object} [options.translate] An optional translation of the scale.
47
+ * @param {number} [options.translate.x=0] The scale translation along the page
48
+ * x-axis.
49
+ * @param {number} [options.translate.y=0] The scale translation along the page
50
+ * y-axis.
51
+ */
52
+ constructor(view) {
53
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
54
+ // ---------- BUILD PROPERTIES ACCORDING TO DEFAULT OPTIONS AND OPTIONS PASSED IN PARAMETERS : ----------
55
+
56
+ super(view, options, DEFAULT_OPTIONS);
57
+
58
+ // ---------- this.domElement SETTINGS SPECIFIC TO SCALE : ----------
59
+
60
+ this.domElement.id = 'widgets-scale';
61
+ this.view = view;
62
+
63
+ // Initialize the text content of the scale, which will later be updated by a numerical value.
64
+ this.domElement.innerHTML = 'Scale';
65
+ this.width = options.width || DEFAULT_OPTIONS.width;
66
+ if (this.view.isGlobeView) {
67
+ this.view.addEventListener(GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, () => {
68
+ this.update();
69
+ });
70
+ this.view.controls.addEventListener(CONTROL_EVENTS.RANGE_CHANGED, () => {
71
+ this.update();
72
+ });
73
+ } else if (this.view.isPlanarView) {
74
+ this.view.addEventListener(VIEW_EVENTS.INITIALIZED, () => {
75
+ this.update();
76
+ });
77
+ this.view.addEventListener(PLANAR_CONTROL_EVENT.MOVED, () => {
78
+ this.update();
79
+ });
80
+ } else {
81
+ console.warn('The \'view\' linked to scale widget is neither a \'GlobeView\' nor a \'PlanarView\'. The ' + 'scale wont automatically update. You can implement its update automation using \'Scale.update\' ' + 'method.');
82
+ }
83
+ }
84
+ addEventListeners() {}
85
+
86
+ /**
87
+ * Update the scale size and content according to view camera position.
88
+ */
89
+ update() {
90
+ // Calculate the rounded metric distance which matches the scale width in pixels.
91
+ let metricDistance = Math.round(this.view.getPixelsToMeters(this.width));
92
+ const digit = 10 ** (metricDistance.toString().length - 1);
93
+ metricDistance = Math.round(metricDistance / digit) * digit;
94
+ const pixelDistance = this.view.getMetersToPixels(metricDistance);
95
+ let unit = 'm';
96
+ if (metricDistance >= 1000) {
97
+ metricDistance /= 1000;
98
+ unit = 'km';
99
+ }
100
+ this.domElement.innerHTML = `${metricDistance} ${unit}`;
101
+ this.domElement.style.width = `${pixelDistance}px`;
102
+ }
103
+ }
104
+ export default Scale;
@@ -0,0 +1,234 @@
1
+ import { Fetcher } from 'itowns';
2
+ import Widget from "./Widget.js";
3
+ const DEFAULT_OPTIONS = {
4
+ width: 300,
5
+ height: 38,
6
+ position: 'top',
7
+ maxSuggestionNumber: 10,
8
+ fontSize: 16,
9
+ placeholder: 'Search location'
10
+ };
11
+ function addActive(htmlElements, index) {
12
+ if (!htmlElements) {
13
+ return index;
14
+ }
15
+ removeAllActives(htmlElements);
16
+ if (index >= htmlElements.length) {
17
+ index = 0;
18
+ } else if (index < 0) {
19
+ index = htmlElements.length - 1;
20
+ }
21
+ htmlElements[index]?.classList.add('active');
22
+ return index;
23
+ }
24
+ function removeAllActives(htmlElements) {
25
+ for (let i = 0; i < htmlElements.length; i++) {
26
+ htmlElements[i].classList.remove('active');
27
+ }
28
+ }
29
+ function eraseSuggestionList(form) {
30
+ while (form.children.length > 1) {
31
+ form.removeChild(form.lastChild);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * A widget for searchbar
37
+ *
38
+ * To use it, you need to link the widgets' stylesheet to your html webpage. This stylesheet is included in
39
+ * [itowns bundles](https://github.com/iTowns/itowns/releases) if you downloaded them, or it can be found in
40
+ * `node_modules/itowns/examples/css` if you installed iTowns with npm. Otherwise, it can be found at
41
+ * [this link](https://raw.githubusercontent.com/iTowns/itowns/master/examples/css/widgets.css). See
42
+ * [this example](http://www.itowns-project.org/itowns/examples/#widgets_searchbar) for more details.
43
+ *
44
+ * @extends Widget
45
+ *
46
+ * @property {HTMLElement} domElement An html div containing the searchbar.
47
+ * @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
48
+ */
49
+ class Searchbar extends Widget {
50
+ #_onSelected;
51
+
52
+ /**
53
+ * @param {View} view The iTowns view the searchbar should be linked
54
+ * to.
55
+ *
56
+ * @param {Object} geocodingOptions Configuration for geocoding.
57
+ * @param {URL} geocodingOptions.url The URL of a geocoding service that should be
58
+ * used to build suggestions.
59
+ * @param {function} geocodingOptions.parser A method to parse fetched results from geocoding
60
+ * url into a Map object. For each entry of this
61
+ * Map, the key must be a string that will be
62
+ * displayed as the html content of each
63
+ * suggestion bellow the searchbar. The value
64
+ * associated to the key is whatever the user
65
+ * wants. The value is the parameter that is
66
+ * passed to the `onSelected` method (specified
67
+ * in another `geocodingOptions` parameter).
68
+ * @param {function} [geocodingOptions.onSelected] A method which describes what should be done
69
+ * when user selects a location (by clicking or
70
+ * hitting enter on a suggestion). The only
71
+ * parameter of this method is the value mapped
72
+ * with `geocodingOptions.parser` method.
73
+ *
74
+ * @param {Object} [options] The searchbar optional configuration.
75
+ * @param {HTMLElement} [options.parentElement=view.domElement] The parent HTML container of the div which
76
+ * contains searchbar widgets.
77
+ * @param {number} [options.size] The size of the searchbar. It is a number that
78
+ * describes both width and height in pixels of
79
+ * the searchbar.
80
+ * @param {number} [options.width=300] The width in pixels of the searchbar.
81
+ * @param {number} [options.height=38] The height in pixels of the searchbar.
82
+ * @param {string} [options.position='top'] Defines which position within the
83
+ * `parentElement` the searchbar should be
84
+ * displayed to. Possible values are `top`,
85
+ * `bottom`, `left`, `right`, `top-left`,
86
+ * `top-right`, `bottom-left` and `bottom-right`.
87
+ * If the input value does not match one of
88
+ * these, it will be defaulted to `top`.
89
+ * @param {Object} [options.translate] An optional translation of the searchbar.
90
+ * @param {number} [options.translate.x=0] The searchbar translation along the page x-axis.
91
+ * @param {number} [options.translate.y=0] The searchbar translation along the page y-axis.
92
+ * @param {number} [options.fontSize=16] The font size in pixel of the searchbar content.
93
+ * @param {number} [options.maxSuggestionNumber=10] The maximum number of suggestions that should
94
+ * appear under the searchbar.
95
+ * @param {string} [options.placeholder='Search location'] The placeholder that appears in the searchbar
96
+ * when nothing has yet been typed.
97
+ */
98
+ constructor(view, geocodingOptions) {
99
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
100
+ // ---------- BUILD PROPERTIES ACCORDING TO DEFAULT OPTIONS AND OPTIONS PASSED IN PARAMETERS : ----------
101
+ super(view, options, DEFAULT_OPTIONS);
102
+
103
+ // Check if `geocodingOptions` parameter was correctly specified.
104
+ if (!geocodingOptions || !geocodingOptions.url || !geocodingOptions.parser || typeof geocodingOptions.parser !== 'function') {
105
+ throw new Error('\'geocodingOptions\' parameter for \'Searchbar\' constructor is not a valid option. Please refer to ' + 'the documentation.');
106
+ }
107
+ this.#_onSelected = geocodingOptions.onSelected ?? (() => {});
108
+
109
+ // ---------- this.domElement SETTINGS SPECIFIC TO SEARCHBAR : ----------
110
+
111
+ this.domElement.id = 'widgets-searchbar';
112
+ this.domElement.style.height = 'auto';
113
+ const form = document.createElement('form');
114
+ form.setAttribute('autocomplete', 'off');
115
+ form.id = 'searchbar-autocompletion-form';
116
+ this.domElement.appendChild(form);
117
+ const input = document.createElement('input');
118
+ input.setAttribute('type', 'text');
119
+ input.setAttribute('name', 'mySearch');
120
+ input.setAttribute('placeholder', options.placeholder || DEFAULT_OPTIONS.placeholder);
121
+ input.style.height = `${options.height || options.size || DEFAULT_OPTIONS.height}px`;
122
+ input.style.fontSize = `${options.fontSize || DEFAULT_OPTIONS.fontSize}px`;
123
+ form.appendChild(input);
124
+
125
+ // currentFocus variable stores the index of the suggestions that is focused by user, either with mouse or arrow
126
+ // keys.
127
+ let currentFocus;
128
+
129
+ // ---------- BUILD AUTOCOMPLETION SUGGESTIONS LIST WHEN TYPING THE SEARCHBAR INPUT : ----------
130
+
131
+ input.addEventListener('input', () => {
132
+ const value = input.value;
133
+
134
+ // Close any already opened list of autocompleted values
135
+ eraseSuggestionList(form);
136
+ currentFocus = -1;
137
+ if (!value) {
138
+ return false;
139
+ }
140
+ geocodingOptions.url.searchParams.set('text', value);
141
+ Fetcher.json(geocodingOptions.url).then(geocodingResult => {
142
+ const result = geocodingOptions.parser(geocodingResult);
143
+ let i = 0;
144
+ result.forEach((info, location) => {
145
+ // Stop looping through the map if enough location have been proceeded.
146
+ if (i === Math.min(result.size, options.maxSuggestionNumber || DEFAULT_OPTIONS.maxSuggestionNumber)) {
147
+ return;
148
+ }
149
+ const mapIndex = i;
150
+ i++;
151
+ const index = location.toUpperCase().indexOf(value.toUpperCase());
152
+ if (index > -1) {
153
+ const autocompleteItem = document.createElement('div');
154
+ autocompleteItem.style.minHeight = input.style.height;
155
+ autocompleteItem.style.fontSize = `${options.fontSize || DEFAULT_OPTIONS.fontSize}px`;
156
+
157
+ // Make the matching letters bold.
158
+ const start = location.slice(0, index);
159
+ const bold = location.slice(index, index + value.length);
160
+ const end = location.slice(index + value.length, location.length);
161
+ autocompleteItem.innerHTML = `<p>${start}<strong>${bold}</strong>${end}</p>`;
162
+ // Store the current location value as an attribute of autocompleteItem div.
163
+ autocompleteItem.setAttribute('location', location);
164
+ form.appendChild(autocompleteItem);
165
+
166
+ // eslint-disable-next-line no-loop-func
167
+ autocompleteItem.addEventListener('mouseover', () => {
168
+ removeAllActives(form.children);
169
+ currentFocus = mapIndex;
170
+ autocompleteItem.classList.add('active');
171
+ });
172
+ autocompleteItem.addEventListener('click', () => {
173
+ this.#_onSelected(info);
174
+ input.value = autocompleteItem.getAttribute('location');
175
+ eraseSuggestionList(form);
176
+ });
177
+ }
178
+ });
179
+ });
180
+ });
181
+
182
+ // ---------- MANAGE KEYBOARD INTERACTIONS ON AUTOCOMPLETION SUGGESTIONS : ----------
183
+
184
+ // When searchbar is positioned at the bottom of the screen (therefore is a flex with `column-reverse`
185
+ // direction, we must exchange up and down arrow actions.
186
+ const topOrBottom = (options.position || DEFAULT_OPTIONS.position).includes('top') ? 1 : -1;
187
+ input.addEventListener('keydown', event => {
188
+ event.stopPropagation();
189
+ const completionSuggestions = form.getElementsByTagName('div');
190
+ switch (event.code) {
191
+ case 'Escape':
192
+ eraseSuggestionList(form);
193
+ input.value = '';
194
+ view.domElement.focus();
195
+ break;
196
+ case 'ArrowDown':
197
+ event.preventDefault();
198
+ currentFocus = addActive(completionSuggestions, currentFocus + topOrBottom);
199
+ break;
200
+ case 'ArrowUp':
201
+ event.preventDefault();
202
+ currentFocus = addActive(completionSuggestions, currentFocus - topOrBottom);
203
+ break;
204
+ case 'Enter':
205
+ event.preventDefault();
206
+ if (completionSuggestions[Math.max(currentFocus, 0)]) {
207
+ completionSuggestions[Math.max(currentFocus, 0)].click();
208
+ view.domElement.focus();
209
+ }
210
+ break;
211
+ default:
212
+ break;
213
+ }
214
+ });
215
+
216
+ // ---------- MANAGE FOCUS AND ACTIVE SUGGESTION WHEN USER ENTERS OR LEAVES THE SEARCHBAR : ----------
217
+
218
+ // User clicks the searchbar.
219
+ input.addEventListener('focus', () => {
220
+ form.classList.add('focus');
221
+ });
222
+ // User clicks out of the searchbar.
223
+ input.addEventListener('blur', () => {
224
+ form.classList.remove('focus');
225
+ removeAllActives(form.children);
226
+ });
227
+ // Cursor leaves the searchbar.
228
+ form.addEventListener('mouseleave', () => {
229
+ removeAllActives(form.children);
230
+ currentFocus = -1;
231
+ });
232
+ }
233
+ }
234
+ export default Searchbar;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * An interface that stores common methods for all specific widgets.
3
+ *
4
+ * @hideconstructor
5
+ */
6
+ class Widget {
7
+ #_display;
8
+ constructor(view) {
9
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10
+ let defaultOptions = arguments.length > 2 ? arguments[2] : undefined;
11
+ this.parentElement = options.parentElement || view.domElement;
12
+ this.position = options.position || defaultOptions.position;
13
+ if (!['top-left', 'top-right', 'bottom-left', 'bottom-right', 'top', 'bottom', 'left', 'right'].includes(this.position)) {
14
+ console.warn('\'position\' optional parameter for \'Widget\' constructor is not a valid option. ' + `It will be set to '${defaultOptions.position}'.`);
15
+ this.position = defaultOptions.position;
16
+ }
17
+
18
+ // ---------- CREATE A DomElement WITH id, classes AND style RELEVANT TO THE WIDGET PROPERTIES : ----------
19
+
20
+ // Create a div containing minimap widget and add it to its specified parent.
21
+ this.domElement = document.createElement('div');
22
+ this.parentElement.appendChild(this.domElement);
23
+
24
+ // Size widget according to options.
25
+ this.domElement.style.width = `${options.width || options.size || defaultOptions.width}px`;
26
+ this.domElement.style.height = `${options.height || options.size || defaultOptions.height}px`;
27
+
28
+ // Position widget according to options.
29
+ const positionArray = this.position.split('-');
30
+ this.domElement.classList.add(`${positionArray[0]}-widget`);
31
+ if (positionArray[1]) {
32
+ this.domElement.classList.add(`${positionArray[1]}-widget`);
33
+ } else {
34
+ // If only one position parameter was given, center the domElement on the other axis.
35
+ // TODO : at this stage, offsetWidth and offsetHeight do no include borders. This should be worked around.
36
+ switch (positionArray[0]) {
37
+ case 'top':
38
+ case 'bottom':
39
+ this.domElement.style.left = `calc(50% - ${this.domElement.offsetWidth / 2}px)`;
40
+ break;
41
+ case 'left':
42
+ case 'right':
43
+ this.domElement.style.top = `calc(50% - ${this.domElement.offsetHeight / 2}px)`;
44
+ break;
45
+ default:
46
+ break;
47
+ }
48
+ }
49
+
50
+ // Translate widget div according to optional translate parameter.
51
+ if (options.translate) {
52
+ this.domElement.style.transform = `translate(${options.translate.x || 0}px, ${options.translate.y || 0}px)`;
53
+ }
54
+
55
+ // Prevent triggering `GlobeControls` and `PlanarControls` mouse or pointer events when clicking the search bar.
56
+ // For example, this prevents triggering an animated travel when double-clicking search bar in a `GlobeView`.
57
+ this.domElement.addEventListener('pointerdown', e => {
58
+ e.stopPropagation();
59
+ });
60
+ this.domElement.addEventListener('mousedown', e => {
61
+ e.stopPropagation();
62
+ });
63
+ }
64
+
65
+ /**
66
+ * Change the widget style `display` property so that the widget becomes visible.
67
+ */
68
+ show() {
69
+ this.domElement.style.display = this.#_display;
70
+ }
71
+
72
+ /**
73
+ * Change the widget style `display` property so that the widget becomes invisible.
74
+ */
75
+ hide() {
76
+ this.#_display = window.getComputedStyle(this.domElement).display;
77
+ this.domElement.style.display = 'none';
78
+ }
79
+ }
80
+ export default Widget;
@@ -0,0 +1,136 @@
1
+ import * as THREE from 'three';
2
+ import { Coordinates } from '@itowns/geographic';
3
+ import DEMUtils from "./DEMUtils.js";
4
+ const temp = {
5
+ v: new THREE.Vector3(),
6
+ coord1: new Coordinates('EPSG:4978'),
7
+ coord2: new Coordinates('EPSG:4978'),
8
+ offset: new THREE.Vector2()
9
+ };
10
+ function _updateVector3(layer, method, nodes, vecCRS, vec, offset) {
11
+ let matrices = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
12
+ let coords = arguments.length > 7 ? arguments[7] : undefined;
13
+ let cache = arguments.length > 8 ? arguments[8] : undefined;
14
+ const coord = coords || new Coordinates(vecCRS);
15
+ if (matrices.worldFromLocal) {
16
+ coord.setFromVector3(temp.v.copy(vec).applyMatrix4(matrices.worldFromLocal));
17
+ } else {
18
+ coord.setFromVector3(vec);
19
+ }
20
+ const result = DEMUtils.getTerrainObjectAt(layer, coord, method, nodes, cache);
21
+ if (result) {
22
+ result.coord.z += offset;
23
+ result.coord.as(vecCRS, temp.coord2).toVector3(vec);
24
+ if (matrices.localFromWorld) {
25
+ vec.applyMatrix4(matrices.localFromWorld);
26
+ }
27
+ return {
28
+ id: result.texture.id,
29
+ version: result.texture.version,
30
+ tile: result.tile
31
+ };
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @deprecated
37
+ * Helper method that will position an object directly on the ground.
38
+ *
39
+ * @param {TiledGeometryLayer} layer - The tile layer owning the elevation
40
+ * textures we're going to query. This is typically a `GlobeLayer` or
41
+ * `PlanarLayer` (accessible through `view.tileLayer`).
42
+ * @param {string} crs - The CRS used by the object coordinates. You
43
+ * probably want to use `view.referenceCRS` here.
44
+ * @param {Object3D} obj - the object we want to modify.
45
+ * @param {Object} options
46
+ * @param {number} [options.method=FAST_READ_Z] - There are two available methods:
47
+ * `FAST_READ_Z` (default) or `PRECISE_READ_Z`. The first one is faster,
48
+ * while the second one is slower but gives better precision.
49
+ * @param {boolean} options.modifyGeometry - if unset/false, this function
50
+ * will modify object.position. If true, it will modify
51
+ * `obj.geometry.vertices` or `obj.geometry.attributes.position`.
52
+ * @param {TileMesh[]} [tileHint] - Optional array of tiles to speed up the
53
+ * process. You can give candidates tiles likely to contain `coord`.
54
+ * Otherwise the lookup process starts from the root of `layer`.
55
+ *
56
+ * @return {boolean} true if successful, false if we couldn't lookup the elevation at the given coords
57
+ */
58
+ function placeObjectOnGround(layer, crs, obj) {
59
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
60
+ let tileHint = arguments.length > 4 ? arguments[4] : undefined;
61
+ console.warn('placeObjectOnGround has been deprecated because it needs review and test');
62
+ let tiles;
63
+ if (tileHint) {
64
+ tiles = tileHint.concat(layer.level0Nodes);
65
+ } else {
66
+ tiles = layer.level0Nodes;
67
+ }
68
+ if (!options.modifyGeometry) {
69
+ if (options.cache) {
70
+ options.cache.length = 1;
71
+ }
72
+ const matrices = {
73
+ worldFromLocal: obj.parent ? obj.parent.matrixWorld : undefined,
74
+ localFromWorld: obj.parent ? new THREE.Matrix4().copy(obj.parent.matrixWorld).invert() : undefined
75
+ };
76
+ const result = _updateVector3(layer, options.method || DEMUtils.FAST_READ_Z, tiles, crs, obj.position, options.offset || 0, matrices, undefined, options.cache ? options.cache[0] : undefined);
77
+ if (result) {
78
+ if (options.cache) {
79
+ options.cache[0] = result;
80
+ }
81
+ obj.updateMatrix();
82
+ obj.updateMatrixWorld();
83
+ return true;
84
+ }
85
+ } else {
86
+ const matrices = {
87
+ worldFromLocal: obj.matrixWorld,
88
+ localFromWorld: new THREE.Matrix4().copy(obj.matrixWorld).invert()
89
+ };
90
+ const geometry = obj.geometry;
91
+ if (geometry.vertices) {
92
+ if (options.cache) {
93
+ options.cache.length = geometry.vertices.length;
94
+ }
95
+ let success = true;
96
+ const coord = new Coordinates(crs);
97
+ for (let i = 0; i < geometry.vertices.length; i++) {
98
+ const cached = options.cache ? options.cache[i] : undefined;
99
+ const result = _updateVector3(layer, options.method || DEMUtils.FAST_READ_Z, tiles, crs, geometry.vertices[i], options.offset || 0, matrices, coord, cached);
100
+ if (options.cache) {
101
+ options.cache[i] = result;
102
+ }
103
+ if (!result) {
104
+ success = false;
105
+ }
106
+ }
107
+ geometry.verticesNeedUpdate = true;
108
+ return success;
109
+ } else if (geometry.isBufferGeometry) {
110
+ if (options.cache) {
111
+ options.cache.length = geometry.attributes.position.count;
112
+ }
113
+ let success = true;
114
+ const tmp = new THREE.Vector3();
115
+ const coord = new Coordinates(crs);
116
+ for (let i = 0; i < geometry.attributes.position.count; i++) {
117
+ const cached = options.cache ? options.cache[i] : undefined;
118
+ tmp.fromBufferAttribute(geometry.attributes.position, i);
119
+ const prev = tmp.z;
120
+ const result = _updateVector3(layer, options.method || DEMUtils.FAST_READ_Z, tiles, crs, tmp, options.offset || 0, matrices, coord, cached);
121
+ if (options.cache) {
122
+ options.cache[i] = result;
123
+ }
124
+ if (!result) {
125
+ success = false;
126
+ }
127
+ if (prev != tmp.z) {
128
+ geometry.attributes.position.needsUpdate = true;
129
+ }
130
+ geometry.attributes.position.setXYZ(i, tmp.x, tmp.y, tmp.z);
131
+ }
132
+ return success;
133
+ }
134
+ }
135
+ }
136
+ export default placeObjectOnGround;
@@ -0,0 +1,19 @@
1
+ import { expose, Transfer } from 'threads/worker';
2
+ import LASLoader from "../Loader/LASLoader.js";
3
+ const loader = new LASLoader();
4
+ function transferable(attributes) {
5
+ return Object.values(attributes).filter(ArrayBuffer.isView).map(a => a.buffer);
6
+ }
7
+ expose({
8
+ lazPerf(path) {
9
+ loader.lazPerf = path;
10
+ },
11
+ async parseChunk(data, options) {
12
+ const result = await loader.parseChunk(data, options);
13
+ return Transfer(result, transferable(result.attributes));
14
+ },
15
+ async parseFile(data, options) {
16
+ const result = await loader.parseFile(data, options);
17
+ return Transfer(result, transferable(result.attributes));
18
+ }
19
+ });
@@ -0,0 +1,21 @@
1
+ import load from "../Loader/Potree2Loader.js";
2
+ import loadBrotli from "../Loader/Potree2BrotliLoader.js";
3
+ import { expose, Transfer } from 'threads/worker';
4
+ function transfer(buffer, data) {
5
+ const transferables = [];
6
+ Object.keys(data.attributeBuffers).forEach(property => {
7
+ transferables.push(data.attributeBuffers[property].buffer);
8
+ });
9
+ transferables.push(buffer);
10
+ return transferables;
11
+ }
12
+ expose({
13
+ async parse(buffer, options) {
14
+ const data = await load(buffer, options);
15
+ return Transfer(data, transfer(buffer, data));
16
+ },
17
+ async parseBrotli(buffer, options) {
18
+ const data = await loadBrotli(buffer, options);
19
+ return Transfer(data, transfer(buffer, data));
20
+ }
21
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itowns",
3
- "version": "2.45.1-next.0",
3
+ "version": "2.45.1-next.1",
4
4
  "description": "A JS/WebGL framework for 3D geospatial data visualization",
5
5
  "type": "module",
6
6
  "main": "lib/Main.js",
@@ -48,7 +48,7 @@
48
48
  "url": "https://github.com/iTowns/itowns/issues"
49
49
  },
50
50
  "dependencies": {
51
- "@itowns/geographic": "^2.45.1-next.0",
51
+ "@itowns/geographic": "^2.45.1-next.1",
52
52
  "@mapbox/vector-tile": "^2.0.3",
53
53
  "@maplibre/maplibre-gl-style-spec": "^22.0.0",
54
54
  "@tmcw/togeojson": "^5.8.1",