Merge branch 'develop' of http://xny.yj-3d.com:3000/zh/sdk4.0 into develop

This commit is contained in:
zh
2025-07-11 09:21:38 +08:00
6 changed files with 531 additions and 177 deletions

View File

@ -139,30 +139,107 @@ class Tools {
* @param [fractionDigits=2] 保留小数点位数
* @param [ground=true] 是否贴地
* */
computeDistance(positions = [], fractionDigits = 2, 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
} 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
}
switch (type) {
case '空间长度':
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
}
break
case '投影长度':
for (let i = 0; i < positions.length - 1; i++) {
const position1 = Cesium.Cartesian3.fromDegrees(positions[i].lng, positions[i].lat, 0);
const position2 = Cesium.Cartesian3.fromDegrees(positions[i + 1].lng, positions[i + 1].lat, 0);
const distance = Cesium.Cartesian3.distance(position1, position2);
length = length + distance
}
break
case '地表长度':
let meters
let lineString2 = []
positions.forEach((item) => {
lineString2.push([item.lng, item.lat, item.alt])
})
let line2 = turf.lineString(lineString2)
let d = turf.length(line2) * 1000
meters = d > 20 ? d / 20 : d
let res = this.chunkLine(positions, meters)
let coordinates = []
res.forEach((Feature, index) => {
if (index === 0) {
coordinates = [...Feature.geometry.coordinates]
} else {
coordinates.push(Feature.geometry.coordinates[1])
}
})
let arr = []
for (const item of coordinates) {
const index = coordinates.indexOf(item);
let r = await this.sampleHeight({ lng: item[0], lat: item[1], alt: 0 }, index)
r.position.alt = r.position.alt < 0 ? 0 : r.position.alt
arr.push(r)
}
let l = arr.length - 1
arr.forEach((item, index) => {
if (index !== l) {
let posi = [item.position, arr[index + 1].position]
let d1 = 0
for (let i = 0; i < posi.length - 1; i++) {
const position1 = Cesium.Cartesian3.fromDegrees(posi[i].lng, posi[i].lat, posi[i].alt);
const position2 = Cesium.Cartesian3.fromDegrees(posi[i + 1].lng, posi[i + 1].lat, posi[i + 1].alt);
const distance = Cesium.Cartesian3.distance(position1, position2);
d1 = d1 + distance
}
let d2 = Math.abs(item.position.alt - arr[index + 1].position.alt)
let d3 = Math.sqrt(d1 * d1 + d2 * d2)
length += d3
}
})
break
default:
break;
}
return length.toFixed(fractionDigits)
}
}
async sampleHeight(p1, index) {
let p2 = await this.sampleHeightMostDetailed([p1])
p1.alt = p2[0].height
return { position: p1, index }
}
/**@description 计算多边形面积
* @method computeArea
@ -555,7 +632,6 @@ class Tools {
// dashSize: newParam.dashSize,
space: newParam.space
})
console.log(newParam.space)
break
case 6: //流动虚线2
material = new Cesium.FlowDashedLineFlowMaterialProperty({