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.
Files changed (219) hide show
  1. package/README.md +3 -129
  2. package/examples/3dtiles_loader.html +123 -48
  3. package/examples/config.json +3 -10
  4. package/examples/copc_simple_loader.html +15 -5
  5. package/examples/effects_stereo.html +2 -2
  6. package/examples/entwine_3d_loader.html +3 -1
  7. package/examples/entwine_simple_loader.html +1 -1
  8. package/examples/images/itowns_logo.svg +123 -0
  9. package/examples/js/plugins/COGParser.js +1 -1
  10. package/examples/jsm/OGC3DTilesHelper.js +6 -1
  11. package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
  12. package/examples/misc_collada.html +2 -2
  13. package/examples/source_file_geojson_3d.html +0 -1
  14. package/examples/source_file_kml_raster_usgs.html +0 -1
  15. package/examples/source_stream_wfs_raster.html +0 -7
  16. package/examples/vector_tile_mapbox_raster.html +91 -0
  17. package/examples/view_3d_map_webxr.html +3 -1
  18. package/examples/view_multi_25d.html +2 -2
  19. package/package.json +21 -75
  20. package/CODING.md +0 -120
  21. package/CONTRIBUTING.md +0 -150
  22. package/CONTRIBUTORS.md +0 -55
  23. package/LICENSE.md +0 -44
  24. package/changelog.md +0 -1361
  25. package/dist/455.js +0 -2
  26. package/dist/455.js.map +0 -1
  27. package/dist/debug.js +0 -3
  28. package/dist/debug.js.LICENSE.txt +0 -13
  29. package/dist/debug.js.map +0 -1
  30. package/dist/itowns.js +0 -3
  31. package/dist/itowns.js.LICENSE.txt +0 -7
  32. package/dist/itowns.js.map +0 -1
  33. package/dist/itowns_lasparser.js +0 -2
  34. package/dist/itowns_lasparser.js.map +0 -1
  35. package/dist/itowns_lasworker.js +0 -2
  36. package/dist/itowns_lasworker.js.map +0 -1
  37. package/dist/itowns_potree2worker.js +0 -2
  38. package/dist/itowns_potree2worker.js.map +0 -1
  39. package/dist/itowns_widgets.js +0 -2
  40. package/dist/itowns_widgets.js.map +0 -1
  41. package/examples/.eslintrc.cjs +0 -35
  42. package/examples/3dtiles_25d.html +0 -120
  43. package/examples/3dtiles_basic.html +0 -94
  44. package/examples/3dtiles_batch_table.html +0 -86
  45. package/examples/3dtiles_ion.html +0 -126
  46. package/examples/3dtiles_pointcloud.html +0 -95
  47. package/examples/jsm/.eslintrc.cjs +0 -38
  48. package/lib/Controls/FirstPersonControls.js +0 -308
  49. package/lib/Controls/FlyControls.js +0 -175
  50. package/lib/Controls/GlobeControls.js +0 -1162
  51. package/lib/Controls/PlanarControls.js +0 -1025
  52. package/lib/Controls/StateControl.js +0 -429
  53. package/lib/Controls/StreetControls.js +0 -392
  54. package/lib/Converter/Feature2Mesh.js +0 -615
  55. package/lib/Converter/Feature2Texture.js +0 -170
  56. package/lib/Converter/convertToTile.js +0 -75
  57. package/lib/Converter/textureConverter.js +0 -44
  58. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  59. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  60. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  61. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  62. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  63. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  64. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  65. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  66. package/lib/Core/AnimationPlayer.js +0 -142
  67. package/lib/Core/CopcNode.js +0 -174
  68. package/lib/Core/Deprecated/Undeprecator.js +0 -75
  69. package/lib/Core/EntwinePointTileNode.js +0 -126
  70. package/lib/Core/Feature.js +0 -490
  71. package/lib/Core/Geographic/CoordStars.js +0 -80
  72. package/lib/Core/Geographic/Coordinates.js +0 -320
  73. package/lib/Core/Geographic/Crs.js +0 -175
  74. package/lib/Core/Geographic/Extent.js +0 -534
  75. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  76. package/lib/Core/Label.js +0 -222
  77. package/lib/Core/MainLoop.js +0 -211
  78. package/lib/Core/Math/Ellipsoid.js +0 -144
  79. package/lib/Core/Picking.js +0 -255
  80. package/lib/Core/PointCloudNode.js +0 -42
  81. package/lib/Core/Potree2Node.js +0 -206
  82. package/lib/Core/Potree2PointAttributes.js +0 -139
  83. package/lib/Core/PotreeNode.js +0 -101
  84. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
  85. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
  86. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
  87. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  88. package/lib/Core/Prefab/GlobeView.js +0 -161
  89. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
  90. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  91. package/lib/Core/Prefab/PlanarView.js +0 -62
  92. package/lib/Core/Prefab/TileBuilder.js +0 -80
  93. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
  94. package/lib/Core/Scheduler/Cache.js +0 -256
  95. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  96. package/lib/Core/Scheduler/Scheduler.js +0 -294
  97. package/lib/Core/Style.js +0 -1121
  98. package/lib/Core/System/Capabilities.js +0 -63
  99. package/lib/Core/Tile/Tile.js +0 -219
  100. package/lib/Core/Tile/TileGrid.js +0 -46
  101. package/lib/Core/TileGeometry.js +0 -40
  102. package/lib/Core/TileMesh.js +0 -109
  103. package/lib/Core/View.js +0 -1109
  104. package/lib/Layer/C3DTilesLayer.js +0 -455
  105. package/lib/Layer/ColorLayer.js +0 -128
  106. package/lib/Layer/CopcLayer.js +0 -58
  107. package/lib/Layer/ElevationLayer.js +0 -107
  108. package/lib/Layer/EntwinePointTileLayer.js +0 -64
  109. package/lib/Layer/FeatureGeometryLayer.js +0 -63
  110. package/lib/Layer/GeoidLayer.js +0 -80
  111. package/lib/Layer/GeometryLayer.js +0 -202
  112. package/lib/Layer/InfoLayer.js +0 -64
  113. package/lib/Layer/LabelLayer.js +0 -456
  114. package/lib/Layer/Layer.js +0 -304
  115. package/lib/Layer/LayerUpdateState.js +0 -89
  116. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  117. package/lib/Layer/OGC3DTilesLayer.js +0 -387
  118. package/lib/Layer/OrientedImageLayer.js +0 -222
  119. package/lib/Layer/PointCloudLayer.js +0 -359
  120. package/lib/Layer/Potree2Layer.js +0 -164
  121. package/lib/Layer/PotreeLayer.js +0 -65
  122. package/lib/Layer/RasterLayer.js +0 -27
  123. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  124. package/lib/Layer/TiledGeometryLayer.js +0 -403
  125. package/lib/Loader/LASLoader.js +0 -193
  126. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  127. package/lib/Loader/Potree2Loader.js +0 -207
  128. package/lib/Main.js +0 -115
  129. package/lib/MainBundle.js +0 -4
  130. package/lib/Parser/B3dmParser.js +0 -174
  131. package/lib/Parser/CameraCalibrationParser.js +0 -94
  132. package/lib/Parser/GDFParser.js +0 -72
  133. package/lib/Parser/GTXParser.js +0 -75
  134. package/lib/Parser/GeoJsonParser.js +0 -212
  135. package/lib/Parser/GpxParser.js +0 -25
  136. package/lib/Parser/ISGParser.js +0 -71
  137. package/lib/Parser/KMLParser.js +0 -25
  138. package/lib/Parser/LASParser.js +0 -137
  139. package/lib/Parser/MapBoxUrlParser.js +0 -83
  140. package/lib/Parser/PntsParser.js +0 -131
  141. package/lib/Parser/Potree2BinParser.js +0 -92
  142. package/lib/Parser/PotreeBinParser.js +0 -106
  143. package/lib/Parser/PotreeCinParser.js +0 -29
  144. package/lib/Parser/ShapefileParser.js +0 -78
  145. package/lib/Parser/VectorTileParser.js +0 -202
  146. package/lib/Parser/XbilParser.js +0 -119
  147. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  148. package/lib/Parser/iGLTFLoader.js +0 -168
  149. package/lib/Process/3dTilesProcessing.js +0 -304
  150. package/lib/Process/FeatureProcessing.js +0 -76
  151. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  152. package/lib/Process/ObjectRemovalHelper.js +0 -97
  153. package/lib/Process/handlerNodeError.js +0 -23
  154. package/lib/Provider/3dTilesProvider.js +0 -149
  155. package/lib/Provider/DataSourceProvider.js +0 -8
  156. package/lib/Provider/Fetcher.js +0 -229
  157. package/lib/Provider/PointCloudProvider.js +0 -45
  158. package/lib/Provider/TileProvider.js +0 -16
  159. package/lib/Provider/URLBuilder.js +0 -116
  160. package/lib/Renderer/Camera.js +0 -281
  161. package/lib/Renderer/Color.js +0 -56
  162. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  163. package/lib/Renderer/CommonMaterial.js +0 -31
  164. package/lib/Renderer/Label2DRenderer.js +0 -190
  165. package/lib/Renderer/LayeredMaterial.js +0 -243
  166. package/lib/Renderer/OBB.js +0 -153
  167. package/lib/Renderer/OrientedImageCamera.js +0 -118
  168. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  169. package/lib/Renderer/PointsMaterial.js +0 -485
  170. package/lib/Renderer/RasterTile.js +0 -209
  171. package/lib/Renderer/RenderMode.js +0 -31
  172. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  173. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  174. package/lib/Renderer/SphereHelper.js +0 -23
  175. package/lib/Renderer/WebXR.js +0 -51
  176. package/lib/Renderer/c3DEngine.js +0 -214
  177. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  178. package/lib/Source/C3DTilesIonSource.js +0 -54
  179. package/lib/Source/C3DTilesSource.js +0 -30
  180. package/lib/Source/CopcSource.js +0 -115
  181. package/lib/Source/EntwinePointTileSource.js +0 -62
  182. package/lib/Source/FileSource.js +0 -189
  183. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  184. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  185. package/lib/Source/OGC3DTilesSource.js +0 -21
  186. package/lib/Source/OrientedImageSource.js +0 -59
  187. package/lib/Source/Potree2Source.js +0 -167
  188. package/lib/Source/PotreeSource.js +0 -82
  189. package/lib/Source/Source.js +0 -223
  190. package/lib/Source/TMSSource.js +0 -145
  191. package/lib/Source/VectorTilesSource.js +0 -178
  192. package/lib/Source/WFSSource.js +0 -168
  193. package/lib/Source/WMSSource.js +0 -133
  194. package/lib/Source/WMTSSource.js +0 -86
  195. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  196. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
  197. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  198. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  199. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
  200. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
  201. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
  202. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  203. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  204. package/lib/Utils/CameraUtils.js +0 -555
  205. package/lib/Utils/DEMUtils.js +0 -350
  206. package/lib/Utils/FeaturesUtils.js +0 -156
  207. package/lib/Utils/Gradients.js +0 -16
  208. package/lib/Utils/OrientationUtils.js +0 -457
  209. package/lib/Utils/ThreeUtils.js +0 -115
  210. package/lib/Utils/gui/C3DTilesStyle.js +0 -215
  211. package/lib/Utils/gui/Main.js +0 -7
  212. package/lib/Utils/gui/Minimap.js +0 -154
  213. package/lib/Utils/gui/Navigation.js +0 -245
  214. package/lib/Utils/gui/Scale.js +0 -107
  215. package/lib/Utils/gui/Searchbar.js +0 -234
  216. package/lib/Utils/gui/Widget.js +0 -80
  217. package/lib/Utils/placeObjectOnGround.js +0 -137
  218. package/lib/Worker/LASLoaderWorker.js +0 -19
  219. package/lib/Worker/Potree2Worker.js +0 -21
