@loaders.gl/3d-tiles 4.2.0-alpha.4 → 4.2.0-alpha.6

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 (144) hide show
  1. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +68 -41
  2. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +1 -1
  3. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -1
  4. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +26 -16
  5. package/dist/3d-tiles-archive-loader.js +26 -15
  6. package/dist/cesium-ion-loader.js +34 -30
  7. package/dist/dist.dev.js +8824 -6420
  8. package/dist/dist.min.js +32 -0
  9. package/dist/index.cjs +138 -340
  10. package/dist/index.cjs.map +7 -0
  11. package/dist/index.d.ts +13 -13
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +7 -1
  14. package/dist/lib/classes/helpers/tile-3d-accessor-utils.d.ts +1 -1
  15. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +103 -87
  16. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +179 -155
  17. package/dist/lib/classes/tile-3d-batch-table.d.ts +1 -1
  18. package/dist/lib/classes/tile-3d-batch-table.js +241 -217
  19. package/dist/lib/classes/tile-3d-feature-table.js +64 -59
  20. package/dist/lib/constants.js +19 -15
  21. package/dist/lib/encoders/encode-3d-tile-batched-model.js +40 -35
  22. package/dist/lib/encoders/encode-3d-tile-composite.js +19 -17
  23. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +32 -31
  24. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +31 -32
  25. package/dist/lib/encoders/encode-3d-tile.js +23 -19
  26. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +23 -23
  27. package/dist/lib/ion/ion.js +55 -54
  28. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +1 -1
  29. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -1
  30. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +57 -51
  31. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +1 -1
  32. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -1
  33. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +21 -18
  34. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +35 -20
  35. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -4
  36. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
  37. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +269 -234
  38. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +2 -2
  39. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
  40. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +83 -55
  41. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +1 -1
  42. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -1
  43. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +23 -14
  44. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +1 -1
  45. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
  46. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +82 -54
  47. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +2 -2
  48. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -1
  49. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +79 -68
  50. package/dist/lib/parsers/helpers/parse-utils.js +19 -14
  51. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +2 -2
  52. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -1
  53. package/dist/lib/parsers/parse-3d-tile-batched-model.js +21 -17
  54. package/dist/lib/parsers/parse-3d-tile-composite.d.ts +2 -2
  55. package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
  56. package/dist/lib/parsers/parse-3d-tile-composite.js +18 -14
  57. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
  58. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
  59. package/dist/lib/parsers/parse-3d-tile-gltf.js +22 -14
  60. package/dist/lib/parsers/parse-3d-tile-header.d.ts +2 -2
  61. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
  62. package/dist/lib/parsers/parse-3d-tile-header.js +168 -159
  63. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +2 -2
  64. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
  65. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +153 -123
  66. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +2 -2
  67. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
  68. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +380 -174
  69. package/dist/lib/parsers/parse-3d-tile.d.ts +2 -2
  70. package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
  71. package/dist/lib/parsers/parse-3d-tile.js +24 -24
  72. package/dist/lib/utils/obb/s2-corners-to-obb.js +29 -16
  73. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +1 -1
  74. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -1
  75. package/dist/lib/utils/s2/converters/s2-to-boundary.js +55 -35
  76. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +31 -20
  77. package/dist/lib/utils/s2/converters/s2-to-region.d.ts +1 -1
  78. package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -1
  79. package/dist/lib/utils/s2/converters/s2-to-region.js +51 -35
  80. package/dist/lib/utils/s2/index.d.ts +7 -7
  81. package/dist/lib/utils/s2/index.d.ts.map +1 -1
  82. package/dist/lib/utils/s2/index.js +3 -1
  83. package/dist/lib/utils/s2/s2-geometry-functions.js +19 -5
  84. package/dist/lib/utils/s2/s2-token-functions.js +51 -22
  85. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +1 -1
  86. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -1
  87. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +23 -9
  88. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +218 -157
  89. package/dist/lib/utils/version.js +4 -2
  90. package/dist/tile-3d-subtree-loader.d.ts +1 -1
  91. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  92. package/dist/tile-3d-subtree-loader.js +15 -10
  93. package/dist/tile-3d-writer.js +19 -14
  94. package/dist/tiles-3d-loader.js +65 -55
  95. package/dist/types.js +3 -1
  96. package/package.json +17 -12
  97. package/src/lib/parsers/helpers/parse-3d-implicit-tiles.ts +1 -1
  98. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
  99. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
  100. package/dist/3d-tiles-archive-loader.js.map +0 -1
  101. package/dist/cesium-ion-loader.js.map +0 -1
  102. package/dist/index.js.map +0 -1
  103. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
  104. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
  105. package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
  106. package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
  107. package/dist/lib/constants.js.map +0 -1
  108. package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
  109. package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
  110. package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
  111. package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
  112. package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
  113. package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
  114. package/dist/lib/ion/ion.js.map +0 -1
  115. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
  116. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
  117. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
  118. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
  119. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
  120. package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
  121. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
  122. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
  123. package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
  124. package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
  125. package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
  126. package/dist/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
  127. package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
  128. package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
  129. package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
  130. package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
  131. package/dist/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
  132. package/dist/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
  133. package/dist/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
  134. package/dist/lib/utils/s2/converters/s2-to-region.js.map +0 -1
  135. package/dist/lib/utils/s2/index.js.map +0 -1
  136. package/dist/lib/utils/s2/s2-geometry-functions.js.map +0 -1
  137. package/dist/lib/utils/s2/s2-token-functions.js.map +0 -1
  138. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
  139. package/dist/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
  140. package/dist/lib/utils/version.js.map +0 -1
  141. package/dist/tile-3d-subtree-loader.js.map +0 -1
  142. package/dist/tile-3d-writer.js.map +0 -1
  143. package/dist/tiles-3d-loader.js.map +0 -1
  144. package/dist/types.js.map +0 -1
