@loaders.gl/tiles 4.0.0-alpha.8 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/dist.min.js +144 -80
  2. package/dist/es5/tileset/tileset-3d.js.map +1 -1
  3. package/dist/es5/tileset/tileset-traverser.js +1 -1
  4. package/dist/es5/tileset/tileset-traverser.js.map +1 -1
  5. package/dist/esm/tileset/tileset-3d.js.map +1 -1
  6. package/dist/esm/tileset/tileset-traverser.js +1 -1
  7. package/dist/esm/tileset/tileset-traverser.js.map +1 -1
  8. package/dist/tileset/tileset-3d.d.ts.map +1 -1
  9. package/package.json +5 -5
  10. package/src/tileset/tileset-3d.ts +1 -0
  11. package/src/tileset/tileset-traverser.ts +1 -1
  12. package/dist/bundle.js +0 -5
  13. package/dist/constants.js +0 -39
  14. package/dist/index.js +0 -26
  15. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js +0 -54
  16. package/dist/tileset/format-i3s/i3s-pending-tiles-register.js +0 -47
  17. package/dist/tileset/format-i3s/i3s-tile-manager.js +0 -80
  18. package/dist/tileset/format-i3s/i3s-tileset-traverser.js +0 -92
  19. package/dist/tileset/helpers/3d-tiles-options.js +0 -9
  20. package/dist/tileset/helpers/bounding-volume.js +0 -293
  21. package/dist/tileset/helpers/frame-state.js +0 -133
  22. package/dist/tileset/helpers/i3s-lod.js +0 -85
  23. package/dist/tileset/helpers/tiles-3d-lod.js +0 -117
  24. package/dist/tileset/helpers/transform-utils.js +0 -53
  25. package/dist/tileset/helpers/zoom.js +0 -89
  26. package/dist/tileset/tile-3d.js +0 -610
  27. package/dist/tileset/tileset-3d.js +0 -715
  28. package/dist/tileset/tileset-cache.js +0 -72
  29. package/dist/tileset/tileset-traverser.js +0 -300
  30. package/dist/types.js +0 -2
  31. package/dist/utils/doubly-linked-list-node.js +0 -18
  32. package/dist/utils/doubly-linked-list.js +0 -97
  33. package/dist/utils/managed-array.js +0 -152