@@ -1,183 +0,0 @@
1
- import * as THREE from 'three';
2
- export function getBufferIndexSize(segments, noSkirt) {
3
- const triangles = segments * segments * 2 + (noSkirt ? 0 : 4 * segments * 2);
4
- return triangles * 3;
5
- }
6
- export default function computeBuffers(params) {
7
- // Create output buffers.
8
- const outBuffers = {
9
- index: null,
10
- position: null,
11
- normal: null,
12
- // 2 UV set per tile: wgs84 (uv[0]) and pm (uv[1])
13
- // - wgs84: 1 texture per tile because tiles are using wgs84 projection
14
- // - pm: use multiple textures per tile.
15
- // +-------------------------+
16
- // | |
17
- // | Texture 0 |
18
- // +-------------------------+
19
- // | |
20
- // | Texture 1 |
21
- // +-------------------------+
22
- // | |
23
- // | Texture 2 |
24
- // +-------------------------+
25
- // * u = wgs84.u
26
- // * v = textureid + v in builder texture
27
- uvs: []
28
- };
29
- const computeUvs = [];
30
- const builder = params.builder;
31
- const nSeg = params.segments;
32
- // segments count :
33
- // Tile : (nSeg + 1) * (nSeg + 1)
34
- // Skirt : 8 * (nSeg - 1)
35
- const nVertex = (nSeg + 1) * (nSeg + 1) + (params.disableSkirt ? 0 : 4 * nSeg);
36
- if (nVertex > 2 ** 32) {
37
- throw new Error('Tile segments count is too big');
38
- }
39
- outBuffers.position = new Float32Array(nVertex * 3);
40
- outBuffers.normal = new Float32Array(nVertex * 3);
41
- const uvCount = params.builder.uvCount;
42
- if (uvCount > 1) {
43
- outBuffers.uvs[1] = new Float32Array(nVertex);
44
- }
45
- computeUvs[0] = () => {};
46
- const bufferIndexSize = getBufferIndexSize(nSeg, params.disableSkirt);
47
- if (params.buildIndexAndUv_0) {
48
- if (nVertex < 2 ** 8) {
49
- outBuffers.index = new Uint8Array(bufferIndexSize);
50
- } else if (nVertex < 2 ** 16) {
51
- outBuffers.index = new Uint16Array(bufferIndexSize);
52
- } else if (nVertex < 2 ** 32) {
53
- outBuffers.index = new Uint32Array(bufferIndexSize);
54
- }
55
- outBuffers.uvs[0] = new Float32Array(nVertex * 2);
56
- computeUvs[0] = (id, u, v) => {
57
- outBuffers.uvs[0][id * 2 + 0] = u;
58
- outBuffers.uvs[0][id * 2 + 1] = v;
59
- };
60
- }
61
- const widthSegments = Math.max(2, Math.floor(nSeg) || 2);
62
- const heightSegments = Math.max(2, Math.floor(nSeg) || 2);
63
- let idVertex = 0;
64
- const vertices = [];
65
- let skirt = [];
66
- const skirtEnd = [];
67
- builder.prepare(params);
68
- for (let y = 0; y <= heightSegments; y++) {
69
- const verticesRow = [];
70
- const v = y / heightSegments;
71
- builder.vProjecte(v, params);
72
- if (uvCount > 1) {
73
- const u = builder.computeUvs[1](params);
74
- computeUvs[1] = id => {
75
- outBuffers.uvs[1][id] = u;
76
- };
77
- }
78
- for (let x = 0; x <= widthSegments; x++) {
79
- const u = x / widthSegments;
80
- const id_m3 = idVertex * 3;
81
- builder.uProjecte(u, params);
82
- const vertex = builder.vertexPosition(params, params.projected);
83
- const normal = builder.vertexNormal(params);
84
-
85
- // move geometry to center world
86
- vertex.sub(params.center);
87
-
88
- // align normal to z axis
89
- if (params.quatNormalToZ) {
90
- vertex.applyQuaternion(params.quatNormalToZ);
91
- normal.applyQuaternion(params.quatNormalToZ);
92
- }
93
- vertex.toArray(outBuffers.position, id_m3);
94
- normal.toArray(outBuffers.normal, id_m3);
95
- for (const computeUv of computeUvs) {
96
- computeUv(idVertex, u, v);
97
- }
98
- if (!params.disableSkirt) {
99
- if (y !== 0 && y !== heightSegments) {
100
- if (x === widthSegments) {
101
- skirt.push(idVertex);
102
- } else if (x === 0) {
103
- skirtEnd.push(idVertex);
104
- }
105
- }
106
- }
107
- verticesRow.push(idVertex);
108
- idVertex++;
109
- }
110
- vertices.push(verticesRow);
111
- if (y === 0) {
112
- skirt = skirt.concat(verticesRow);
113
- } else if (y === heightSegments) {
114
- skirt = skirt.concat(verticesRow.slice().reverse());
115
- }
116
- }
117
- if (!params.disableSkirt) {
118
- skirt = skirt.concat(skirtEnd.reverse());
119
- }
120
- function bufferize(va, vb, vc, idVertex) {
121
- outBuffers.index[idVertex + 0] = va;
122
- outBuffers.index[idVertex + 1] = vb;
123
- outBuffers.index[idVertex + 2] = vc;
124
- return idVertex + 3;
125
- }
126
- let idVertex2 = 0;
127
- if (params.buildIndexAndUv_0) {
128
- for (let y = 0; y < heightSegments; y++) {
129
- for (let x = 0; x < widthSegments; x++) {
130
- const v1 = vertices[y][x + 1];
131
- const v2 = vertices[y][x];
132
- const v3 = vertices[y + 1][x];
133
- const v4 = vertices[y + 1][x + 1];
134
- idVertex2 = bufferize(v4, v2, v1, idVertex2);
135
- idVertex2 = bufferize(v4, v3, v2, idVertex2);
136
- }
137
- }
138
- }
139
- const iStart = idVertex;
140
-
141
- // TODO: WARNING beware skirt's size influences performance
142
- // The size of the skirt is now a ratio of the size of the tile.
143
- // To be perfect it should depend on the real elevation delta but too heavy to compute
144
- if (!params.disableSkirt) {
145
- // We compute the actual size of tile segment to use later for the skirt.
146
- const segmentSize = new THREE.Vector3().fromArray(outBuffers.position).distanceTo(new THREE.Vector3().fromArray(outBuffers.position, 3));
147
- let buildIndexSkirt = function () {};
148
- let buildUVSkirt = function () {};
149
- if (params.buildIndexAndUv_0) {
150
- buildIndexSkirt = function (id, v1, v2, v3, v4) {
151
- id = bufferize(v1, v2, v3, id);
152
- id = bufferize(v1, v3, v4, id);
153
- return id;
154
- };
155
- buildUVSkirt = function (id) {
156
- outBuffers.uvs[0][idVertex * 2 + 0] = outBuffers.uvs[0][id * 2 + 0];
157
- outBuffers.uvs[0][idVertex * 2 + 1] = outBuffers.uvs[0][id * 2 + 1];
158
- };
159
- }
160
- for (let i = 0; i < skirt.length; i++) {
161
- const id = skirt[i];
162
- const id_m3 = idVertex * 3;
163
- const id2_m3 = id * 3;
164
- outBuffers.position[id_m3 + 0] = outBuffers.position[id2_m3 + 0] - outBuffers.normal[id2_m3 + 0] * segmentSize;
165
- outBuffers.position[id_m3 + 1] = outBuffers.position[id2_m3 + 1] - outBuffers.normal[id2_m3 + 1] * segmentSize;
166
- outBuffers.position[id_m3 + 2] = outBuffers.position[id2_m3 + 2] - outBuffers.normal[id2_m3 + 2] * segmentSize;
167
- outBuffers.normal[id_m3 + 0] = outBuffers.normal[id2_m3 + 0];
168
- outBuffers.normal[id_m3 + 1] = outBuffers.normal[id2_m3 + 1];
169
- outBuffers.normal[id_m3 + 2] = outBuffers.normal[id2_m3 + 2];
170
- buildUVSkirt(id);
171
- if (uvCount > 1) {
172
- outBuffers.uvs[1][idVertex] = outBuffers.uvs[1][id];
173
- }
174
- const idf = (i + 1) % skirt.length;
175
- const v2 = idVertex;
176
- const v3 = idf === 0 ? iStart : idVertex + 1;
177
- const v4 = skirt[idf];
178
- idVertex2 = buildIndexSkirt(idVertex2, id, v2, v3, v4);
179
- idVertex++;
180
- }
181
- }
182
- return outBuffers;
183
- }
@@ -1,256 +0,0 @@
1
- let entry;
2
-
3
- /**
4
- * Cache policies for flushing. Those policies can be used when something is
5
- * [set]{@link Cache.set} into the Cache, as the lifetime property.
6
- *
7
- * @typedef {Object} CACHE_POLICIES
8
- *
9
- * @property {number} INFINITE - The entry is never flushed, except when the
10
- * `all` flag is set to `true` when calling {@link Cache.flush}.
11
- * @property {number} TEXTURE - Shortcut for texture resources. Time is 15 minutes.
12
- * @property {number} GEOMETRY - Shortcut for geometry resources. Time is 15 minutes.
13
- * minutes.
14
- */
15
- export const CACHE_POLICIES = {
16
- INFINITE: Infinity,
17
- TEXTURE: 900000,
18
- GEOMETRY: 900000
19
- };
20
-
21
- /**
22
- * This is a copy of the Map object, except that it also store a value for last
23
- * time used. This value is used for cache expiration mechanism.
24
- *
25
- * @example
26
- * import Cache, { CACHE_POLICIES } from 'Core/Scheduler/Cache';
27
- *
28
- * const cache = new Cache(CACHE_POLICIES.TEXTURE)
29
- * cache.set({ bar: 1 }, 'foo');
30
- * cache.set({ bar: 32 }, 'foo', 'toto');
31
- *
32
- * cache.get('foo');
33
- *
34
- * cache.delete('foo');
35
- *
36
- * cache.clear();
37
- *
38
- * cache.flush();
39
- */
40
- class Cache {
41
- /**
42
- * @param {number} [lifetime=CACHE_POLICIES.INFINITE] The cache expiration time for all values.
43
- */
44
- constructor() {
45
- let lifetime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CACHE_POLICIES.INFINITE;
46
- this.lifeTime = lifetime;
47
- this.lastTimeFlush = Date.now();
48
- this.data = new Map();
49
- }
50
-
51
- /**
52
- * Returns the entry related to the specified key, content in array, from the cache.
53
- * The array contents one to three key.
54
- * The last time used property of the entry is updated to extend the longevity of the
55
- * entry.
56
- *
57
- * @param {string[]|number[]} keyArray key array ([key0, key1, key3])
58
- *
59
- * @return {Object}
60
- */
61
-
62
- getByArray(keyArray) {
63
- return this.get(keyArray[0], keyArray[1], keyArray[2]);
64
- }
65
-
66
- /**
67
- * Adds or updates an entry with specified keys array ([key0, key1, key3]).
68
- * Caution: it overrides any existing entry already set at this/those key/s.
69
- *
70
- * @param {Object} value to add in cache
71
- * @param {string[]|number[]} keyArray key array ([key0, key1, key3])
72
- *
73
- * @return {Object} the added value
74
- */
75
- setByArray(value, keyArray) {
76
- return this.set(value, keyArray[0], keyArray[1], keyArray[2]);
77
- }
78
-
79
- /**
80
- * Returns the entry related to the specified key from the cache. The last
81
- * time used property of the entry is updated to extend the longevity of the
82
- * entry.
83
- *
84
- * @param {string|number} key1
85
- * @param {string|number} [key2]
86
- * @param {string|number} [key3]
87
- *
88
- * @return {Object}
89
- */
90
- get(key1, key2, key3) {
91
- const entry_1 = this.data.get(key1);
92
- if (entry_1 == undefined) {
93
- return;
94
- }
95
- if (entry_1.lastTimeUsed != undefined) {
96
- entry = entry_1;
97
- } else {
98
- const entry_2 = entry_1.get(key2);
99
- if (entry_2 == undefined) {
100
- return;
101
- }
102
- if (entry_2.lastTimeUsed != undefined) {
103
- entry = entry_2;
104
- } else {
105
- const entry_3 = entry_2.get(key3);
106
- if (entry_3 == undefined) {
107
- return;
108
- }
109
- entry = entry_3;
110
- }
111
- }
112
- if (entry.value) {
113
- entry.lastTimeUsed = Date.now();
114
- return entry.value;
115
- }
116
- }
117
-
118
- /**
119
- * Adds or updates an entry with specified keys (up to 3).
120
- * Caution: it overrides any existing entry already set at this/those key/s.
121
- *
122
- *
123
- * @param {Object} value to add in cache
124
- * @param {string|number} key1
125
- * @param {string|number} [key2]
126
- * @param {string|number} [key3]
127
- *
128
- * @return {Object} the added value
129
- */
130
- set(value, key1, key2, key3) {
131
- entry = {
132
- value,
133
- lastTimeUsed: Date.now()
134
- };
135
- if (key2 == undefined) {
136
- this.data.set(key1, entry);
137
- return value;
138
- }
139
- if (!this.data.get(key1)) {
140
- this.data.set(key1, new Map());
141
- }
142
- const entry_map = this.data.get(key1);
143
- if (key3 == undefined) {
144
- entry_map.set(key2, entry);
145
- return value;
146
- }
147
- if (!entry_map.get(key2)) {
148
- entry_map.set(key2, new Map());
149
- }
150
- entry_map.get(key2).set(key3, entry);
151
- return value;
152
- }
153
-
154
- /**
155
- * Deletes the specified entry from the cache.
156
- *
157
- * @param {string|number} key1
158
- * @param {string|number} [key2]
159
- * @param {string|number} [key3]
160
- */
161
- delete(key1, key2, key3) {
162
- const entry_1 = this.data.get(key1);
163
- if (entry_1 === undefined) {
164
- return;
165
- }
166
- if (entry_1.lastTimeUsed != undefined) {
167
- delete this.data.get(key1);
168
- this.data.delete(key1);
169
- } else {
170
- const entry_2 = entry_1.get(key2);
171
- if (entry_2 === undefined) {
172
- return;
173
- }
174
- if (entry_2.lastTimeUsed != undefined) {
175
- delete entry_1.get(key2);
176
- entry_1.delete(key2);
177
- if (entry_1.size == 0) {
178
- this.data.delete(key1);
179
- }
180
- } else {
181
- const entry_3 = entry_2.get(key3);
182
- if (entry_3 === undefined) {
183
- return;
184
- }
185
- delete entry_2.get(key3);
186
- entry_2.delete(key3);
187
- if (entry_2.size == 0) {
188
- entry_1.delete(key2);
189
- if (entry_1.size == 0) {
190
- this.data.delete(key1);
191
- }
192
- }
193
- }
194
- }
195
- }
196
-
197
- /**
198
- * Removes all entries of the cache.
199
- *
200
- */
201
- clear() {
202
- this.data.clear();
203
- }
204
-
205
- /**
206
- * Flush the cache: entries that have been present for too long since the
207
- * last time they were used, are removed from the cache. By default, the
208
- * time is the current time, but the interval can be reduced by doing
209
- * something like `Cache.flush(Date.now() - reductionTime)`. If you want to
210
- * clear the whole cache, use {@link Cache.clear} instead.
211
- *
212
- * @param {number} [time=Date.now()]
213
- */
214
- flush() {
215
- let time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Date.now();
216
- if (this.lifeTime == CACHE_POLICIES.INFINITE || this.lifeTime > time - this.lastTimeFlush || !this.data.size) {
217
- return;
218
- }
219
- this.lastTimeFlush = Infinity;
220
- this.data.forEach((v1, i) => {
221
- if (this.lifeTime < time - v1.lastTimeUsed) {
222
- delete this.data.get(i);
223
- this.data.delete(i);
224
- } else {
225
- v1.forEach((v2, j) => {
226
- if (this.lifeTime < time - v2.lastTimeUsed) {
227
- delete v1.get(j);
228
- v1.delete(j);
229
- } else {
230
- v2.forEach((v3, k) => {
231
- if (this.lifeTime < time - v3.lastTimeUsed) {
232
- delete v2.get(k);
233
- v2.delete(k);
234
- } else {
235
- // Work for the moment because all flushed caches have 3 key!
236
- this.lastTimeFlush = Math.min(this.lastTimeFlush, v3.lastTimeUsed);
237
- }
238
- });
239
- if (!v2.size) {
240
- delete v1.get(j);
241
- v1.delete(j);
242
- }
243
- }
244
- });
245
- if (!v1.size) {
246
- delete this.data.get(i);
247
- this.data.delete(i);
248
- }
249
- }
250
- });
251
- if (this.data.size == 0) {
252
- this.lastTimeFlush = Date.now();
253
- }
254
- }
255
- }
256
- export default Cache;
@@ -1,15 +0,0 @@
1
- /**
2
- * Custom error thrown when cancelling commands. Allows the caller to act differently if needed.
3
- * @class
4
- * @param {Command} command
5
- */
6
- class CancelledCommandException {
7
- constructor(command) {
8
- this.command = command;
9
- this.isCancelledCommandException = true;
10
- }
11
- toString() {
12
- return `Cancelled command ${this.command.requester.id}/${this.command.layer.id}`;
13
- }
14
- }
15
- export default CancelledCommandException;