瓦片层级根据到相机距离变化。

This commit is contained in:
tengge1 2019-04-01 19:55:03 +08:00
parent 53324c01ba
commit 4518fa2dbf
2 changed files with 17 additions and 10 deletions

View File

@ -12,8 +12,6 @@ function SphereTileCreator(camera) {
TileCreator.call(this, camera);
this.cache = new Map();
this.center = new THREE.Vector3();
this.tiles = [];
}
@ -23,9 +21,6 @@ SphereTileCreator.prototype.constructor = SphereTileCreator;
SphereTileCreator.prototype.get = function () {
this.tiles.length = 0;
MathUtils._xyzToLonlat(this.camera.position, this.center);
this.center.z = 0;
this.fork(0, 0, 0);
return this.tiles;
@ -56,11 +51,23 @@ SphereTileCreator.prototype.fork = function (x, y, z) {
}
};
SphereTileCreator.prototype.canFork = function (tile) {
var distance = MathUtils._getDistance(this.center.x, this.center.y, tile._center.x, tile._center.y);
SphereTileCreator.prototype.canFork = function () {
var xyz = new THREE.Vector3();
return tile.z <= 1;
};
return function (tile) {
if (tile.z <= 1) {
return true;
}
MathUtils._lonlatToXYZ(tile._center, xyz);
var distance = this.camera.position.distanceTo(xyz);
var zoom = MathUtils.altToZoom(distance) + 2;
return tile.z <= zoom;
};
}();
SphereTileCreator.prototype.dispose = function () {
this.tiles.length = 0;

View File

@ -10,7 +10,7 @@ const MAX_PROJECTED_COORD = 20037508.3427892; // 墨卡托最大投影坐标(
function _lonlatToXYZ(lonlat, xyz) {
var lon = lonlat.x;
var lat = lonlat.y;
var r = WGS84.a + lonlat.z;
var r = WGS84.a + (lonlat.z || 0);
if (xyz === undefined) {
xyz = new THREE.Vector3();