修改线空间长度选择
This commit is contained in:
@ -277,18 +277,29 @@ class PolylineObject extends Base {
|
||||
this._elms.wordsName.forEach(item => {
|
||||
item.value = v
|
||||
})
|
||||
if (this.options.lengthByMeter) {
|
||||
switch (v) {
|
||||
case '空间长度':
|
||||
break
|
||||
case '投影长度':
|
||||
break
|
||||
case '地表长度':
|
||||
break
|
||||
default:
|
||||
break
|
||||
|
||||
let _this = this
|
||||
|
||||
if (!this.noseToTail) {
|
||||
this.computeDistance(
|
||||
this.options.positions,
|
||||
2,
|
||||
v
|
||||
).then(res => {
|
||||
_this.options.lengthByMeter = res
|
||||
if (res > 1000 || res == 1000) {
|
||||
_this.length = (res / 1000).toFixed(5)
|
||||
_this.lengthUnit = '千米'
|
||||
} else {
|
||||
_this.length = res
|
||||
_this.lengthUnit = '米'
|
||||
}
|
||||
|
||||
})
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
get fitLengthUnit() {
|
||||
@ -538,11 +549,11 @@ class PolylineObject extends Base {
|
||||
break
|
||||
}
|
||||
|
||||
this.options.lengthByMeter = this.computeDistance(
|
||||
this.options.positions,
|
||||
2,
|
||||
ground
|
||||
)
|
||||
// this.options.lengthByMeter = this.computeDistance(
|
||||
// this.options.positions,
|
||||
// 2,
|
||||
// ground
|
||||
// )
|
||||
this.lengthUnit = this.lengthUnit
|
||||
this._elms.heightMode && (this._elms.heightMode.value = heightModeName)
|
||||
this._elms.heightModeObject && (this._elms.heightModeObject.legp_searchActive(
|
||||
@ -1330,12 +1341,18 @@ class PolylineObject extends Base {
|
||||
PolylineObject.createLabel(that)
|
||||
// that.entity.polyline.positionsLngLat = positions
|
||||
that.renewPolygon(fromDegreesArray)
|
||||
that.options.lengthByMeter = that.computeDistance(positions, 2, ground)
|
||||
that.computeDistance(
|
||||
positions,
|
||||
2
|
||||
).then(res => {
|
||||
that.options.lengthByMeter = res
|
||||
that.lengthUnit = that.options['length-unit']
|
||||
syncData(that.sdk, that.options.id)
|
||||
if (that.options.show) {
|
||||
setSplitDirection(0, that.options.id)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// if (this.options['nose-to-tail']) {
|
||||
// let array = []
|
||||
@ -2150,21 +2167,39 @@ class PolylineObject extends Base {
|
||||
alt: fromDegreesArray[i + 2]
|
||||
})
|
||||
}
|
||||
this.options.fitLengthByMeter = this.computeDistance(
|
||||
// this.options.fitLengthByMeter = this.computeDistance(
|
||||
// array,
|
||||
// 2,
|
||||
// ground
|
||||
// )
|
||||
let _this = this
|
||||
this.computeDistance(
|
||||
array,
|
||||
2,
|
||||
ground
|
||||
)
|
||||
this.options['words-name']
|
||||
).then(res => {
|
||||
_this.options.fitLengthByMeter
|
||||
})
|
||||
} else {
|
||||
this.options.fitLengthByMeter = this.computeDistance(
|
||||
let _this = this
|
||||
this.computeDistance(
|
||||
positions,
|
||||
2,
|
||||
ground
|
||||
)
|
||||
this.options['words-name']
|
||||
).then(res => {
|
||||
_this.options.fitLengthByMeter
|
||||
})
|
||||
}
|
||||
this.fitLengthUnit = this.options['fit-length-unit']
|
||||
this.options.lengthByMeter = this.computeDistance(positions, 2, ground)
|
||||
this.lengthUnit = this.options['length-unit']
|
||||
let _this = this
|
||||
this.computeDistance(
|
||||
positions,
|
||||
2,
|
||||
this.options['words-name']
|
||||
).then(res => {
|
||||
_this.options.lengthByMeter
|
||||
_this.lengthUnit = this.options['length-unit']
|
||||
})
|
||||
return fromDegreesArray
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
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({
|
||||
|
Reference in New Issue
Block a user