1.根据2点经纬度计算2点距离(单位公里)
//经度1
let j1 = 114.3052500
let startLon = (Math.PI / 180) * j1 ;
// 纬度1
let w1 = 30.592760
let startLan = (Math.PI / 180) * w1;
for(let i = 0 ;i<10;i++){
let endLon = this.getCgGrData[i].perj //经度2
let endtLan = this.getCgGrData[i].perw //纬度2
let earthR = 6378;
let distence = Math.acos(Math.sin(startLan) * Math.sin(endtLan)+ Math.cos(startLan) * Math.cos(endtLan) * Math.cos(endLon - startLon)) * earthR;
distence = parseInt(distence)
console.log(distence,'1')
if(distence%2==0){
distence = distence
}else{
distence = distence+1
}
this.getCgGrData[i].distence = distence
}
console.log(this.getCgGrData,'距离结果')
2.根据距离计算出路线点 代码示例是计算出抛物线
for(let i = 0;i<10;i++){
let index = i
let Gldistence = this.getCgGrData[i].distence
let GLfLat = 30.592760
let GLfLng = 114.3052500
let GLtLng = ((this.getCgGrData[i].perj)/Math.PI) * 180;
let GLtLat = ((this.getCgGrData[i].perw)/Math.PI) * 180 ;
let A = []
//最高点
let maxhight = parseInt((Gldistence+1)/2)
//y=0点
let minhight = parseInt((Gldistence+1)/2)
// 常数
let constant = maxhight*600
// 系数
let coefficient = -(constant/(minhight*minhight))
let a = JSON.parse(GLfLat) / 180 * Math.PI
let b = JSON.parse(GLfLng) / 180 * Math.PI
A[0] = [b,a]
let lasttg = JSON.parse(GLtLng) / 180 * Math.PI
let lasttt = JSON.parse(GLtLat) / 180 * Math.PI
for(let i = 1;i<Gldistence+1;i++){
let fLat = Math.PI * (GLfLat) / 180.0;
let fLng = Math.PI * (GLfLng) / 180.0;
let tLat = Math.PI * (GLtLat) / 180.0;
let tLng = Math.PI * (GLtLng) / 180.0;
let degree = (Math.atan2(Math.sin(tLng - fLng) * Math.cos(tLat), Math.cos(fLat) * Math.sin(tLat) - Math.sin(fLat) * Math.cos(tLat) * Math.cos(tLng - fLng))) * 180.0 / Math.PI;
if(degree<0){
degree = 360+degree
}
let Rc=6378137
let Rj=6356725
let m_RadLo=GLfLng*Math.PI/180.;
let m_RadLa=GLfLat*Math.PI/180.;
let Ec=Rj+(Rc-Rj)*(90.- GLfLat)/90.;
let Ed=Ec*Math.cos(m_RadLa);
let dx = 1000*Math.sin(degree*(Math.PI/180));
let dy= 1000*Math.cos(degree*(Math.PI/180));
let bjd=(dx/Ed+m_RadLo)*180./Math.PI;
let bwd=(dy/Ec+m_RadLa)*180./Math.PI;
A[i] = [bwd,bjd]
GLfLat= bwd
GLfLng = bjd
let c = bwd / 180 * Math.PI
let d = bjd / 180 * Math.PI
A[i] = [d,c]
}
A[Gldistence] = [lasttg,lasttt]
A = JSON.parse(JSON.stringify(A))
console.log(A,'距离')
for(let i = 0;i<Gldistence+1;i++){
let x
if(i<maxhight){
x = maxhight - i
}else if(i>maxhight){
x = i- maxhight
}
A[i][2] = coefficient*(x*x) +constant
A[maxhight][2] = constant
}
A[0][2] = 0
A[Gldistence][2] = 0
let lestData = JSON.parse(JSON.stringify(this.LocData))
let len = lestData.length
for(let i = 0;i<len;i++){
for(let x = 0;x<A.length;x++){
lestData[i].positions.push(A[x])
}
this._earth.sceneTree.$refs.zhanyi.children[2].children[index].czmObject.data.push(lestData[i])
}
this._earth.sceneTree.$refs.zhanyi.children[2].children[index].enabled = true
this._earth.sceneTree.$refs.zhanyi.children[2].children[index].czmObject.enabled = true
console.log(this._earth.sceneTree.$refs.zhanyi)
}