@loaders.gl/3d-tiles 4.2.0-alpha.4 → 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +66 -41
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +1 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +26 -16
- package/dist/3d-tiles-archive-loader.js +25 -14
- package/dist/cesium-ion-loader.js +34 -30
- package/dist/dist.dev.js +1963 -1037
- package/dist/dist.min.js +32 -0
- package/dist/index.cjs +122 -337
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +103 -87
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +179 -155
- package/dist/lib/classes/tile-3d-batch-table.js +232 -217
- package/dist/lib/classes/tile-3d-feature-table.js +62 -59
- package/dist/lib/constants.js +19 -15
- package/dist/lib/encoders/encode-3d-tile-batched-model.js +40 -35
- package/dist/lib/encoders/encode-3d-tile-composite.js +19 -17
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js +32 -31
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js +31 -32
- package/dist/lib/encoders/encode-3d-tile.js +23 -19
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js +23 -23
- package/dist/lib/ion/ion.js +55 -54
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +57 -51
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +21 -18
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +35 -20
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -4
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +269 -234
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +2 -2
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +83 -55
- package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js +23 -14
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +82 -54
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +2 -2
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +79 -68
- package/dist/lib/parsers/helpers/parse-utils.js +19 -14
- package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-batched-model.js +21 -17
- package/dist/lib/parsers/parse-3d-tile-composite.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-composite.js +18 -14
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.js +22 -14
- package/dist/lib/parsers/parse-3d-tile-header.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-header.js +168 -159
- package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js +153 -123
- package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js +380 -174
- package/dist/lib/parsers/parse-3d-tile.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile.js +24 -24
- package/dist/lib/utils/obb/s2-corners-to-obb.js +29 -16
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +1 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.js +55 -35
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js +31 -20
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts +1 -1
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -1
- package/dist/lib/utils/s2/converters/s2-to-region.js +51 -35
- package/dist/lib/utils/s2/index.d.ts +7 -7
- package/dist/lib/utils/s2/index.d.ts.map +1 -1
- package/dist/lib/utils/s2/index.js +3 -1
- package/dist/lib/utils/s2/s2-geometry-functions.js +19 -5
- package/dist/lib/utils/s2/s2-token-functions.js +51 -22
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +1 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +23 -9
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js +218 -157
- package/dist/lib/utils/version.js +3 -1
- package/dist/tile-3d-subtree-loader.d.ts +1 -1
- package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
- package/dist/tile-3d-subtree-loader.js +15 -10
- package/dist/tile-3d-writer.js +19 -14
- package/dist/tiles-3d-loader.js +65 -55
- package/dist/types.js +3 -1
- package/package.json +11 -10
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
- package/dist/3d-tiles-archive-loader.js.map +0 -1
- package/dist/cesium-ion-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
- package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
- package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
- package/dist/lib/ion/ion.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
- package/dist/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-region.js.map +0 -1
- package/dist/lib/utils/s2/index.js.map +0 -1
- package/dist/lib/utils/s2/s2-geometry-functions.js.map +0 -1
- package/dist/lib/utils/s2/s2-token-functions.js.map +0 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/tile-3d-subtree-loader.js.map +0 -1
- package/dist/tile-3d-writer.js.map +0 -1
- package/dist/tiles-3d-loader.js.map +0 -1
- 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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 +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,
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 +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,
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
let corners
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
2
|
-
export { getS2BoundaryFlat, getS2LngLat } from
|
|
3
|
-
export { getS2Cell, getS2QuadKey } from
|
|
4
|
-
export { getS2QuadkeyFromCellId, getS2CellFromQuadKey, getS2CellIdFromQuadkey, getS2LngLatFromS2Cell } from
|
|
5
|
-
export { getS2Region } from
|
|
6
|
-
export type { S2HeightInfo } from
|
|
7
|
-
export { getS2OrientedBoundingBoxCornerPoints } from
|
|
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,
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|