@@ -1,3 +1,8 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT AND Apache-2.0
3
+ // Copyright vis.gl contributors
4
+ // This file is derived from the Cesium code base under Apache 2 license
5
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
1
6
  import { TILE3D_TYPE } from "../constants.js";
2
7
  import { getMagicString } from "./helpers/parse-utils.js";
3
8
  import { parsePointCloud3DTile } from "./parse-3d-tile-point-cloud.js";
@@ -5,28 +10,23 @@ import { parseBatchedModel3DTile } from "./parse-3d-tile-batched-model.js";
5
10
  import { parseInstancedModel3DTile } from "./parse-3d-tile-instanced-model.js";
6
11
  import { parseComposite3DTile } from "./parse-3d-tile-composite.js";
7
12
  import { parseGltf3DTile } from "./parse-3d-tile-gltf.js";
8
- export async function parse3DTile(arrayBuffer) {
9
- let byteOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
10
- let options = arguments.length > 2 ? arguments[2] : undefined;
11
- let context = arguments.length > 3 ? arguments[3] : undefined;
12
- let tile = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
13
- shape: 'tile3d'
14
- };
15
- tile.byteOffset = byteOffset;
16
- tile.type = getMagicString(arrayBuffer, byteOffset);
17
- switch (tile.type) {
18
- case TILE3D_TYPE.COMPOSITE:
19
- return await parseComposite3DTile(tile, arrayBuffer, byteOffset, options, context, parse3DTile);
20
- case TILE3D_TYPE.BATCHED_3D_MODEL:
21
- return await parseBatchedModel3DTile(tile, arrayBuffer, byteOffset, options, context);
22
- case TILE3D_TYPE.GLTF:
23
- return await parseGltf3DTile(tile, arrayBuffer, options, context);
24
- case TILE3D_TYPE.INSTANCED_3D_MODEL:
25
- return await parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context);
26
- case TILE3D_TYPE.POINT_CLOUD:
27
- return await parsePointCloud3DTile(tile, arrayBuffer, byteOffset, options, context);
28
- default:
29
- throw new Error(`3DTileLoader: unknown type ${tile.type}`);
30
- }
13
+ // Extracts
14
+ export async function parse3DTile(arrayBuffer, byteOffset = 0, options, context, tile = { shape: 'tile3d' }) {
15
+ tile.byteOffset = byteOffset;
16
+ tile.type = getMagicString(arrayBuffer, byteOffset);
17
+ switch (tile.type) {
18
+ case TILE3D_TYPE.COMPOSITE:
19
+ // Note: We pass this function as argument so that embedded tiles can be parsed recursively
20
+ return await parseComposite3DTile(tile, arrayBuffer, byteOffset, options, context, parse3DTile);
21
+ case TILE3D_TYPE.BATCHED_3D_MODEL:
22
+ return await parseBatchedModel3DTile(tile, arrayBuffer, byteOffset, options, context);
23
+ case TILE3D_TYPE.GLTF:
24
+ return await parseGltf3DTile(tile, arrayBuffer, options, context);
25
+ case TILE3D_TYPE.INSTANCED_3D_MODEL:
26
+ return await parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context);
27
+ case TILE3D_TYPE.POINT_CLOUD:
28
+ return await parsePointCloud3DTile(tile, arrayBuffer, byteOffset, options, context);
29
+ default:
30
+ throw new Error(`3DTileLoader: unknown type ${tile.type}`); // eslint-disable-line
31
+ }
31
32
  }