@@ -1,133 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.limitSelectedTiles = exports.getFrameState = void 0;
4
- const core_1 = require("@math.gl/core");
5
- const culling_1 = require("@math.gl/culling");
6
- const geospatial_1 = require("@math.gl/geospatial");
7
- const scratchVector = new core_1.Vector3();
8
- const scratchPosition = new core_1.Vector3();
9
- const cullingVolume = new culling_1.CullingVolume([
10
- new culling_1.Plane(),
11
- new culling_1.Plane(),
12
- new culling_1.Plane(),
13
- new culling_1.Plane(),
14
- new culling_1.Plane(),
15
- new culling_1.Plane()
16
- ]);
17
- // Extracts a frame state appropriate for tile culling from a deck.gl viewport
18
- // TODO - this could likely be generalized and merged back into deck.gl for other culling scenarios
19
- function getFrameState(viewport, frameNumber) {
20
- // Traverse and and request. Update _selectedTiles so that we know what to render.
21
- // Traverse and and request. Update _selectedTiles so that we know what to render.
22
- const { cameraDirection, cameraUp, height } = viewport;
23
- const { metersPerUnit } = viewport.distanceScales;
24
- // TODO - Ellipsoid.eastNorthUpToFixedFrame() breaks on raw array, create a Vector.
25
- // TODO - Ellipsoid.eastNorthUpToFixedFrame() takes a cartesian, is that intuitive?
26
- const viewportCenterCartesian = worldToCartesian(viewport, viewport.center);
27
- const enuToFixedTransform = geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
28
- const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
29
- const cameraPositionCartesian = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new core_1.Vector3());
30
- // These should still be normalized as the transform has scale 1 (goes from meters to meters)
31
- const cameraDirectionCartesian = new core_1.Vector3(
32
- // @ts-ignore
33
- enuToFixedTransform.transformAsVector(new core_1.Vector3(cameraDirection).scale(metersPerUnit))).normalize();
34
- const cameraUpCartesian = new core_1.Vector3(
35
- // @ts-ignore
36
- enuToFixedTransform.transformAsVector(new core_1.Vector3(cameraUp).scale(metersPerUnit))).normalize();
37
- commonSpacePlanesToWGS84(viewport);
38
- const ViewportClass = viewport.constructor;
39
- const { longitude, latitude, width, bearing, zoom } = viewport;
40
- // @ts-ignore
41
- const topDownViewport = new ViewportClass({
42
- longitude,
43
- latitude,
44
- height,
45
- width,
46
- bearing,
47
- zoom,
48
- pitch: 0
49
- });
50
- // TODO: make a file/class for frameState and document what needs to be attached to this so that traversal can function
51
- return {
52
- camera: {
53
- position: cameraPositionCartesian,
54
- direction: cameraDirectionCartesian,
55
- up: cameraUpCartesian
56
- },
57
- viewport,
58
- topDownViewport,
59
- height,
60
- cullingVolume,
61
- frameNumber,
62
- sseDenominator: 1.15 // Assumes fovy = 60 degrees
63
- };
64
- }
65
- exports.getFrameState = getFrameState;
66
- /**
67
- * Limit `tiles` array length with `maximumTilesSelected` number.
68
- * The criteria for this filtering is distance of a tile center
69
- * to the `frameState.viewport`'s longitude and latitude
70
- * @param tiles - tiles array to filter
71
- * @param frameState - frameState to calculate distances
72
- * @param maximumTilesSelected - maximal amount of tiles in the output array
73
- * @returns new tiles array
74
- */
75
- function limitSelectedTiles(tiles, frameState, maximumTilesSelected) {
76
- if (maximumTilesSelected === 0 || tiles.length <= maximumTilesSelected) {
77
- return [tiles, []];
78
- }
79
- // Accumulate distances in couples array: [tileIndex: number, distanceToViewport: number]
80
- const tuples = [];
81
- const { longitude: viewportLongitude, latitude: viewportLatitude } = frameState.viewport;
82
- for (const [index, tile] of tiles.entries()) {
83
- const [longitude, latitude] = tile.header.mbs;
84
- const deltaLon = Math.abs(viewportLongitude - longitude);
85
- const deltaLat = Math.abs(viewportLatitude - latitude);
86
- const distance = Math.sqrt(deltaLat * deltaLat + deltaLon * deltaLon);
87
- tuples.push([index, distance]);
88
- }
89
- const tuplesSorted = tuples.sort((a, b) => a[1] - b[1]);
90
- const selectedTiles = [];
91
- for (let i = 0; i < maximumTilesSelected; i++) {
92
- selectedTiles.push(tiles[tuplesSorted[i][0]]);
93
- }
94
- const unselectedTiles = [];
95
- for (let i = maximumTilesSelected; i < tuplesSorted.length; i++) {
96
- unselectedTiles.push(tiles[tuplesSorted[i][0]]);
97
- }
98
- return [selectedTiles, unselectedTiles];
99
- }
100
- exports.limitSelectedTiles = limitSelectedTiles;
101
- function commonSpacePlanesToWGS84(viewport) {
102
- // Extract frustum planes based on current view.
103
- const frustumPlanes = viewport.getFrustumPlanes();
104
- // Get the near/far plane centers
105
- const nearCenterCommon = closestPointOnPlane(frustumPlanes.near, viewport.cameraPosition);
106
- const nearCenterCartesian = worldToCartesian(viewport, nearCenterCommon);
107
- const cameraCartesian = worldToCartesian(viewport, viewport.cameraPosition, scratchPosition);
108
- let i = 0;
109
- cullingVolume.planes[i++].fromPointNormal(nearCenterCartesian, scratchVector.copy(nearCenterCartesian).subtract(cameraCartesian));
110
- for (const dir in frustumPlanes) {
111
- if (dir === 'near') {
112
- continue; // eslint-disable-line no-continue
113
- }
114
- const plane = frustumPlanes[dir];
115
- const posCommon = closestPointOnPlane(plane, nearCenterCommon, scratchPosition);
116
- const cartesianPos = worldToCartesian(viewport, posCommon, scratchPosition);
117
- cullingVolume.planes[i++].fromPointNormal(cartesianPos,
118
- // Want the normal to point into the frustum since that's what culling expects
119
- scratchVector.copy(nearCenterCartesian).subtract(cartesianPos));
120
- }
121
- }
122
- function closestPointOnPlane(plane, refPoint, out = new core_1.Vector3()) {
123
- const distanceToRef = plane.normal.dot(refPoint);
124
- out
125
- .copy(plane.normal)
126
- .scale(plane.distance - distanceToRef)
127
- .add(refPoint);
128
- return out;
129
- }
130
- function worldToCartesian(viewport, point, out = new core_1.Vector3()) {
131
- const cartographicPos = viewport.unprojectPosition(point);
132
- return geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, out);
133
- }
@@ -1,85 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getProjectedRadius = exports.getLodStatus = void 0;
5
- const core_1 = require("@math.gl/core");
6
- const geospatial_1 = require("@math.gl/geospatial");
7
- const cameraPositionCartesian = new core_1.Vector3();
8
- const toEye = new core_1.Vector3();
9
- const cameraPositionEnu = new core_1.Vector3();
10
- const extraVertexEnu = new core_1.Vector3();
11
- const projectedOriginVector = new core_1.Vector3();
12
- const enuToCartesianMatrix = new core_1.Matrix4();
13
- const cartesianToEnuMatrix = new core_1.Matrix4();
14
- /**
15
- * For the maxScreenThreshold error metric, maxError means that you should replace the node with it's children
16
- as soon as the nodes bounding sphere has a screen radius larger than maxError pixels.
17
- In this sense a value of 0 means you should always load it's children,
18
- or if it's a leaf node, you should always display it.
19
- * @param tile
20
- * @param frameState
21
- * @returns
22
- */
23
- function getLodStatus(tile, frameState) {
24
- if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
25
- return 'DIG';
26
- }
27
- const screenSize = 2 * getProjectedRadius(tile, frameState);
28
- if (screenSize < 2) {
29
- return 'OUT';
30
- }
31
- if (!tile.header.children || screenSize <= tile.lodMetricValue) {
32
- return 'DRAW';
33
- }
34
- else if (tile.header.children) {
35
- return 'DIG';
36
- }
37
- return 'OUT';
38
- }
39
- exports.getLodStatus = getLodStatus;
40
- /**
41
- * Calculate size of MBS radius projected on the screen plane
42
- * @param tile
43
- * @param frameState
44
- * @returns
45
- */
46
- // eslint-disable-next-line max-statements
47
- function getProjectedRadius(tile, frameState) {
48
- const { topDownViewport: viewport } = frameState;
49
- const mbsLat = tile.header.mbs[1];
50
- const mbsLon = tile.header.mbs[0];
51
- const mbsZ = tile.header.mbs[2];
52
- const mbsR = tile.header.mbs[3];
53
- const mbsCenterCartesian = [...tile.boundingVolume.center];
54
- const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
55
- geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, cameraPositionCartesian);
56
- // ---------------------------
57
- // Calculate mbs border vertex
58
- // ---------------------------
59
- toEye.copy(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
60
- // Add extra vector to form plane
61
- geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
62
- cartesianToEnuMatrix.copy(enuToCartesianMatrix).invert();
63
- cameraPositionEnu.copy(cameraPositionCartesian).transform(cartesianToEnuMatrix);
64
- // Mean Proportionals in Right Triangles - Altitude rule
65
- // https://mathbitsnotebook.com/Geometry/RightTriangles/RTmeanRight.html
66
- const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
67
- const extraZ = (projection * projection) / cameraPositionEnu[2];
68
- extraVertexEnu.copy([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
69
- const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
70
- const extraVectorCartesian = extraVertexCartesian.subtract(mbsCenterCartesian).normalize();
71
- // We need radius vector orthogonal to toEye vector
72
- const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
73
- const sphereMbsBorderVertexCartesian = radiusVector.add(mbsCenterCartesian);
74
- const sphereMbsBorderVertexCartographic = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
75
- // ---------------------------
76
- // Project center vertex and border vertex and calculate projected radius of MBS
77
- const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
78
- const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
79
- const projectedRadius = projectedOriginVector
80
- .copy(projectedOrigin)
81
- .subtract(projectedMbsBorderVertex)
82
- .magnitude();
83
- return projectedRadius;
84
- }
85
- exports.getProjectedRadius = getProjectedRadius;
@@ -1,117 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getTiles3DScreenSpaceError = exports.getDynamicScreenSpaceError = exports.fog = exports.calculateDynamicScreenSpaceError = void 0;
5
- // This file is derived from the Cesium code base under Apache 2 license
6
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
7
- // TODO - Dynamic screen space error provides an optimization when looking at
8
- // tilesets from above
9
- /* eslint-disable */
10
- // @ts-nocheck
11
- const core_1 = require("@math.gl/core");
12
- const scratchPositionNormal = new core_1.Vector3();
13
- const scratchCartographic = new core_1.Vector3();
14
- const scratchMatrix = new core_1.Matrix4();
15
- const scratchCenter = new core_1.Vector3();
16
- const scratchPosition = new core_1.Vector3();
17
- const scratchDirection = new core_1.Vector3();
18
- // eslint-disable-next-line max-statements, complexity
19
- function calculateDynamicScreenSpaceError(root, { camera, mapProjection }, options = {}) {
20
- const { dynamicScreenSpaceErrorHeightFalloff = 0.25, dynamicScreenSpaceErrorDensity = 0.00278 } = options;
21
- let up;
22
- let direction;
23
- let height;
24
- let minimumHeight;
25
- let maximumHeight;
26
- const tileBoundingVolume = root.contentBoundingVolume;
27
- if (tileBoundingVolume instanceof TileBoundingRegion) {
28
- up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
29
- direction = camera.directionWC;
30
- height = camera.positionCartographic.height;
31
- minimumHeight = tileBoundingVolume.minimumHeight;
32
- maximumHeight = tileBoundingVolume.maximumHeight;
33
- }
34
- else {
35
- // Transform camera position and direction into the local coordinate system of the tileset
36
- const transformLocal = core_1.Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);
37
- const ellipsoid = mapProjection.ellipsoid;
38
- const boundingVolume = tileBoundingVolume.boundingVolume;
39
- const centerLocal = core_1.Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter);
40
- if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {
41
- // The tileset is defined in WGS84. Approximate the minimum and maximum height.
42
- const centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic);
43
- up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
44
- direction = camera.directionWC;
45
- height = camera.positionCartographic.height;
46
- minimumHeight = 0.0;
47
- maximumHeight = centerCartographic.height * 2.0;
48
- }
49
- else {
50
- // The tileset is defined in local coordinates (z-up)
51
- const positionLocal = core_1.Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition);
52
- up = Cartesian3.UNIT_Z;
53
- direction = core_1.Matrix4.multiplyByPointAsVector(transformLocal, camera.directionWC, scratchDirection);
54
- direction = Cartesian3.normalize(direction, direction);
55
- height = positionLocal.z;
56
- if (tileBoundingVolume instanceof TileOrientedBoundingBox) {
57
- // Assuming z-up, the last component stores the half-height of the box
58
- const boxHeight = root._header.boundingVolume.box[11];
59
- minimumHeight = centerLocal.z - boxHeight;
60
- maximumHeight = centerLocal.z + boxHeight;
61
- }
62
- else if (tileBoundingVolume instanceof TileBoundingSphere) {
63
- const radius = boundingVolume.radius;
64
- minimumHeight = centerLocal.z - radius;
65
- maximumHeight = centerLocal.z + radius;
66
- }
67
- }
68
- }
69
- // The range where the density starts to lessen. Start at the quarter height of the tileset.
70
- const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;
71
- const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;
72
- const heightFar = maximumHeight;
73
- const t = (0, core_1.clamp)((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);
74
- // Increase density as the camera tilts towards the horizon
75
- const dot = Math.abs(Cartesian3.dot(direction, up));
76
- let horizonFactor = 1.0 - dot;
77
- // Weaken the horizon factor as the camera height increases, implying the camera is further away from the tileset.
78
- // The goal is to increase density for the "street view", not when viewing the tileset from a distance.
79
- horizonFactor = horizonFactor * (1.0 - t);
80
- return dynamicScreenSpaceErrorDensity * horizonFactor;
81
- }
82
- exports.calculateDynamicScreenSpaceError = calculateDynamicScreenSpaceError;
83
- function fog(distanceToCamera, density) {
84
- const scalar = distanceToCamera * density;
85
- return 1.0 - Math.exp(-(scalar * scalar));
86
- }
87
- exports.fog = fog;
88
- function getDynamicScreenSpaceError(tileset, distanceToCamera) {
89
- if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {
90
- const density = tileset.dynamicScreenSpaceErrorComputedDensity;
91
- const factor = tileset.dynamicScreenSpaceErrorFactor;
92
- // TODO: Refined screen space error that minimizes tiles in non-first-person
93
- const dynamicError = fog(distanceToCamera, density) * factor;
94
- return dynamicError;
95
- }
96
- return 0;
97
- }
98
- exports.getDynamicScreenSpaceError = getDynamicScreenSpaceError;
99
- function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {
100
- const tileset = tile.tileset;
101
- const parentLodMetricValue = (tile.parent && tile.parent.lodMetricValue) || tile.lodMetricValue;
102
- const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;
103
- // Leaf tiles do not have any error so save the computation
104
- if (lodMetricValue === 0.0) {
105
- return 0.0;
106
- }
107
- // TODO: Orthographic Frustum needs special treatment?
108
- // this._getOrthograhicScreenSpaceError();
109
- // Avoid divide by zero when viewer is inside the tile
110
- const distance = Math.max(tile._distanceToCamera, 1e-7);
111
- const { height, sseDenominator } = frameState;
112
- const { viewDistanceScale } = tileset.options;
113
- let error = (lodMetricValue * height * (viewDistanceScale || 1.0)) / (distance * sseDenominator);
114
- error -= getDynamicScreenSpaceError(tileset, distance);
115
- return error;
116
- }
117
- exports.getTiles3DScreenSpaceError = getTiles3DScreenSpaceError;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.calculateTransformProps = void 0;
5
- const geospatial_1 = require("@math.gl/geospatial");
6
- const core_1 = require("@math.gl/core");
7
- const loader_utils_1 = require("@loaders.gl/loader-utils");
8
- function calculateTransformProps(tileHeader, tile) {
9
- (0, loader_utils_1.assert)(tileHeader);
10
- (0, loader_utils_1.assert)(tile);
11
- const { rtcCenter, gltfUpAxis } = tile;
12
- const { computedTransform, boundingVolume: { center } } = tileHeader;
13
- let modelMatrix = new core_1.Matrix4(computedTransform);
14
- // Translate if appropriate
15
- if (rtcCenter) {
16
- modelMatrix.translate(rtcCenter);
17
- }
18
- // glTF models need to be rotated from Y to Z up
19
- // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
20
- switch (gltfUpAxis) {
21
- case 'Z':
22
- break;
23
- case 'Y':
24
- const rotationY = new core_1.Matrix4().rotateX(Math.PI / 2);
25
- modelMatrix = modelMatrix.multiplyRight(rotationY);
26
- break;
27
- case 'X':
28
- const rotationX = new core_1.Matrix4().rotateY(-Math.PI / 2);
29
- modelMatrix = modelMatrix.multiplyRight(rotationX);
30
- break;
31
- default:
32
- break;
33
- }
34
- // Scale/offset positions if normalized integers
35
- if (tile.isQuantized) {
36
- modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);
37
- }
38
- // Option 1: Cartesian matrix and origin
39
- const cartesianOrigin = new core_1.Vector3(center);
40
- tile.cartesianModelMatrix = modelMatrix;
41
- tile.cartesianOrigin = cartesianOrigin;
42
- // Option 2: Cartographic matrix and origin
43
- const cartographicOrigin = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new core_1.Vector3());
44
- const fromFixedFrameMatrix = geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);
45
- const toFixedFrameMatrix = fromFixedFrameMatrix.invert();
46
- tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);
47
- tile.cartographicOrigin = cartographicOrigin;
48
- // Deprecated, drop
49
- if (!tile.coordinateSystem) {
50
- tile.modelMatrix = tile.cartographicModelMatrix;
51
- }
52
- }
53
- exports.calculateTransformProps = calculateTransformProps;
@@ -1,89 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getZoomFromExtent = exports.getZoomFromFullExtent = exports.getZoomFromBoundingVolume = void 0;
5
- const core_1 = require("@math.gl/core");
6
- const culling_1 = require("@math.gl/culling");
7
- const geospatial_1 = require("@math.gl/geospatial");
8
- const WGS84_RADIUS_X = 6378137.0;
9
- const WGS84_RADIUS_Y = 6378137.0;
10
- const WGS84_RADIUS_Z = 6356752.3142451793;
11
- const scratchVector = new core_1.Vector3();
12
- /**
13
- * Calculate appropriate zoom value for a particular boundingVolume
14
- * @param boundingVolume - the instance of bounding volume
15
- * @param cartorgraphicCenter - cartographic center of the bounding volume
16
- * @returns {number} - zoom value
17
- */
18
- function getZoomFromBoundingVolume(boundingVolume, cartorgraphicCenter) {
19
- if (boundingVolume instanceof culling_1.OrientedBoundingBox) {
20
- // OrientedBoundingBox
21
- const { halfAxes } = boundingVolume;
22
- const obbSize = getObbSize(halfAxes);
23
- // Use WGS84_RADIUS_Z to allign with BoundingSphere algorithm
24
- // Add the tile elevation value for correct zooming to elevated tiles
25
- return Math.log2(WGS84_RADIUS_Z / (obbSize + cartorgraphicCenter[2]));
26
- }
27
- else if (boundingVolume instanceof culling_1.BoundingSphere) {
28
- // BoundingSphere
29
- const { radius } = boundingVolume;
30
- // Add the tile elevation value for correct zooming to elevated tiles
31
- return Math.log2(WGS84_RADIUS_Z / (radius + cartorgraphicCenter[2]));
32
- }
33
- else if (boundingVolume.width && boundingVolume.height) {
34
- // BoundingRectangle
35
- const { width, height } = boundingVolume;
36
- const zoomX = Math.log2(WGS84_RADIUS_X / width);
37
- const zoomY = Math.log2(WGS84_RADIUS_Y / height);
38
- return (zoomX + zoomY) / 2;
39
- }
40
- return 1;
41
- }
42
- exports.getZoomFromBoundingVolume = getZoomFromBoundingVolume;
43
- /**
44
- * Calculate initial zoom for the tileset from 3D `fullExtent` defined in
45
- * the tileset metadata
46
- * @param fullExtent - 3D extent of the tileset
47
- * @param fullExtent.xmin - minimal longitude in decimal degrees
48
- * @param fullExtent.xmax - maximal longitude in decimal degrees
49
- * @param fullExtent.ymin - minimal latitude in decimal degrees
50
- * @param fullExtent.ymax - maximal latitude in decimal degrees
51
- * @param fullExtent.zmin - minimal elevation in meters
52
- * @param fullExtent.zmax - maximal elevation in meters
53
- * @param cartorgraphicCenter - tileset center in cartographic coordinate system
54
- * @param cartesianCenter - tileset center in cartesian coordinate system
55
- * @returns - initial zoom for the tileset
56
- */
57
- function getZoomFromFullExtent(fullExtent, cartorgraphicCenter, cartesianCenter) {
58
- const extentVertex = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian([fullExtent.xmax, fullExtent.ymax, fullExtent.zmax], new core_1.Vector3());
59
- const extentSize = Math.sqrt(Math.pow(extentVertex[0] - cartesianCenter[0], 2) +
60
- Math.pow(extentVertex[1] - cartesianCenter[1], 2) +
61
- Math.pow(extentVertex[2] - cartesianCenter[2], 2));
62
- return Math.log2(WGS84_RADIUS_Z / (extentSize + cartorgraphicCenter[2]));
63
- }
64
- exports.getZoomFromFullExtent = getZoomFromFullExtent;
65
- /**
66
- * Calculate initial zoom for the tileset from 2D `extent` defined in
67
- * the tileset metadata
68
- * @param extent - 2D extent of the tileset. It is array of 4 elements [xmin, ymin, xmax, ymax]
69
- * @param extent[0] - minimal longitude in decimal degrees
70
- * @param extent[1] - minimal latitude in decimal degrees
71
- * @param extent[2] - maximal longitude in decimal degrees
72
- * @param extent[3] - maximal latitude in decimal degrees
73
- * @param cartorgraphicCenter - tileset center in cartographic coordinate system
74
- * @param cartesianCenter - tileset center in cartesian coordinate system
75
- * @returns - initial zoom for the tileset
76
- */
77
- function getZoomFromExtent(extent, cartorgraphicCenter, cartesianCenter) {
78
- const [xmin, ymin, xmax, ymax] = extent;
79
- return getZoomFromFullExtent({ xmin, xmax, ymin, ymax, zmin: 0, zmax: 0 }, cartorgraphicCenter, cartesianCenter);
80
- }
81
- exports.getZoomFromExtent = getZoomFromExtent;
82
- function getObbSize(halfAxes) {
83
- halfAxes.getColumn(0, scratchVector);
84
- const axeY = halfAxes.getColumn(1);
85
- const axeZ = halfAxes.getColumn(2);
86
- const farthestVertex = scratchVector.add(axeY).add(axeZ);
87
- const size = farthestVertex.len();
88
- return size;
89
- }