距离计算
This commit is contained in:
@ -140,30 +140,6 @@ class Tools {
|
||||
* @param [fractionDigits=2] 保留小数点位数
|
||||
* @param [ground=true] 是否贴地
|
||||
* */
|
||||
// computeDistance(positions = [], fractionDigits = 2, ground = true) {
|
||||
// if (positions.length < 2) {
|
||||
// return 0
|
||||
// } else {
|
||||
// let length = 0
|
||||
// if (ground) {
|
||||
// let lineString = []
|
||||
// positions.forEach((item) => {
|
||||
// lineString.push([item.lng, item.lat, item.alt])
|
||||
// })
|
||||
// let line = turf.lineString(lineString)
|
||||
// length = turf.length(line) * 1000
|
||||
// }
|
||||
// else {
|
||||
// for (let i = 0; i < positions.length - 1; i++) {
|
||||
// const position1 = Cesium.Cartesian3.fromDegrees(positions[i].lng, positions[i].lat, positions[i].alt);
|
||||
// const position2 = Cesium.Cartesian3.fromDegrees(positions[i + 1].lng, positions[i + 1].lat, positions[i + 1].alt);
|
||||
// const distance = Cesium.Cartesian3.distance(position1, position2);
|
||||
// length = length + distance
|
||||
// }
|
||||
// }
|
||||
// return length.toFixed(fractionDigits)
|
||||
// }
|
||||
// }
|
||||
async computeDistance(positions = [], fractionDigits = 2, type = '空间长度') {
|
||||
if (positions.length < 2) {
|
||||
return 0
|
||||
@ -226,6 +202,32 @@ class Tools {
|
||||
return length.toFixed(fractionDigits)
|
||||
}
|
||||
}
|
||||
|
||||
computeDistance2(positions = [], fractionDigits = 2, ground = true) {
|
||||
if (positions.length < 2) {
|
||||
return 0
|
||||
} else {
|
||||
let length = 0
|
||||
if (ground) {
|
||||
let lineString = []
|
||||
positions.forEach((item) => {
|
||||
lineString.push([item.lng, item.lat, item.alt])
|
||||
})
|
||||
let line = turf.lineString(lineString)
|
||||
length = turf.length(line) * 1000
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < positions.length - 1; i++) {
|
||||
const position1 = Cesium.Cartesian3.fromDegrees(positions[i].lng, positions[i].lat, positions[i].alt);
|
||||
const position2 = Cesium.Cartesian3.fromDegrees(positions[i + 1].lng, positions[i + 1].lat, positions[i + 1].alt);
|
||||
const distance = Cesium.Cartesian3.distance(position1, position2);
|
||||
length = length + distance
|
||||
}
|
||||
}
|
||||
return length.toFixed(fractionDigits)
|
||||
}
|
||||
}
|
||||
|
||||
async sampleHeight(p1, index) {
|
||||
let p2 = await this.sampleHeightMostDetailed([p1])
|
||||
p1.alt = p2[0].height
|
||||
|
Reference in New Issue
Block a user