|
|
@@ -38,9 +38,6 @@ const HALF_WORLD_SIZE = 21e6 //略大于半个周长(mapSizeM/2)
|
|
|
const MAX_VERTICAL_DIST = 2
|
|
|
const MAX_VERTICAL_DIST_TO_BEST = 1
|
|
|
|
|
|
-function defineLocalProj(locationLonLat){
|
|
|
- proj4.defs("LOCAL_MAP", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15));
|
|
|
-}
|
|
|
|
|
|
|
|
|
const getSid = (function(){
|
|
|
@@ -272,7 +269,7 @@ export class TiledMapBase extends THREE.EventDispatcher{
|
|
|
|
|
|
updateProjection(){
|
|
|
if(!this.transformMapToLocal){
|
|
|
- this.transformMapToLocal = proj4(this.projection, "LOCAL_MAP")
|
|
|
+ this.transformMapToLocal = proj4(this.projection, "LOCAL_MAP") //由地图原本的坐标转为本地坐标
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -300,7 +297,7 @@ export class TiledMapBase extends THREE.EventDispatcher{
|
|
|
|
|
|
|
|
|
|
|
|
- update(e, n){
|
|
|
+ update(frustum, sceneGroup){
|
|
|
this.computeCount = 0
|
|
|
var unavailable = (this.disabled || !this.objectGroup.visible)//地图即使不显示也要获得zoomlevel
|
|
|
if(this.name != 'map' && unavailable)return
|
|
|
@@ -309,8 +306,8 @@ export class TiledMapBase extends THREE.EventDispatcher{
|
|
|
|
|
|
if(!this.transformMapToLocal)return
|
|
|
|
|
|
- if (!this.isTileVisible(new THREE.Vector3(0,0,0), this.mapSizeM, e))
|
|
|
- return this.removeFromSceneGroup(n), !0;
|
|
|
+ if (!this.isTileVisible(new THREE.Vector3(0,0,0), this.mapSizeM, frustum))
|
|
|
+ return this.removeFromSceneGroup(sceneGroup), !0;
|
|
|
|
|
|
let viewport = this.mapLayer.viewport
|
|
|
|
|
|
@@ -321,12 +318,12 @@ export class TiledMapBase extends THREE.EventDispatcher{
|
|
|
var o = new THREE.Vector3(.5 * this.mapSizeM,0,0);
|
|
|
o.applyMatrix4(this.objectGroup.matrixWorld),
|
|
|
o.project(viewport.camera);
|
|
|
- var a = viewport.resolution.x
|
|
|
- , s = viewport.resolution.y
|
|
|
- if (a <= 0 || s <= 0 || isNaN(i.x) || isNaN(o.x)) return !1;
|
|
|
+ var rx = viewport.resolution.x
|
|
|
+ , ry = viewport.resolution.y
|
|
|
+ if (rx <= 0 || ry <= 0 || isNaN(i.x) || isNaN(o.x)) return !1;
|
|
|
i.sub(o),
|
|
|
- i.x *= a / 2,
|
|
|
- i.y *= s / 2;
|
|
|
+ i.x *= rx / 2,
|
|
|
+ i.y *= ry / 2;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -351,7 +348,7 @@ export class TiledMapBase extends THREE.EventDispatcher{
|
|
|
}
|
|
|
|
|
|
var c = this.tileSizePx / i.length() / scale //多除以一个scale缩放因子,scale越大level越小
|
|
|
- , level = Math.ceil(-Math.log(c) / Math.log(2) - this.bias);
|
|
|
+ , level = Math.ceil( -math.getBaseLog(2,c) - this.bias);
|
|
|
|
|
|
if(this.style == 'dark-standard'){ //该模式贴图比较小放大点
|
|
|
level -= 1
|
|
|
@@ -368,28 +365,28 @@ export class TiledMapBase extends THREE.EventDispatcher{
|
|
|
} */
|
|
|
|
|
|
if(!unavailable){
|
|
|
- this.addToSceneGroup(n)
|
|
|
- return this.baseTile.update(this, e, level, this.mapSizeM, 0, 0, "")
|
|
|
+ this.addToSceneGroup(sceneGroup)
|
|
|
+ return this.baseTile.update(this, frustum, level, this.mapSizeM, 0, 0, "")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- isTileVisible(e, n, i){
|
|
|
- if (n > HALF_WORLD_SIZE) return !0;
|
|
|
- var r = .5 * n;
|
|
|
+ isTileVisible(tileCenter, tileSize, frustum){
|
|
|
+ if (tileSize > HALF_WORLD_SIZE) return !0; //root must visible
|
|
|
+ var halfSize = .5 * tileSize; //在地图上的size和local的差不多是吗
|
|
|
|
|
|
//简单版:
|
|
|
- this.transformMapToLocal.forward(e) //e转化为local
|
|
|
+ this.transformMapToLocal.forward(tileCenter) //e转化为local
|
|
|
this.isTileVisibleBox.makeEmpty()
|
|
|
- this.isTileVisibleVec.set(e.x - r, e.y - r, e.z).applyMatrix4(this.objectGroup.matrixWorld)
|
|
|
+ this.isTileVisibleVec.set(tileCenter.x - halfSize, tileCenter.y - halfSize, tileCenter.z).applyMatrix4(this.objectGroup.matrixWorld)
|
|
|
this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
|
|
|
- this.isTileVisibleVec.set(e.x - r, e.y + r, e.z).applyMatrix4(this.objectGroup.matrixWorld)
|
|
|
+ this.isTileVisibleVec.set(tileCenter.x - halfSize, tileCenter.y + halfSize, tileCenter.z).applyMatrix4(this.objectGroup.matrixWorld)
|
|
|
this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
|
|
|
- this.isTileVisibleVec.set(e.x + r, e.y - r, e.z).applyMatrix4(this.objectGroup.matrixWorld)
|
|
|
+ this.isTileVisibleVec.set(tileCenter.x + halfSize, tileCenter.y - halfSize, tileCenter.z).applyMatrix4(this.objectGroup.matrixWorld)
|
|
|
this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
|
|
|
- this.isTileVisibleVec.set(e.x + r, e.y + r, e.z).applyMatrix4(this.objectGroup.matrixWorld)
|
|
|
+ this.isTileVisibleVec.set(tileCenter.x + halfSize, tileCenter.y + halfSize, tileCenter.z).applyMatrix4(this.objectGroup.matrixWorld)
|
|
|
this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
|
|
|
|
|
|
|
|
|
@@ -418,7 +415,7 @@ export class TiledMapBase extends THREE.EventDispatcher{
|
|
|
this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec) */
|
|
|
|
|
|
|
|
|
- return i.intersectsBox(this.isTileVisibleBox)
|
|
|
+ return frustum.intersectsBox(this.isTileVisibleBox)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -465,6 +462,9 @@ const loadDone = (tile, success)=>{
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
function addLoadTile(tile){
|
|
|
/* if(tile.texURL && tile.texURL.includes('testdata') ){
|
|
|
console.error('addLoadTile', tile.texURL.split('map_tiles/')[1] )
|
|
|
@@ -546,21 +546,21 @@ export class MapTile{
|
|
|
this.children = []
|
|
|
this.id = getSid();
|
|
|
}
|
|
|
- update(e, n, i, r, o, a, s){
|
|
|
- return !!this.doesNotContainTilesToBeDisplayed(e) || (0 === i ? this.updateTile(e, r, o, a) : this.updateSubTiles(e, n, i, r, o, a, s))
|
|
|
- }
|
|
|
+ update(entity, frustum, level, tileSize, centerX, centerY, treeStr){
|
|
|
+ return !!this.doesNotContainTilesToBeDisplayed(entity) || (0 === level ? this.updateTileLeaf(entity, tileSize, centerX, centerY ) : this.updateSubTiles(entity, frustum, level, tileSize, centerX, centerY, treeStr))
|
|
|
+ }
|
|
|
|
|
|
- doesNotContainTilesToBeDisplayed(t){
|
|
|
- return t.tilePresenceMap && t.tilePresenceMap.empty
|
|
|
+ doesNotContainTilesToBeDisplayed(entity){
|
|
|
+ return entity.tilePresenceMap && entity.tilePresenceMap.empty
|
|
|
}
|
|
|
|
|
|
- updateTile(t, e, n, i){ //真正显示mesh的是这一层,最高level
|
|
|
+ updateTileLeaf(entity, tileSize, centerX, centerY ){ //真正显示mesh的是这一层,最高level
|
|
|
|
|
|
- //if(this.map.name.includes('floorplan'))console.log('updateTile',this.name)
|
|
|
+ //if(this.map.name.includes('floorplan'))console.log('updateTileLeaf',this.name)
|
|
|
|
|
|
|
|
|
if(!this.mesh){
|
|
|
- this.createTileObject(t, e, n, i)
|
|
|
+ this.createTileObject(entity, tileSize, centerX, centerY )
|
|
|
}
|
|
|
if(!this.meshAdded){
|
|
|
this.objectGroup.add(this.mesh)
|
|
|
@@ -575,26 +575,28 @@ export class MapTile{
|
|
|
return this.textureLoaded
|
|
|
}
|
|
|
|
|
|
- updateSubTiles(entity, n, level, o, a, s, c){
|
|
|
+ updateSubTiles(entity, frustum, level, tileSize, centerX, centerY, treeStr){
|
|
|
//if(entity.name.includes('floorplan'))console.log('updateSubTiles',this.name) //名字越长代表level越高
|
|
|
|
|
|
-
|
|
|
- for (var childrenLoaded = !0, u = [-.25 * o, .25 * o, -.25 * o, .25 * o], d = [.25 * o, .25 * o, -.25 * o, -.25 * o], p = 0; p < 4; ++p){
|
|
|
- var h = c + p.toString(10);
|
|
|
+ let shiftX = [-.25 * tileSize, .25 * tileSize, -.25 * tileSize, .25 * tileSize],
|
|
|
+ shiftY = [ .25 * tileSize, .25 * tileSize, -.25 * tileSize, -.25 * tileSize]
|
|
|
+
|
|
|
+ for (var childrenLoaded = !0, p = 0; p < 4; ++p){
|
|
|
+ var childTreeStr = treeStr + p.toString(10);
|
|
|
//一级(512):0 1 2 3分别为左上、右上、左下、右下。二级(1024)就是把一级的每一块分裂,如00 01 02 03分别是0的左上、右上、左下、右下……
|
|
|
|
|
|
- if (!entity.tilePresenceMap || entity.tilePresenceMap[h]){
|
|
|
+ if (!entity.tilePresenceMap || entity.tilePresenceMap[childTreeStr]){
|
|
|
//去掉判断,直接显示
|
|
|
- var f = a + u[p]
|
|
|
- , m = s + d[p];
|
|
|
- tempVector.set(f, m, 0);
|
|
|
+ var childCenterX = centerX + shiftX[p]
|
|
|
+ , childCenterY = centerY + shiftY[p];
|
|
|
+ tempVector.set(childCenterX, childCenterY, 0);
|
|
|
this.map.computeCount ++
|
|
|
//console.log(this.map.computeCount, this.name, 'level:',level)
|
|
|
|
|
|
- if (entity.isTileVisible(tempVector, .5 * o, n)){
|
|
|
+ if (entity.isTileVisible(tempVector, .5 * tileSize, frustum)){
|
|
|
this.children[p] || (this.children[p] = new MapTile(this.map, this.objectGroup,this.tileColor, this, this.name+p ))
|
|
|
- //childrenLoaded = childrenLoaded && this.children[p].update(entity, n, level - 1, .5 * o, f, m, h) //这句会使若有一个tile还在加载,就阻断了。原版是这么写的。但是为了加快加载速度,改成下面两行。感觉直接全部updateTile也没太卡,不知道很大的场景会不会卡,单帧updateTile次数超过100次的话(应该不会吧,地图大小会限制住个数) -- 2023.12
|
|
|
- let childLoaded = this.children[p].update(entity, n, level - 1, .5 * o, f, m, h)
|
|
|
+ //childrenLoaded = childrenLoaded && this.children[p].update(entity, frustum, level - 1, .5 * tileSize, childCenterX, childCenterY, childTreeStr) //这句会使若有一个tile还在加载,就阻断了。原版是这么写的。但是为了加快加载速度,改成下面两行。感觉直接全部updateTile也没太卡,不知道很大的场景会不会卡,单帧updateTile次数超过100次的话(应该不会吧,地图大小会限制住个数) -- 2023.12
|
|
|
+ let childLoaded = this.children[p].update(entity, frustum, level - 1, .5 * tileSize, childCenterX, childCenterY, childTreeStr)
|
|
|
childrenLoaded = childrenLoaded && childLoaded
|
|
|
} else {
|
|
|
if (this.children[p]){
|
|
|
@@ -616,19 +618,18 @@ export class MapTile{
|
|
|
|
|
|
|
|
|
|
|
|
- */
|
|
|
-
|
|
|
- createTileObject(t, e, n, a){
|
|
|
+ */
|
|
|
+ createTileObject(entity, tileSize, centerXatMap, centerYatMap){
|
|
|
var s = this;
|
|
|
- this.mesh = this.createMesh(t.transformMapToLocal, e, n, a),
|
|
|
+ this.mesh = this.createMesh(entity.transformMapToLocal,tileSize, centerXatMap, centerYatMap),
|
|
|
this.textureLoaded = !1;
|
|
|
- var c = t.mapSizeM / e
|
|
|
- , l = Math.log(c) / Math.log(2)
|
|
|
- , u = n / e + .5 * (c - 1)
|
|
|
- , d = -a / e + .5 * (c - 1)
|
|
|
- , p = t.getTileUrl(Math.round(l), Math.round(u), Math.round(d));
|
|
|
+ var c = entity.mapSizeM / tileSize
|
|
|
+ , z = math.getBaseLog(2,c) //以2为底c的对数
|
|
|
+ , x = centerXatMap / tileSize + .5 * (c - 1)
|
|
|
+ , y = -centerYatMap / tileSize + .5 * (c - 1)
|
|
|
+ , p = entity.getTileUrl(Math.round(x), Math.round(y), Math.round(z));
|
|
|
Potree.Utils.setObjectLayers(this.mesh, 'map' )
|
|
|
- this.mesh.renderOrder = -(1e6 - l - 100 * (t.zIndex || 0));
|
|
|
+ this.mesh.renderOrder = -(1e6 - z - 100 * (entity.zIndex || 0));
|
|
|
this.mesh.name = this.name //add
|
|
|
this.texURL = p
|
|
|
|
|
|
@@ -641,16 +642,16 @@ export class MapTile{
|
|
|
|
|
|
}
|
|
|
|
|
|
- createMesh(t, e, n, o){
|
|
|
+ createMesh(transform, tileSize, centerXatMap, centerYatMap){
|
|
|
var a = new THREE.Geometry;
|
|
|
- return tempVector.set(n - e / 2, o - e / 2, 0),
|
|
|
- a.vertices.push(new THREE.Vector3().copy(t.forward(tempVector))),
|
|
|
- tempVector.set(n + e / 2, o - e / 2, 0),
|
|
|
- a.vertices.push(new THREE.Vector3().copy(t.forward(tempVector))),
|
|
|
- tempVector.set(n + e / 2, o + e / 2, 0),
|
|
|
- a.vertices.push(new THREE.Vector3().copy(t.forward(tempVector))),
|
|
|
- tempVector.set(n - e / 2, o + e / 2, 0),
|
|
|
- a.vertices.push(new THREE.Vector3().copy(t.forward(tempVector))),
|
|
|
+ return tempVector.set(centerXatMap - tileSize / 2, centerYatMap - tileSize / 2, 0),
|
|
|
+ a.vertices.push(new THREE.Vector3().copy(transform.forward(tempVector))),
|
|
|
+ tempVector.set(centerXatMap + tileSize / 2, centerYatMap - tileSize / 2, 0),
|
|
|
+ a.vertices.push(new THREE.Vector3().copy(transform.forward(tempVector))),
|
|
|
+ tempVector.set(centerXatMap + tileSize / 2, centerYatMap + tileSize / 2, 0),
|
|
|
+ a.vertices.push(new THREE.Vector3().copy(transform.forward(tempVector))),
|
|
|
+ tempVector.set(centerXatMap - tileSize / 2, centerYatMap + tileSize / 2, 0),
|
|
|
+ a.vertices.push(new THREE.Vector3().copy(transform.forward(tempVector))),
|
|
|
a.faces.push(face1),
|
|
|
a.faces.push(face2),
|
|
|
a.faceVertexUvs[0].push(face1UV),
|
|
|
@@ -763,8 +764,8 @@ export class TiledMapOpenStreetMap extends TiledMapBase{
|
|
|
|
|
|
}
|
|
|
|
|
|
- getTileUrl(t, e, n){
|
|
|
- return this.baseUrl.replace(/\${z}/, t.toString(10)).replace(/\${x}/, e.toString(10)).replace(/\${y}/, n.toString(10))
|
|
|
+ getTileUrl(x, y, z){
|
|
|
+ return this.baseUrl.replace(/\${x}/, x.toString(10)).replace(/\${y}/, y.toString(10)).replace(/\${z}/, z.toString(10))
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -826,8 +827,8 @@ export class TiledMapOpenStreetMap extends TiledMapBase{
|
|
|
this.baseUrl = "https://wprd01.is.autonavi.com/appmaptile?lang=zh_cn&style=8&yrs=m&x=${x}&y=${y}&z=${z}" //路网 加上scl=2后去掉名字
|
|
|
}else{
|
|
|
this.maxDepth = 19
|
|
|
- this.baseUrl = "https://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&style=7&yrs=m&x=${x}&y=${y}&z=${z}" //
|
|
|
-
|
|
|
+ this.baseUrl = "https://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&style=7&yrs=m&x=${x}&y=${y}&z=${z}" //加这个才会精细lang=zh_cn
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}//详解 https://www.cnblogs.com/lucio110/p/17310054.html
|
|
|
@@ -931,8 +932,8 @@ export class TiledMapFromEntity extends TiledMapBase{
|
|
|
return typeof(this.pointcloud.orientationUser ) == 'number' ? this.tiledMapEntity.orientation : this.pointcloud.orientationUser.clone()
|
|
|
}
|
|
|
|
|
|
- getTileUrl(t, e, n) {
|
|
|
- var i = (this.tiledMapEntity.filePath + "/" + this.tiledMapEntity.fileName).replace(/\$DEPTH/g, t.toString(10)).replace(/\$X/g, e.toString(10)).replace(/\$Y/g, n.toString(10));
|
|
|
+ getTileUrl(x,y,z) {
|
|
|
+ var i = (this.tiledMapEntity.filePath + "/" + this.tiledMapEntity.fileName).replace(/\$DEPTH/g, z.toString(10)).replace(/\$X/g, x.toString(10)).replace(/\$Y/g, y.toString(10));
|
|
|
return i += "?t=" + this.postStamp
|
|
|
//this.RestService.addAuthorizationQueryParameter(i) //????
|
|
|
}
|