32
- //# sourceMappingURL=parse-3d-tile.js.map
@@ -1,23 +1,36 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  import { Vector3 } from '@math.gl/core';
2
5
  import { makeOrientedBoundingBoxFromPoints } from '@math.gl/culling';
3
6
  import { getS2OrientedBoundingBoxCornerPoints } from "../../utils/s2/index.js";
4
7
  import { getS2LngLat } from "../../utils/s2/index.js";
5
8
  import { Ellipsoid } from '@math.gl/geospatial';
9
+ /**
10
+ * Converts S2VolumeInfo to OrientedBoundingBox
11
+ * @param {S2VolumeInfo} s2VolumeInfo - s2 volume to convert
12
+ * @returns Oriented Bounding Box of type Box
13
+ */
6
14
  export function convertS2BoundingVolumetoOBB(s2VolumeInfo) {
7
- const token = s2VolumeInfo.token;
8
- const heightInfo = {
9
- minimumHeight: s2VolumeInfo.minimumHeight,
10
- maximumHeight: s2VolumeInfo.maximumHeight
11
- };
12
- const corners = getS2OrientedBoundingBoxCornerPoints(token, heightInfo);
13
- const center = getS2LngLat(token);
14
- const centerLng = center[0];
15
- const centerLat = center[1];
16
- const point = Ellipsoid.WGS84.cartographicToCartesian([centerLng, centerLat, heightInfo.maximumHeight]);
17
- const centerPointAdditional = new Vector3(point[0], point[1], point[2]);
18
- corners.push(centerPointAdditional);
19
- const obb = makeOrientedBoundingBoxFromPoints(corners);
20
- const box = [...obb.center, ...obb.halfAxes];
21
- return box;
15
+ const token = s2VolumeInfo.token;
16
+ const heightInfo = {
17
+ minimumHeight: s2VolumeInfo.minimumHeight,
18
+ maximumHeight: s2VolumeInfo.maximumHeight
19
+ };
20
+ const corners = getS2OrientedBoundingBoxCornerPoints(token, heightInfo);
21
+ // Add a point that doesn't allow the box dive under the Earth
22
+ const center = getS2LngLat(token);
23
+ const centerLng = center[0];
24
+ const centerLat = center[1];
25
+ const point = Ellipsoid.WGS84.cartographicToCartesian([
26
+ centerLng,
27
+ centerLat,
28
+ heightInfo.maximumHeight
29
+ ]);
30
+ const centerPointAdditional = new Vector3(point[0], point[1], point[2]);
31
+ corners.push(centerPointAdditional);
32
+ // corners should be an array of Vector3 (XYZ)
33
+ const obb = makeOrientedBoundingBoxFromPoints(corners);
34
+ const box = [...obb.center, ...obb.halfAxes];
35
+ return box;
22
36
  }
