|
@@ -3,7 +3,7 @@ import * as THREE from "../../libs/three.js/build/three.module.js";
|
|
|
import {Utils} from "../utils.js";
|
|
|
import { EventDispatcher } from "../EventDispatcher.js";
|
|
|
import Sprite from '../viewer/Sprite'
|
|
|
-
|
|
|
+import Common from "../utils/Common.js";
|
|
|
|
|
|
const texLoader = new THREE.TextureLoader()
|
|
|
const arrowSpacing = 1 //间隔
|
|
@@ -175,7 +175,7 @@ export class RouteGuider extends EventDispatcher{
|
|
|
setArrowDir(arrows,index){
|
|
|
let arrow = arrows[index]
|
|
|
var nextOne = arrows[index+1];
|
|
|
- var nextPos = nextOne ? nextOne.position : this.routeEnd
|
|
|
+ var nextPos = nextOne ? nextOne.position : this.endPolePos //routeEnd
|
|
|
var direction = new THREE.Vector3().subVectors(arrow.position, nextPos).setZ(0);
|
|
|
//direction.normalize();
|
|
|
//console.log(direction.toArray())
|
|
@@ -188,35 +188,38 @@ export class RouteGuider extends EventDispatcher{
|
|
|
|
|
|
|
|
|
|
|
|
- setRouteStart(pos, dealMapZ, ifReset){
|
|
|
+ setRouteStart(pos, dealMapZ ){
|
|
|
if(this.routeStart && pos && this.routeStart.equals(pos)) return //可能重复设置
|
|
|
this.routeStart = pos && new THREE.Vector3().copy(pos)
|
|
|
//if(dealMapZ && this.routeStart) this.routeStart.setZ(0)//后端要求设置为0,但设置后反而得不到了。直接用的是接近boundingbox.min.z的值
|
|
|
- console.log('setRouteStart',ifReset,this.routeStart&&this.routeStart.toArray())
|
|
|
-
|
|
|
- if(ifReset){
|
|
|
- this.bus && this.bus.emit('reposStartMarker', pos)
|
|
|
- }else{
|
|
|
- this.generateRoute()
|
|
|
- }
|
|
|
+ console.log('setRouteStart',this.routeStart&&this.routeStart.toArray())
|
|
|
+
|
|
|
+
|
|
|
+ this.generateRoute()
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
+ setStartPole(pos){
|
|
|
+ this.startPolePos = pos
|
|
|
+ this.bus && this.bus.emit('reposStartMarker', pos)
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- setRouteEnd(pos, dealMapZ, ifReset){
|
|
|
+ setRouteEnd(pos, dealMapZ ){
|
|
|
if(this.routeEnd && pos && this.routeEnd.equals(pos)) return
|
|
|
this.routeEnd = pos && new THREE.Vector3().copy(pos)
|
|
|
//if(dealMapZ && this.routeEnd) this.routeEnd.setZ(0)//后端要求设置为0
|
|
|
- console.log('setRouteEnd',ifReset,this.routeEnd&&this.routeEnd.toArray())
|
|
|
+ console.log('setRouteEnd',this.routeEnd&&this.routeEnd.toArray())
|
|
|
+
|
|
|
+
|
|
|
+ this.generateRoute()
|
|
|
|
|
|
- if(ifReset){
|
|
|
- this.bus && this.bus.emit('reposEndMarker', pos)
|
|
|
- }else{
|
|
|
- this.generateRoute()
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
+ setEndPole(pos){
|
|
|
+ this.endPolePos = pos
|
|
|
+ this.bus && this.bus.emit('reposEndMarker', pos)
|
|
|
+ }
|
|
|
|
|
|
getSourceProjectionIndex(route) {//真正的起始
|
|
|
var e = route.findIndex(function(t) {
|
|
@@ -233,6 +236,7 @@ export class RouteGuider extends EventDispatcher{
|
|
|
|
|
|
generateRoute(){
|
|
|
if(!this.routeStart || !this.routeEnd){
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -260,7 +264,7 @@ export class RouteGuider extends EventDispatcher{
|
|
|
this.updateMapArrows()
|
|
|
this.displayRoute()
|
|
|
|
|
|
- {
|
|
|
+ {//map focus on this area
|
|
|
|
|
|
const minBound = new THREE.Vector2(1,1)//针对垂直线,在地图上只有一个点
|
|
|
let bound = new THREE.Box2;
|
|
@@ -268,7 +272,13 @@ export class RouteGuider extends EventDispatcher{
|
|
|
bound.expandByPoint(e)
|
|
|
})
|
|
|
let size = bound.getSize(new THREE.Vector2)
|
|
|
- let margin = viewer.mapViewer.viewports[0].resolution2.clone().multiplyScalar(0.01)
|
|
|
+ let markerSize = new THREE.Vector2(115,40) //起始和终点的标识呈长方形
|
|
|
+ let areaSize = viewer.mapViewer.viewports[0].resolution2
|
|
|
+ let areaArea = areaSize.x * areaSize.y
|
|
|
+ if(areaArea> 800 * 400){//是放大的
|
|
|
+ markerSize.multiplyScalar(areaArea / (800 * 400) /* / (size.x * size.y) */)
|
|
|
+ }
|
|
|
+ let margin = size.clone().divide(viewer.mapViewer.viewports[0].resolution2).multiply(markerSize) ///边距 重点是起始和终点的标识占据较大
|
|
|
size.add(margin)
|
|
|
let center = bound.getCenter(new THREE.Vector2)
|
|
|
|
|
@@ -287,19 +297,28 @@ export class RouteGuider extends EventDispatcher{
|
|
|
if(Potree.fileServer){
|
|
|
let dealData = (data)=>{
|
|
|
|
|
|
- if(!data){
|
|
|
+ if(!data.data){
|
|
|
console.log('没有数据')
|
|
|
- this.bus && this.bus.emit('gotResult','没有数据')
|
|
|
+ let result
|
|
|
+ if(data && data.code == 4002){
|
|
|
+ result = data;//正被修改数据集
|
|
|
+ }else{
|
|
|
+ result = { code: 500, msg: '超出数据集范围,无法规划路线' }
|
|
|
+ }
|
|
|
+ this.clearRoute()
|
|
|
+ this.bus && this.bus.emit('gotResult', result )
|
|
|
|
|
|
return //this.generateDeferred && this.generateDeferred.resolve()
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ data = data.data
|
|
|
|
|
|
this.clearRoute()
|
|
|
let length = data.length
|
|
|
|
|
|
- if(length == 0){//可能距离太短
|
|
|
- console.log('路径点数为0,直接取起点和终点连线')
|
|
|
+ if(length < 2){//可能距离太短
|
|
|
+ console.log('路径点数为'+length+',直接取起点和终点连线')
|
|
|
this.route = [this.routeStart, this.routeEnd];
|
|
|
}else{
|
|
|
let startIndex = this.getSourceProjectionIndex(data)
|
|
@@ -315,8 +334,8 @@ export class RouteGuider extends EventDispatcher{
|
|
|
|
|
|
console.log(this.route)
|
|
|
|
|
|
- this.setRouteStart(this.route[0],false, true)
|
|
|
- this.setRouteEnd(this.route[this.route.length-1],false,true)
|
|
|
+ this.setStartPole(this.route[0])
|
|
|
+ this.setEndPole(this.route[this.route.length-1])
|
|
|
}
|
|
|
create()
|
|
|
/*
|
|
@@ -334,21 +353,20 @@ export class RouteGuider extends EventDispatcher{
|
|
|
|
|
|
|
|
|
|
|
|
- if(this.lastResult){
|
|
|
- let data, use; //直接用上次的结果
|
|
|
+ if(this.lastResult && (this.lastResult.data || this.lastResult.data.code != 4002)){//正被修改数据集的话要重新计算
|
|
|
+ let data = Common.CloneObject(this.lastResult.data) , use; //直接用上次的结果
|
|
|
if(this.lastResult.routeStart.equals(this.routeStart) && this.lastResult.routeEnd.equals(this.routeEnd)){//和上次请求相同
|
|
|
- use = true
|
|
|
- data = this.lastResult.data
|
|
|
-
|
|
|
+ use = true
|
|
|
}else if(this.lastResult.routeStart.equals(this.routeEnd) && this.lastResult.routeEnd.equals(this.routeStart)){//..反向
|
|
|
use = true
|
|
|
- data = this.lastResult.data.slice(0).reverse()
|
|
|
+ if(data.data){
|
|
|
+ data.data = this.lastResult.data.data.slice(0).reverse()
|
|
|
+ }
|
|
|
}
|
|
|
if(use){
|
|
|
console.log('直接用上次的结果')
|
|
|
return setTimeout(()=>{dealData(data)}, 1)//延迟是为了等待获得 RouteGuider.generateDeferred
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -381,10 +399,11 @@ export class RouteGuider extends EventDispatcher{
|
|
|
this.lastResult = {//保存数据
|
|
|
routeStart : this.routeStart.clone(),
|
|
|
routeEnd: this.routeEnd.clone(),
|
|
|
- data : data.data
|
|
|
+ data,
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- dealData(data.data)
|
|
|
+ dealData(data)
|
|
|
|
|
|
})
|
|
|
|
|
@@ -439,8 +458,8 @@ export class RouteGuider extends EventDispatcher{
|
|
|
displayRoute(o={}){
|
|
|
if(!o.resetMap){
|
|
|
|
|
|
- this.poleStart.position.copy(this.routeStart)
|
|
|
- this.poleEnd.position.copy(this.routeEnd)
|
|
|
+ this.poleStart.position.copy(this.startPolePos || this.routeStart)
|
|
|
+ this.poleEnd.position.copy(this.endPolePos || this.routeEnd)
|
|
|
/* this.mapMarkStart.position.copy(this.routeStart).setZ(0)
|
|
|
this.mapMarkEnd.position.copy(this.routeEnd).setZ(0) */
|
|
|
this.scenePoints.forEach(e=>this.addArrow(e))
|
|
@@ -472,6 +491,7 @@ export class RouteGuider extends EventDispatcher{
|
|
|
|
|
|
this.sceneMeshGroup.visible = false
|
|
|
this.mapMeshGroup.visible = false
|
|
|
+ viewer.mapViewer.dispatchEvent({'type':'content_changed'})
|
|
|
}
|
|
|
|
|
|
clear(){//退出
|