距离计算
This commit is contained in:
@ -49,7 +49,7 @@ export default class DrawCircle extends Draw {
|
||||
if (clickNum === 2) {
|
||||
radius_points = cache_points.concat(cartesian)
|
||||
endpoint = this.cartesian3Towgs84(cartesian, this.viewer)
|
||||
radius = this.computeDistance([center, endpoint])
|
||||
radius = this.computeDistance2([center, endpoint])
|
||||
positions = this.createCircle(center, radius)
|
||||
this.end()
|
||||
cb(null, { center, radius: Number(radius) })
|
||||
@ -74,7 +74,7 @@ export default class DrawCircle extends Draw {
|
||||
if (clickNum) {
|
||||
radius_points = cache_points.concat(cartesian)
|
||||
endpoint = this.cartesian3Towgs84(cartesian, this.viewer)
|
||||
radius = this.computeDistance([center, endpoint])
|
||||
radius = this.computeDistance2([center, endpoint])
|
||||
positions = this.createCircle(center, radius)
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ export default class DrawCircle extends Draw {
|
||||
if (clickNum === 2) {
|
||||
radius_points = cache_points.concat(cartesian)
|
||||
endpoint = this.cartesian3Towgs84(cartesian, this.viewer)
|
||||
radius = this.computeDistance([center, endpoint])
|
||||
radius = this.computeDistance2([center, endpoint])
|
||||
positions = this.createCircle(center, radius)
|
||||
this.end()
|
||||
cb(null, { center, radius: Number(radius) })
|
||||
@ -136,7 +136,7 @@ export default class DrawCircle extends Draw {
|
||||
if (clickNum === 2) {
|
||||
radius_points = cache_points.concat(cartesian)
|
||||
endpoint = this.cartesian3Towgs84(cartesian, this.viewer)
|
||||
radius = this.computeDistance([center, endpoint])
|
||||
radius = this.computeDistance2([center, endpoint])
|
||||
positions = this.createCircle(center, radius)
|
||||
this.end()
|
||||
cb(null, { center, radius: Number(radius) })
|
||||
@ -161,7 +161,7 @@ export default class DrawCircle extends Draw {
|
||||
if (clickNum) {
|
||||
radius_points = cache_points.concat(cartesian)
|
||||
endpoint = this.cartesian3Towgs84(cartesian, this.viewer)
|
||||
radius = this.computeDistance([center, endpoint])
|
||||
radius = this.computeDistance2([center, endpoint])
|
||||
positions = this.createCircle(center, radius)
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ export default class DrawCircle extends Draw {
|
||||
if (clickNum === 2) {
|
||||
radius_points = cache_points.concat(cartesian)
|
||||
endpoint = this.cartesian3Towgs84(cartesian, this.viewer)
|
||||
radius = this.computeDistance([center, endpoint])
|
||||
radius = this.computeDistance2([center, endpoint])
|
||||
positions = this.createCircle(center, radius)
|
||||
this.end()
|
||||
cb(null, { center, radius: Number(radius) })
|
||||
|
@ -48,7 +48,7 @@ class MeasureDistance extends Measure {
|
||||
}
|
||||
|
||||
async computeDisByTowPoint(p1, p2) {
|
||||
let d = this.computeDistance([p1, p2])
|
||||
let d = this.computeDistance2([p1, p2])
|
||||
let meters = 10
|
||||
let createLabel = (distance) => {
|
||||
if(this._isDestroy) {
|
||||
@ -80,7 +80,7 @@ class MeasureDistance extends Measure {
|
||||
let l = arr.length - 1
|
||||
arr.forEach((item, index) => {
|
||||
if (index !== l) {
|
||||
let d1 = this.computeDistance([item.position, arr[index + 1].position])
|
||||
let d1 = this.computeDistance2([item.position, arr[index + 1].position])
|
||||
let d2 = Math.abs(item.position.alt - arr[index + 1].position.alt)
|
||||
let d3 = Math.sqrt(d1 * d1 + d2 * d2)
|
||||
total_length += d3
|
||||
@ -131,7 +131,7 @@ class MeasureDistance extends Measure {
|
||||
let l = this.clampPositions.length - 1
|
||||
this.clampPositions.forEach((item, index) => {
|
||||
if (index !== l) {
|
||||
let d1 = this.computeDistance([item.position, this.clampPositions[index + 1].position])
|
||||
let d1 = this.computeDistance2([item.position, this.clampPositions[index + 1].position])
|
||||
let d2 = Math.abs(item.position.alt - this.clampPositions[index + 1].position.alt)
|
||||
let d3 = Math.sqrt(d1 * d1 + d2 * d2)
|
||||
total_length += d3
|
||||
@ -270,7 +270,7 @@ class MeasureDistance extends Measure {
|
||||
// if (this.cachePositions.length) {
|
||||
// let cur_point = this.cartesian3Towgs84(car, this.viewer)
|
||||
// let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer)
|
||||
// let cur_len = this.computeDistance([cur_point, pre_p])
|
||||
// let cur_len = this.computeDistance2([cur_point, pre_p])
|
||||
// let text = "当前投影距离:" + cur_len + " 米"
|
||||
// // this.tip.set_text(text)
|
||||
// }
|
||||
|
@ -47,7 +47,7 @@ class MeasureDistance extends Measure {
|
||||
}
|
||||
|
||||
async computeDisByTowPoint(p1, p2) {
|
||||
let d = this.computeDistance([p1, p2])
|
||||
let d = this.computeDistance2([p1, p2])
|
||||
let meters = 10
|
||||
let createLabel = (distance) => {
|
||||
let label = this.getLabel("贴地距离:" + distance.toFixed(2) + "米")
|
||||
@ -84,7 +84,7 @@ class MeasureDistance extends Measure {
|
||||
let l = arr.length - 1
|
||||
arr.forEach((item, index) => {
|
||||
if (index !== l) {
|
||||
let d1 = this.computeDistance([item.position, arr[index + 1].position])
|
||||
let d1 = this.computeDistance2([item.position, arr[index + 1].position])
|
||||
let d2 = Math.abs(item.position.alt - arr[index + 1].position.alt)
|
||||
let d3 = Math.sqrt(d1 * d1 + d2 * d2)
|
||||
total_length += d3
|
||||
@ -135,7 +135,7 @@ class MeasureDistance extends Measure {
|
||||
let l = this.clampPositions.length - 1
|
||||
this.clampPositions.forEach((item, index) => {
|
||||
if (index !== l) {
|
||||
let d1 = this.computeDistance([item.position, this.clampPositions[index + 1].position])
|
||||
let d1 = this.computeDistance2([item.position, this.clampPositions[index + 1].position])
|
||||
let d2 = Math.abs(item.position.alt - this.clampPositions[index + 1].position.alt)
|
||||
let d3 = Math.sqrt(d1 * d1 + d2 * d2)
|
||||
total_length += d3
|
||||
@ -231,7 +231,7 @@ class MeasureDistance extends Measure {
|
||||
if (this.ids.length !== 0) {
|
||||
let cur_point = this.cartesian3Towgs84(car, this.viewer)
|
||||
let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer)
|
||||
let cur_len = this.computeDistance([cur_point, pre_p])
|
||||
let cur_len = this.computeDistance2([cur_point, pre_p])
|
||||
let text = "投影距离:" + cur_len + " 米"
|
||||
this.ids.push(MeasureDistance.create_point(car, {label: this.getLabel(text)}, this))
|
||||
this.cachePositions.push(car)
|
||||
@ -250,7 +250,7 @@ class MeasureDistance extends Measure {
|
||||
if (this.cachePositions.length) {
|
||||
let cur_point = this.cartesian3Towgs84(car, this.viewer)
|
||||
let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer)
|
||||
let cur_len = this.computeDistance([cur_point, pre_p])
|
||||
let cur_len = this.computeDistance2([cur_point, pre_p])
|
||||
let text = "当前投影距离:" + cur_len + " 米"
|
||||
this.tip.set_text(text)
|
||||
}
|
||||
@ -280,7 +280,7 @@ class MeasureDistance extends Measure {
|
||||
}
|
||||
|
||||
computeAngle(start, end) {
|
||||
let d1 = this.computeDistance([start, end])
|
||||
let d1 = this.computeDistance2([start, end])
|
||||
let d2 = Math.abs(start.alt - end.alt)
|
||||
let d3 = Math.sqrt(d1 * d1 + d2 * d2)
|
||||
let cosAlpha = d1 / d3
|
||||
|
@ -128,7 +128,7 @@ class MeasureHeight extends Measure {
|
||||
this.positions[1] = Cesium.Cartesian3.fromDegrees(this.firstpoint.lng, this.firstpoint.lat, cur_point.alt)
|
||||
this.positions[2] = cartesian
|
||||
this.position = this.positions[1]
|
||||
this.circleRadius = this.computeDistance([this.firstpoint, cur_point])
|
||||
this.circleRadius = this.computeDistance2([this.firstpoint, cur_point])
|
||||
this.height = Number((cur_point.alt - this.firstpoint.alt).toFixed(2))
|
||||
this.text = "相对高度:" + this.height + " 米"
|
||||
this.tip.set_text("左键完成,右键取消;半径:" + this.circleRadius + " 米")
|
||||
@ -145,7 +145,7 @@ class MeasureHeight extends Measure {
|
||||
this.positions[1] = Cesium.Cartesian3.fromDegrees(this.firstpoint.lng, this.firstpoint.lat, cur_point.alt)
|
||||
this.positions[2] = cartesian
|
||||
this.position = this.positions[1]
|
||||
this.circleRadius = this.computeDistance([this.firstpoint, cur_point])
|
||||
this.circleRadius = this.computeDistance2([this.firstpoint, cur_point])
|
||||
this.height = Number((cur_point.alt - this.firstpoint.alt).toFixed(2))
|
||||
this.text = "相对高度:" + this.height + " 米"
|
||||
this.tip.set_text("左键完成,右键取消;半径:" + this.circleRadius + " 米")
|
||||
|
@ -73,7 +73,7 @@ class MeasureProjectionDistance extends Measure {
|
||||
let l = this.clampPositions.length - 1
|
||||
this.clampPositions.forEach((item, index) => {
|
||||
if (index !== l) {
|
||||
let d1 = this.computeDistance([item.position, this.clampPositions[index + 1].position])
|
||||
let d1 = this.computeDistance2([item.position, this.clampPositions[index + 1].position])
|
||||
let d2 = Math.abs(item.position.alt - this.clampPositions[index + 1].position.alt)
|
||||
let d3 = Math.sqrt(d1 * d1 + d2 * d2)
|
||||
total_length += d3
|
||||
@ -174,7 +174,7 @@ class MeasureProjectionDistance extends Measure {
|
||||
if (this.ids.length !== 0) {
|
||||
let cur_point = this.cartesian3Towgs84(car, this.viewer)
|
||||
let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer)
|
||||
let cur_len = this.computeDistance([cur_point, pre_p])
|
||||
let cur_len = this.computeDistance2([cur_point, pre_p])
|
||||
let text = "投影距离:" + cur_len + " 米"
|
||||
this.ids.push(MeasureProjectionDistance.create_point(car, {label: this.getLabel(text)}, this))
|
||||
this.cachePositions.push(car)
|
||||
@ -215,7 +215,7 @@ class MeasureProjectionDistance extends Measure {
|
||||
if (this.cachePositions.length) {
|
||||
let cur_point = this.cartesian3Towgs84(car, this.viewer)
|
||||
let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer)
|
||||
let cur_len = this.computeDistance([cur_point, pre_p])
|
||||
let cur_len = this.computeDistance2([cur_point, pre_p])
|
||||
let text = "当前投影距离:" + cur_len + " 米"
|
||||
this.tip.set_text(text)
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ class MeasureSlopeDistance extends Measure {
|
||||
let l = this.clampPositions.length - 1
|
||||
this.clampPositions.forEach((item, index) => {
|
||||
if (index !== l) {
|
||||
let d1 = this.computeDistance([item.position, this.clampPositions[index + 1].position])
|
||||
let d1 = this.computeDistance2([item.position, this.clampPositions[index + 1].position])
|
||||
let d2 = Math.abs(item.position.alt - this.clampPositions[index + 1].position.alt)
|
||||
let d3 = Math.sqrt(d1 * d1 + d2 * d2)
|
||||
total_length += d3
|
||||
@ -235,7 +235,7 @@ class MeasureSlopeDistance extends Measure {
|
||||
if (this.cachePositions.length) {
|
||||
let cur_point = this.cartesian3Towgs84(cartesian, this.viewer)
|
||||
let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer)
|
||||
let d1 = this.computeDistance([pre_p, cur_point])
|
||||
let d1 = this.computeDistance2([pre_p, cur_point])
|
||||
let d2 = Math.abs(pre_p.alt - cur_point.alt)
|
||||
let d3 = Math.sqrt(d1 * d1 + d2 * d2)
|
||||
let cosAlpha = d1 / d3
|
||||
@ -276,7 +276,7 @@ class MeasureSlopeDistance extends Measure {
|
||||
}
|
||||
|
||||
computeAngle(start, end) {
|
||||
let d1 = this.computeDistance([start, end])
|
||||
let d1 = this.computeDistance2([start, end])
|
||||
let d2 = Math.abs(start.alt - end.alt)
|
||||
let d3 = Math.sqrt(d1 * d1 + d2 * d2)
|
||||
let cosAlpha = d1 / d3
|
||||
|
@ -27,7 +27,7 @@ class MeasureTriangle extends Measure {
|
||||
cal_distance(positions) {
|
||||
let p1 = this.cartesian3Towgs84(positions[0], this.viewer)
|
||||
let p2 = this.cartesian3Towgs84(positions[1], this.viewer)
|
||||
let dis = this.computeDistance([p1, p2])
|
||||
let dis = this.computeDistance2([p1, p2])
|
||||
p1.alt = p1.alt.toFixed(2)
|
||||
p2.alt = p2.alt.toFixed(2)
|
||||
if (p1.alt === p2.alt) {//水平边
|
||||
@ -128,10 +128,10 @@ class MeasureTriangle extends Measure {
|
||||
let positions2 = this.id_map.get(id2).positions
|
||||
let p1 = this.cartesian3Towgs84(positions1[0], this.viewer)
|
||||
let p2 = this.cartesian3Towgs84(positions1[1], this.viewer)
|
||||
let shuiping = this.computeDistance([p2, p1])
|
||||
let shuiping = this.computeDistance2([p2, p1])
|
||||
let p3 = this.cartesian3Towgs84(positions2[0], this.viewer)
|
||||
let p4 = this.cartesian3Towgs84(positions2[1], this.viewer)
|
||||
let d = this.computeDistance([p3, p4])
|
||||
let d = this.computeDistance2([p3, p4])
|
||||
let h = Math.abs(p3.alt - p4.alt)
|
||||
let x = Math.sqrt(Math.pow(h, 2) + Math.pow(d, 2))
|
||||
if (shuiping == 0.00) {
|
||||
|
@ -1878,7 +1878,7 @@ class CircleObject extends Base {
|
||||
entity = null
|
||||
}
|
||||
endpoint = that.cartesian3Towgs84(cartesian, that.viewer)
|
||||
let radius = that.computeDistance([that.options.center, endpoint])
|
||||
let radius = that.computeDistance2([that.options.center, endpoint])
|
||||
that.radius = radius
|
||||
|
||||
YJ.Measure.SetMeasureStatus(false)
|
||||
@ -1904,7 +1904,7 @@ class CircleObject extends Base {
|
||||
that.event.mouse_move((movement, cartesian) => {
|
||||
entity && (entity.show = true)
|
||||
endpoint = that.cartesian3Towgs84(cartesian, that.viewer)
|
||||
moveRadius = that.computeDistance([that.options.center, endpoint])
|
||||
moveRadius = that.computeDistance2([that.options.center, endpoint])
|
||||
fromDegreesArray = that.createCircle(that.options.center, moveRadius)
|
||||
that.tip.setPosition(
|
||||
cartesian,
|
||||
|
@ -349,7 +349,7 @@ class CurvelineObject extends Base {
|
||||
break
|
||||
}
|
||||
|
||||
this.options.lengthByMeter = this.computeDistance(
|
||||
this.options.lengthByMeter = this.computeDistance2(
|
||||
this.smoothHandle(this.options.positions),
|
||||
2,
|
||||
ground
|
||||
@ -1157,7 +1157,7 @@ class CurvelineObject extends Base {
|
||||
CurvelineObject.createLabel(that)
|
||||
// that.entity.polyline.positionsLngLat = positions
|
||||
that.renewPolygon(fromDegreesArray)
|
||||
that.options.lengthByMeter = that.computeDistance(that.smoothHandle(positions), 2, ground)
|
||||
that.options.lengthByMeter = that.computeDistance2(that.smoothHandle(positions), 2, ground)
|
||||
that.lengthUnit = that.options['length-unit']
|
||||
syncData(that.sdk, that.options.id)
|
||||
if (that.options.show) {
|
||||
@ -1169,10 +1169,10 @@ class CurvelineObject extends Base {
|
||||
// for (let i = 0; i < fromDegreesArray.length; i += 2) {
|
||||
// array.push({ lng: fromDegreesArray[i], lat: fromDegreesArray[i + 1] })
|
||||
// }
|
||||
// this.options.fit_length = tool.computeDistance(array)
|
||||
// this.options.fit_length = tool.computeDistance2(array)
|
||||
// }
|
||||
// else {
|
||||
// this.options.fit_length = tool.computeDistance(positions)
|
||||
// this.options.fit_length = tool.computeDistance2(positions)
|
||||
// }
|
||||
// if (this.options.fit_length_unit === 'km') {
|
||||
// this.options.fit_length = this.options.fit_length / 1000
|
||||
@ -1856,13 +1856,13 @@ class CurvelineObject extends Base {
|
||||
alt: fromDegreesArray[i + 2]
|
||||
})
|
||||
}
|
||||
this.options.fitLengthByMeter = this.computeDistance(
|
||||
this.options.fitLengthByMeter = this.computeDistance2(
|
||||
array,
|
||||
2,
|
||||
ground
|
||||
)
|
||||
this.fitLengthUnit = this.options['fit-length-unit']
|
||||
this.options.lengthByMeter = this.computeDistance(this.smoothHandle(positions), 2, ground)
|
||||
this.options.lengthByMeter = this.computeDistance2(this.smoothHandle(positions), 2, ground)
|
||||
this.lengthUnit = this.options['length-unit']
|
||||
return fromDegreesArray
|
||||
}
|
||||
@ -2234,7 +2234,7 @@ class CurvelineObject extends Base {
|
||||
// )
|
||||
// let fromDegreesArray = that.renewPositions(that.options.positions)
|
||||
// that.renewPolygon(fromDegreesArray)
|
||||
// that.options.lengthByMeter = that.computeDistance(
|
||||
// that.options.lengthByMeter = that.computeDistance2(
|
||||
// that.options.positions,
|
||||
// 2,
|
||||
// that.ground
|
||||
|
@ -1322,7 +1322,8 @@ class PolylineObject extends Base {
|
||||
that.renewPolygon(fromDegreesArray)
|
||||
that.computeDistance(
|
||||
positions,
|
||||
2
|
||||
2,
|
||||
that.options['words-name']
|
||||
).then(res => {
|
||||
that.options.lengthByMeter = res
|
||||
that.lengthUnit = that.options['length-unit']
|
||||
|
@ -27,7 +27,7 @@ class Corridor extends Base {
|
||||
fromDegreesArray.push(positions[i].lng, positions[i].lat)
|
||||
}
|
||||
|
||||
let length = this.computeDistance(positions)
|
||||
let length = this.computeDistance2(positions)
|
||||
|
||||
let geometry = new Cesium.CorridorGeometry({
|
||||
positions: Cesium.Cartesian3.fromDegreesArray(fromDegreesArray),
|
||||
|
@ -31,7 +31,7 @@ class Corridor extends Base {
|
||||
fromDegreesArray.push(positions[i].lng, positions[i].lat)
|
||||
}
|
||||
|
||||
let length = this.computeDistance(positions)
|
||||
let length = this.computeDistance2(positions)
|
||||
|
||||
let geometry = new Cesium.CorridorGeometry({
|
||||
positions: Cesium.Cartesian3.fromDegreesArray(fromDegreesArray),
|
||||
|
@ -94,7 +94,7 @@ class StandText extends Base {
|
||||
let minimumHeights = []
|
||||
let maximumHeights = []
|
||||
let material = this.getMaterial()
|
||||
let width = this.computeDistance(positions)
|
||||
let width = this.computeDistance2(positions)
|
||||
let extrudedHeight = this.aspectRatio ? (width / this.aspectRatio) : 0
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
fromDegreesArray.push(positions[i].lng, positions[i].lat)
|
||||
@ -303,7 +303,7 @@ class StandText extends Base {
|
||||
let minimumHeights = []
|
||||
let maximumHeights = []
|
||||
let material = that.getMaterial()
|
||||
let width = that.computeDistance(positions)
|
||||
let width = that.computeDistance2(positions)
|
||||
let extrudedHeight = that.aspectRatio ? (width / that.aspectRatio) : 0
|
||||
// aspectRatio
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
@ -503,7 +503,7 @@ class StandText extends Base {
|
||||
let fromDegreesArray = []
|
||||
let minimumHeights = []
|
||||
let maximumHeights = []
|
||||
let width = this.computeDistance(positions)
|
||||
let width = this.computeDistance2(positions)
|
||||
let extrudedHeight = this.aspectRatio ? (width / this.aspectRatio) : 0
|
||||
// aspectRatio
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
@ -602,7 +602,7 @@ class StandText extends Base {
|
||||
let fromDegreesArray = []
|
||||
let minimumHeights = []
|
||||
let maximumHeights = []
|
||||
let width = that.computeDistance(positions)
|
||||
let width = that.computeDistance2(positions)
|
||||
let extrudedHeight = that.aspectRatio ? (width / that.aspectRatio) : 0
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
fromDegreesArray.push(positions[i].lng, positions[i].lat)
|
||||
@ -635,7 +635,7 @@ class StandText extends Base {
|
||||
fromDegreesArray = []
|
||||
minimumHeights = []
|
||||
maximumHeights = []
|
||||
width = that.computeDistance(positions)
|
||||
width = that.computeDistance2(positions)
|
||||
extrudedHeight = that.aspectRatio ? (width / that.aspectRatio) : 0
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
fromDegreesArray.push(positions[i].lng, positions[i].lat)
|
||||
@ -680,7 +680,7 @@ class StandText extends Base {
|
||||
fromDegreesArray = []
|
||||
minimumHeights = []
|
||||
maximumHeights = []
|
||||
width = that.computeDistance(positions)
|
||||
width = that.computeDistance2(positions)
|
||||
extrudedHeight = that.aspectRatio ? (width / that.aspectRatio) : 0
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
fromDegreesArray.push(positions[i].lng, positions[i].lat)
|
||||
@ -710,7 +710,7 @@ class StandText extends Base {
|
||||
fromDegreesArray = []
|
||||
minimumHeights = []
|
||||
maximumHeights = []
|
||||
width = that.computeDistance(positions)
|
||||
width = that.computeDistance2(positions)
|
||||
extrudedHeight = that.aspectRatio ? (width / that.aspectRatio) : 0
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
fromDegreesArray.push(positions[i].lng, positions[i].lat)
|
||||
|
@ -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