Skip to content

Commit

Permalink
Merge 76080eb into 7006abe
Browse files Browse the repository at this point in the history
  • Loading branch information
Xintong Xia committed Jul 4, 2019
2 parents 7006abe + 76080eb commit b63cb2d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 31 additions & 1 deletion modules/3d-tiles/src/tileset/tileset-3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ import Tileset3DTraverser from './tileset-3d-traverser';

// import Tileset3DCache from './tileset-3d-cache';

// TODO move to Math library?
const WGS84_RADIUS_X = 6378137.0;
const WGS84_RADIUS_Y = 6378137.0;
const WGS84_RADIUS_Z = 6356752.3142451793;

function getZoom(boundingVolume) {
const {halfAxes, radius, width, height} = boundingVolume;

if (halfAxes) {
// OrientedBoundingBox
const [x, , , , y, , , , z] = halfAxes;
const zoomX = Math.log2(WGS84_RADIUS_X / x / 2);
const zoomY = Math.log2(WGS84_RADIUS_Y / y / 2);
const zoomZ = Math.log2(WGS84_RADIUS_Z / z / 2);
return (zoomX + zoomY + zoomZ) / 3;
} else if (radius) {
// BoundingSphere
return Math.log2(WGS84_RADIUS_Z / radius);
} else if (height && width) {
// BoundingRectangle
const zoomX = Math.log2(WGS84_RADIUS_X / width);
const zoomY = Math.log2(WGS84_RADIUS_Y / height);

return (zoomX + zoomY) / 2;
}

return 18;
}

const DEFAULT_OPTIONS = {
basePath: '',

Expand Down Expand Up @@ -448,7 +477,8 @@ export default class Tileset3D {
result = result || new Vector3();
result.copy(center);
Ellipsoid.WGS84.cartesianToCartographic(result, result);
result[2] = 18;

result[2] = getZoom(root.boundingVolume);
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@luma.gl/constants": "^7.1.1",
"@luma.gl/core": "^7.1.1",
"@luma.gl/webgl": "^7.1.1",
"@probe.gl/stats-widget": "^3.0.1",
"@probe.gl/stats-widget": "^3.1.0-alpha.2",
"react": "^16.6.0",
"react-dom": "^16.6.0",
"react-map-gl": "^5.0.0",
Expand Down

0 comments on commit b63cb2d

Please sign in to comment.