From 4518fa2dbf1349692f48e2d5de862b3e36109e73 Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Mon, 1 Apr 2019 19:55:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=93=A6=E7=89=87=E5=B1=82=E7=BA=A7=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E5=88=B0=E7=9B=B8=E6=9C=BA=E8=B7=9D=E7=A6=BB=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/gis/tile/SphereTileCreator.js | 25 ++++++++++++------- ShadowEditor.Web/src/gis/utils/MathUtils.js | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ShadowEditor.Web/src/gis/tile/SphereTileCreator.js b/ShadowEditor.Web/src/gis/tile/SphereTileCreator.js index 5b08712f..4cce03b6 100644 --- a/ShadowEditor.Web/src/gis/tile/SphereTileCreator.js +++ b/ShadowEditor.Web/src/gis/tile/SphereTileCreator.js @@ -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; diff --git a/ShadowEditor.Web/src/gis/utils/MathUtils.js b/ShadowEditor.Web/src/gis/utils/MathUtils.js index b3fc5b66..c1332d47 100644 --- a/ShadowEditor.Web/src/gis/utils/MathUtils.js +++ b/ShadowEditor.Web/src/gis/utils/MathUtils.js @@ -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();