23
- //# sourceMappingURL=s2-corners-to-obb.js.map
@@ -1,4 +1,4 @@
1
- import type { S2Cell } from '../s2geometry/s2-geometry';
1
+ import type { S2Cell } from "../s2geometry/s2-geometry.js";
2
2
  /**
3
3
  * Get a polygon with corner coordinates for an S2 cell
4
4
  * @param s2cell {S2Cell} S2 cell
@@ -1 +1 @@
1
- {"version":3,"file":"s2-to-boundary.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/s2/converters/s2-to-boundary.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,2BAA2B,CAAC;AAKtD;;;;;GAKG;AAEH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAsDxE"}
1
+ {"version":3,"file":"s2-to-boundary.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/s2/converters/s2-to-boundary.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,qCAAkC;AAKtD;;;;;GAKG;AAEH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAsDxE"}
@@ -1,40 +1,60 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  import { IJToST, STToUV, FaceUVToXYZ, XYZToLngLat } from "../s2geometry/s2-geometry.js";
2
5
  const MAX_RESOLUTION = 100;
6
+ /**
7
+ * Get a polygon with corner coordinates for an S2 cell
8
+ * @param s2cell {S2Cell} S2 cell
9
+ * @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
10
+ * - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
11
+ */
12
+ // eslint-disable-next-line max-statements
3
13
  export function getS2BoundaryFlatFromS2Cell(s2cell) {
4
- const {
5
- face,
6
- ij,
7
- level
8
- } = s2cell;
9
- const offsets = [[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]];
10
- const resolution = Math.max(1, Math.ceil(MAX_RESOLUTION * Math.pow(2, -level)));
11
- const result = new Float64Array(4 * resolution * 2 + 2);
12
- let ptIndex = 0;
13
- let prevLng = 0;
14
- for (let i = 0; i < 4; i++) {
15
- const offset = offsets[i].slice(0);
16
- const nextOffset = offsets[i + 1];
17
- const stepI = (nextOffset[0] - offset[0]) / resolution;
18
- const stepJ = (nextOffset[1] - offset[1]) / resolution;
19
- for (let j = 0; j < resolution; j++) {
20
- offset[0] += stepI;
21
- offset[1] += stepJ;
22
- const st = IJToST(ij, level, offset);
23
- const uv = STToUV(st);
24
- const xyz = FaceUVToXYZ(face, uv);
25
- const lngLat = XYZToLngLat(xyz);
26
- if (Math.abs(lngLat[1]) > 89.999) {
27
- lngLat[0] = prevLng;
28
- }
29
- const deltaLng = lngLat[0] - prevLng;
30
- lngLat[0] += deltaLng > 180 ? -360 : deltaLng < -180 ? 360 : 0;
31
- result[ptIndex++] = lngLat[0];
32
- result[ptIndex++] = lngLat[1];
33
- prevLng = lngLat[0];
14
+ const { face, ij, level } = s2cell;
15
+ const offsets = [
16
+ [0, 0],
17
+ [0, 1],
18
+ [1, 1],
19
+ [1, 0],
20
+ [0, 0]
21
+ ];
22
+ // The S2 cell edge is curved: http://s2geometry.io/
23
+ // This is more prominent at lower levels
24
+ // resolution is the number of segments to generate per edge.
25
+ // We exponentially reduce resolution as level increases so it doesn't affect perf
26
+ // when there are a large number of cells
27
+ const resolution = Math.max(1, Math.ceil(MAX_RESOLUTION * Math.pow(2, -level)));
28
+ const result = new Float64Array(4 * resolution * 2 + 2);
29
+ let ptIndex = 0;
30
+ let prevLng = 0;
31
+ for (let i = 0; i < 4; i++) {
32
+ const offset = offsets[i].slice(0);
33
+ const nextOffset = offsets[i + 1];
34
+ const stepI = (nextOffset[0] - offset[0]) / resolution;
35
+ const stepJ = (nextOffset[1] - offset[1]) / resolution;
36
+ for (let j = 0; j < resolution; j++) {
37
+ offset[0] += stepI;
38
+ offset[1] += stepJ;
39
+ // Cell can be represented by coordinates IJ, ST, UV, XYZ
40
+ // http://s2geometry.io/devguide/s2cell_hierarchy#coordinate-systems
41
+ const st = IJToST(ij, level, offset);
42
+ const uv = STToUV(st);
43
+ const xyz = FaceUVToXYZ(face, uv);
44
+ const lngLat = XYZToLngLat(xyz);
45
+ // Adjust longitude for Web Mercator projection
46
+ if (Math.abs(lngLat[1]) > 89.999) {
47
+ lngLat[0] = prevLng;
48
+ }
49
+ const deltaLng = lngLat[0] - prevLng;
50
+ lngLat[0] += deltaLng > 180 ? -360 : deltaLng < -180 ? 360 : 0;
51
+ result[ptIndex++] = lngLat[0];
52
+ result[ptIndex++] = lngLat[1];
53
+ prevLng = lngLat[0];
54
+ }
34
55
  }
35
- }
36
- result[ptIndex++] = result[0];
37
- result[ptIndex++] = result[1];
38
- return result;
56
+ // close the loop
57
+ result[ptIndex++] = result[0];
58
+ result[ptIndex++] = result[1];
59
+ return result;
39
60
  }
40
- //# sourceMappingURL=s2-to-boundary.js.map
@@ -1,24 +1,35 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  import { getS2Cell } from "../s2geometry/s2-cell-utils.js";
2
5
  import { getS2Region } from "./s2-to-region.js";
3
6
  import { Vector3 } from '@math.gl/core';
4
- export function getS2OrientedBoundingBoxCornerPoints(tokenOrKey, heightInfo) {
5
- const min = (heightInfo === null || heightInfo === void 0 ? void 0 : heightInfo.minimumHeight) || 0;
6
- const max = (heightInfo === null || heightInfo === void 0 ? void 0 : heightInfo.maximumHeight) || 0;
7
- const s2cell = getS2Cell(tokenOrKey);
8
- const region = getS2Region(s2cell);
9
- const W = region.west;
10
- const S = region.south;
11
- const E = region.east;
12
- const N = region.north;
13
- const points = [];
14
- points.push(new Vector3(W, N, min));
15
- points.push(new Vector3(E, N, min));
16
- points.push(new Vector3(E, S, min));
17
- points.push(new Vector3(W, S, min));
18
- points.push(new Vector3(W, N, max));
19
- points.push(new Vector3(E, N, max));
20
- points.push(new Vector3(E, S, max));
21
- points.push(new Vector3(W, S, max));
22
- return points;
7
+ /**
8
+ * Converts S2HeightInfo to corner points of an oriented bounding box
9
+ * Can be used to constuct an OrientedBoundingBox instance
10
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
11
+ * @param heightInfo {S2HeightInfo} min and max height of the box
12
+ * @returns corner points of the oriented bounding box
13
+ */
14
+ export function getS2OrientedBoundingBoxCornerPoints(tokenOrKey, // This can be an S2 key or token
15
+ heightInfo) {
16
+ const min = heightInfo?.minimumHeight || 0;
17
+ const max = heightInfo?.maximumHeight || 0;
18
+ const s2cell = getS2Cell(tokenOrKey);
19
+ const region = getS2Region(s2cell);
20
+ // region lng/lat are in degrees
21
+ const W = region.west;
22
+ const S = region.south;
23
+ const E = region.east;
24
+ const N = region.north;
25
+ const points = [];
26
+ points.push(new Vector3(W, N, min));
27
+ points.push(new Vector3(E, N, min));
28
+ points.push(new Vector3(E, S, min));
29
+ points.push(new Vector3(W, S, min));
30
+ points.push(new Vector3(W, N, max));
31
+ points.push(new Vector3(E, N, max));
32
+ points.push(new Vector3(E, S, max));
33
+ points.push(new Vector3(W, S, max));
34
+ return points;
23
35
  }
24
- //# sourceMappingURL=s2-to-obb-points.js.map
@@ -1,4 +1,4 @@
1
- import type { S2Cell } from '../s2geometry/s2-geometry';
1
+ import type { S2Cell } from "../s2geometry/s2-geometry.js";
2
2
  /**
3
3
  * Converts S2 cell to the 2D region
4
4
  * @param s2cell {S2Cell} S2 cell to convert to 2D region
@@ -1 +1 @@
1
- {"version":3,"file":"s2-to-region.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/s2/converters/s2-to-region.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,2BAA2B,CAAC;AAItD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAqBA"}
1
+ {"version":3,"file":"s2-to-region.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/s2/converters/s2-to-region.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,qCAAkC;AAItD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAqBA"}
@@ -1,42 +1,58 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  import { getS2BoundaryFlatFromS2Cell } from "./s2-to-boundary.js";
2
5
  import { getS2Cell } from "../s2geometry/s2-cell-utils.js";
6
+ /**
7
+ * Converts S2 cell to the 2D region
8
+ * @param s2cell {S2Cell} S2 cell to convert to 2D region
9
+ * @returns 2D region as an object containing: west, north, east, south in degrees
10
+ */
3
11
  export function getS2Region(s2cell) {
4
- let region;
5
- if (s2cell.face === 2 || s2cell.face === 5) {
6
- let corners = null;
7
- let len = 0;
8
- for (let i = 0; i < 4; i++) {
9
- const key = `${s2cell.face}/${i}`;
10
- const cell = getS2Cell(key);
11
- const corns = getS2BoundaryFlatFromS2Cell(cell);
12
- if (typeof corners === 'undefined' || corners === null) corners = new Float64Array(4 * corns.length);
13
- corners.set(corns, len);
14
- len += corns.length;
12
+ let region;
13
+ if (s2cell.face === 2 || s2cell.face === 5) {
14
+ // let corners: Float64Array;
15
+ let corners = null;
16
+ let len = 0;
17
+ for (let i = 0; i < 4; i++) {
18
+ const key = `${s2cell.face}/${i}`;
19
+ const cell = getS2Cell(key);
20
+ const corns = getS2BoundaryFlatFromS2Cell(cell);
21
+ if (typeof corners === 'undefined' || corners === null)
22
+ corners = new Float64Array(4 * corns.length);
23
+ corners.set(corns, len);
24
+ len += corns.length;
25
+ }
26
+ region = get2DRegionFromS2Corners(corners);
15
27
  }
16
- region = get2DRegionFromS2Corners(corners);
17
- } else {
18
- const corners = getS2BoundaryFlatFromS2Cell(s2cell);
19
- region = get2DRegionFromS2Corners(corners);
20
- }
21
- return region;
28
+ else {
29
+ const corners = getS2BoundaryFlatFromS2Cell(s2cell);
30
+ region = get2DRegionFromS2Corners(corners);
31
+ }
32
+ return region;
22
33
  }
34
+ /**
35
+ * Converts the S2 cell defined by its corners to the 2D region
36
+ * @param corners {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
37
+ * @returns 2D region as an object containing: west, north, east, south in degrees
38
+ */
23
39
  function get2DRegionFromS2Corners(corners) {
24
- if (corners.length % 2 !== 0) {
25
- throw new Error('Invalid corners');
26
- }
27
- const longitudes = [];
28
- const latitudes = [];
29
- for (let i = 0; i < corners.length; i += 2) {
30
- longitudes.push(corners[i]);
31
- latitudes.push(corners[i + 1]);
32
- }
33
- longitudes.sort((a, b) => a - b);
34
- latitudes.sort((a, b) => a - b);
35
- return {
36
- west: longitudes[0],
37
- east: longitudes[longitudes.length - 1],
38
- north: latitudes[latitudes.length - 1],
39
- south: latitudes[0]
40
- };
40
+ if (corners.length % 2 !== 0) {
41
+ throw new Error('Invalid corners');
42
+ }
43
+ const longitudes = [];
44
+ const latitudes = [];
45
+ for (let i = 0; i < corners.length; i += 2) {
46
+ longitudes.push(corners[i]);
47
+ latitudes.push(corners[i + 1]);
48
+ }
49
+ longitudes.sort((a, b) => a - b);
50
+ latitudes.sort((a, b) => a - b);
51
+ // Return the region in degrees
52
+ return {
53
+ west: longitudes[0],
54
+ east: longitudes[longitudes.length - 1],
55
+ north: latitudes[latitudes.length - 1],
56
+ south: latitudes[0]
57
+ };
41
58
  }
42
- //# sourceMappingURL=s2-to-region.js.map
@@ -1,8 +1,8 @@
1
- export { getS2CellIdFromToken, getS2TokenFromCellId, getS2ChildCellId } from './s2-token-functions';
2
- export { getS2BoundaryFlat, getS2LngLat } from './s2-geometry-functions';
3
- export { getS2Cell, getS2QuadKey } from './s2geometry/s2-cell-utils';
4
- export { getS2QuadkeyFromCellId, getS2CellFromQuadKey, getS2CellIdFromQuadkey, getS2LngLatFromS2Cell } from './s2geometry/s2-geometry';
5
- export { getS2Region } from './converters/s2-to-region';
6
- export type { S2HeightInfo } from './converters/s2-to-obb-points';
7
- export { getS2OrientedBoundingBoxCornerPoints } from './converters/s2-to-obb-points';
1
+ export { getS2CellIdFromToken, getS2TokenFromCellId, getS2ChildCellId } from "./s2-token-functions.js";
2
+ export { getS2BoundaryFlat, getS2LngLat } from "./s2-geometry-functions.js";
3
+ export { getS2Cell, getS2QuadKey } from "./s2geometry/s2-cell-utils.js";
4
+ export { getS2QuadkeyFromCellId, getS2CellFromQuadKey, getS2CellIdFromQuadkey, getS2LngLatFromS2Cell } from "./s2geometry/s2-geometry.js";
5
+ export { getS2Region } from "./converters/s2-to-region.js";
6
+ export type { S2HeightInfo } from "./converters/s2-to-obb-points.js";
7
+ export { getS2OrientedBoundingBoxCornerPoints } from "./converters/s2-to-obb-points.js";
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/s2/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,oBAAoB,EAAE,oBAAoB,EAAE,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAC,iBAAiB,EAAE,WAAW,EAAC,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAC,SAAS,EAAE,YAAY,EAAC,MAAM,4BAA4B,CAAC;AACnE,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAEtD,YAAY,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAC,oCAAoC,EAAC,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/s2/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,oBAAoB,EAAE,oBAAoB,EAAE,gBAAgB,EAAC,gCAA6B;AAClG,OAAO,EAAC,iBAAiB,EAAE,WAAW,EAAC,mCAAgC;AAEvE,OAAO,EAAC,SAAS,EAAE,YAAY,EAAC,sCAAmC;AACnE,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACtB,oCAAiC;AAElC,OAAO,EAAC,WAAW,EAAC,qCAAkC;AAEtD,YAAY,EAAC,YAAY,EAAC,yCAAsC;AAChE,OAAO,EAAC,oCAAoC,EAAC,yCAAsC"}
@@ -1,7 +1,9 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  export { getS2CellIdFromToken, getS2TokenFromCellId, getS2ChildCellId } from "./s2-token-functions.js";
2
5
  export { getS2BoundaryFlat, getS2LngLat } from "./s2-geometry-functions.js";
3
6
  export { getS2Cell, getS2QuadKey } from "./s2geometry/s2-cell-utils.js";
4
7
  export { getS2QuadkeyFromCellId, getS2CellFromQuadKey, getS2CellIdFromQuadkey, getS2LngLatFromS2Cell } from "./s2geometry/s2-geometry.js";
5
8
  export { getS2Region } from "./converters/s2-to-region.js";
6
9
  export { getS2OrientedBoundingBoxCornerPoints } from "./converters/s2-to-obb-points.js";
7
- //# sourceMappingURL=index.js.map
@@ -1,12 +1,26 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  import { getS2BoundaryFlatFromS2Cell } from "./converters/s2-to-boundary.js";
2
5
  import { getS2LngLatFromS2Cell } from "./s2geometry/s2-geometry.js";
3
6
  import { getS2Cell } from "./s2geometry/s2-cell-utils.js";
7
+ // GEOMETRY
8
+ /**
9
+ * Retrieve S2 geometry center
10
+ * @param s2Token {string} A string that is the cell's hex token
11
+ * @returns {[number, number]} Longitude and Latitude coordinates of the S2 cell's center
12
+ */
4
13
  export function getS2LngLat(s2Token) {
5
- const s2cell = getS2Cell(s2Token);
6
- return getS2LngLatFromS2Cell(s2cell);
14
+ const s2cell = getS2Cell(s2Token);
15
+ return getS2LngLatFromS2Cell(s2cell);
7
16
  }
17
+ /**
18
+ * Get a polygon with corner coordinates for an s2 cell
19
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
20
+ * @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
21
+ * - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
22
+ */
8
23
  export function getS2BoundaryFlat(tokenOrKey) {
9
- const s2cell = getS2Cell(tokenOrKey);
10
- return getS2BoundaryFlatFromS2Cell(s2cell);
24
+ const s2cell = getS2Cell(tokenOrKey);
25
+ return getS2BoundaryFlatFromS2Cell(s2cell);
11
26
  }
12
- //# sourceMappingURL=s2-geometry-functions.js.map
@@ -1,32 +1,61 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  import Long from 'long';
2
5
  const MAXIMUM_TOKEN_LENGTH = 16;
6
+ /**
7
+ * Convert the S2 token to the S2 cell ID
8
+ * @param token {string} A string that is the cell's hex token. Zero cell ID is represented as 'X'.
9
+ * @returns {Long} Cell id that is a 64-bit encoding of a face and a Hilbert curve parameter on that face.
10
+ * See {@link https://github.com/google/s2-geometry-library-java/blob/c04b68bf3197a9c34082327eeb3aec7ab7c85da1/src/com/google/common/geometry/S2CellId.java#L439} for more information
11
+ */
3
12
  export function getS2CellIdFromToken(token) {
4
- if (token === 'X') {
5
- token = '';
6
- }
7
- const paddedToken = token.padEnd(MAXIMUM_TOKEN_LENGTH, '0');
8
- return Long.fromString(paddedToken, true, 16);
13
+ if (token === 'X') {
14
+ token = '';
15
+ }
16
+ // pad token with zeros to make the length 16 that is defined in MAXIMUM_TOKEN_LENGTH
17
+ const paddedToken = token.padEnd(MAXIMUM_TOKEN_LENGTH, '0');
18
+ return Long.fromString(paddedToken, true, 16); // Hex base
9
19
  }
20
+ /**
21
+ * Convert the S2 cell ID to the S2 token
22
+ * @param cellId {Long} A 64-bit encoding of a face and a Hilbert curve parameter on that face.
23
+ * @returns {string} A string that is the cell's hex token. Zero cell ID is represented as 'X'.
24
+ */
10
25
  export function getS2TokenFromCellId(cellId) {
11
- if (cellId.isZero()) {
12
- return 'X';
13
- }
14
- let numZeroDigits = cellId.countTrailingZeros();
15
- const remainder = numZeroDigits % 4;
16
- numZeroDigits = (numZeroDigits - remainder) / 4;
17
- const trailingZeroHexChars = numZeroDigits;
18
- numZeroDigits *= 4;
19
- const x = cellId.shiftRightUnsigned(numZeroDigits);
20
- const hexString = x.toString(16).replace(/0+$/, '');
21
- const zeroString = Array(17 - trailingZeroHexChars - hexString.length).join('0');
22
- return zeroString + hexString;
26
+ if (cellId.isZero()) {
27
+ return 'X';
28
+ }
29
+ let numZeroDigits = cellId.countTrailingZeros();
30
+ const remainder = numZeroDigits % 4;
31
+ numZeroDigits = (numZeroDigits - remainder) / 4;
32
+ const trailingZeroHexChars = numZeroDigits;
33
+ numZeroDigits *= 4;
34
+ const x = cellId.shiftRightUnsigned(numZeroDigits);
35
+ const hexString = x.toString(16).replace(/0+$/, '');
36
+ const zeroString = Array(17 - trailingZeroHexChars - hexString.length).join('0');
37
+ return zeroString + hexString;
23
38
  }
39
+ /**
40
+ * Get one of four S2 cell's children.
41
+ * @param cellId {Long} A 64-bit encoding of a face and a Hilbert curve parameter on that face.
42
+ * The cell must NOT be a leaf one. So, the cell's level is in the range [0-29].
43
+ * @param index {number} Child index defines one of four S2 cell's children. Must be in the range [0-3].
44
+ * @returns The ID of the cell's child.
45
+ */
24
46
  export function getS2ChildCellId(cellId, index) {
25
- const newLsb = lsb(cellId).shiftRightUnsigned(2);
26
- const childCellId = cellId.add(Long.fromNumber(2 * index + 1 - 4).multiply(newLsb));
27
- return childCellId;
47
+ // Shift sentinel bit 2 positions to the right.
48
+ const newLsb = lsb(cellId).shiftRightUnsigned(2);
49
+ // Insert child index before the sentinel bit.
50
+ const childCellId = cellId.add(Long.fromNumber(2 * index + 1 - 4).multiply(newLsb));
51
+ return childCellId;
28
52
  }
53
+ /**
54
+ * Return the lowest-numbered bit that is on for this cell id.
55
+ * @private
56
+ * @param cellId {Long} Cell id.
57
+ * @returns {Long} The lowest-numbered bit that is on for this cell id.
58
+ */
29
59
  function lsb(cellId) {
30
- return cellId.and(cellId.not().add(1));
60
+ return cellId.and(cellId.not().add(1)); // eslint-disable-line
31
61
  }
32
- //# sourceMappingURL=s2-token-functions.js.map
@@ -1,4 +1,4 @@
1
- import type { S2Cell } from './s2-geometry';
1
+ import type { S2Cell } from "./s2-geometry.js";
2
2
  /**
3
3
  * Return the S2Cell from the cell's hex token or the Hilbert quad key
4
4
  * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
@@ -1 +1 @@
1
- {"version":3,"file":"s2-cell-utils.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/s2/s2geometry/s2-cell-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAM1C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAIpD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAQvD"}
1
+ {"version":3,"file":"s2-cell-utils.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/s2/s2geometry/s2-cell-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,yBAAsB;AAM1C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAIpD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAQvD"}
@@ -1,15 +1,29 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  import { getS2CellFromQuadKey, getS2QuadkeyFromCellId } from "./s2-geometry.js";
2
5
  import { getS2CellIdFromToken } from "../s2-token-functions.js";
6
+ /**
7
+ * Return the S2Cell from the cell's hex token or the Hilbert quad key
8
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
9
+ * @returns {@link S2Cell}
10
+ */
3
11
  export function getS2Cell(tokenOrKey) {
4
- const key = getS2QuadKey(tokenOrKey);
5
- const s2cell = getS2CellFromQuadKey(key);
6
- return s2cell;
12
+ const key = getS2QuadKey(tokenOrKey);
13
+ const s2cell = getS2CellFromQuadKey(key);
14
+ return s2cell;
7
15
  }
16
+ /**
17
+ * Get the underlying Hilbert quad key
18
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
19
+ * @returns Hilbert quad key
20
+ */
8
21
  export function getS2QuadKey(tokenOrKey) {
9
- if (tokenOrKey.indexOf('/') > 0) {
10
- return tokenOrKey;
11
- }
12
- const id = getS2CellIdFromToken(tokenOrKey);
13
- return getS2QuadkeyFromCellId(id);
22
+ if (tokenOrKey.indexOf('/') > 0) {
23
+ // is Hilbert quad key
24
+ return tokenOrKey;
25
+ }
26
+ // is S2 cell's hex token
27
+ const id = getS2CellIdFromToken(tokenOrKey);
28
+ return getS2QuadkeyFromCellId(id);
14
29
  }
15
- //# sourceMappingURL=s2-cell-utils.js.map