代码迁移

This commit is contained in:
zh
2025-07-03 13:54:01 +08:00
parent b04de8a084
commit 2a4da33e62
985 changed files with 358292 additions and 13 deletions

View File

@ -0,0 +1,173 @@
import Measure from "../index"
/**@extends Measure*/
class MeasureTdArea extends Measure {
/**
* @constructor
* @param sdk
* @description 贴地面积测量
* */
constructor(sdk, options = {}) {
super(sdk, options);
this.options.lineColor = '#ffdf53'
this.polygon_id = ""
}
static create_polygon(that) {
let id = that.randomString()
let scaleByDistance = new Cesium.NearFarScalar(2000, 1, 100000, 0)
let e = that.viewer.entities.add(
new Cesium.Entity({
id: id,
label: {
text: new Cesium.CallbackProperty(() => {
return that.text
}, false),
//标注文字描述
font: '20px Microsoft YaHei',
fillColor: Cesium.Color.fromCssColorString('#ffffff'),
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
//标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡
// distanceDisplayCondition: this.distanceDisplayCondition,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
// scaleByDistance,
scale: 1,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
},
position: new Cesium.CallbackProperty(() => {
return that.center
}, false),
polygon: {
classificationType: Cesium.ClassificationType.BOTH,
hierarchy: new Cesium.CallbackProperty((e) => {
return new Cesium.PolygonHierarchy(that.positions)
}, false),
material: new Cesium.Color.fromCssColorString(that.options.color || that.defaultColor),
zIndex: 99999999
},
polyline: {
positions: new Cesium.CallbackProperty(() => {
if (that.positions.length)
return that.positions.concat(that.positions[0])
return that.positions
}, false),
width: 2,
material: new Cesium.PolylineDashMaterialProperty({
color: new Cesium.Color.fromCssColorString(that.options.lineColor || that.defaultColor),
dashLength: 20, //短划线长度
}),
clampToGround: true,
zIndex: 99999999
}
})
)
return id
}
/**
* 开始测量
*/
start() {
if (!YJ.Measure.GetMeasureStatus()) {
super.start()
this.ids = []
this.positions = []
this.text = ""
this.center = new Cesium.Cartesian3()
this.cachePositions = []
let height = 0
let text
let leftEvent = (movement, car) => {
if (this.ids.length === 0) {
this.polygon_id = MeasureTdArea.create_polygon(this)
}
this.cachePositions.push({ ...car })
this.ids.push(this.create_point({ ...car }, false))
let po = this.cartesian3Towgs84({ ...car }, this.viewer)
if (po.alt > height) {
height = po.alt
}
this.positions = this.cachePositions.concat({ ...car })
this.tip.setPosition({ ...car }, movement.position.x, movement.position.y)
}
let rightEvent = (movement, car) => {
this.positions = this.cachePositions
if (this.positions.length > 2) {
let arr = []
this.positions.forEach(item => {
let p = this.cartesian3Towgs84(item, this.viewer)
arr.push({ lng: p.lng, lat: p.lat })
})
setTimeout(() => {
let center = this.computeCenter(arr)
let area = this.computeSignedArea(this.viewer, arr)
this.center = new Cesium.Cartesian3.fromDegrees(center.lng, center.lat, height)
this.text = "贴地面积:" + area + " ㎡"
}, 0);
}
else {
let error = '面积计算至少需要三个坐标!'
console.warn(error)
window.ELEMENT && window.ELEMENT.Message({
message: error,
type: 'warning',
duration: 1500
});
this.destroy()
}
this.end()
}
this.event.mouse_left(leftEvent)
this.event.mouse_move((movement, car) => {
this.tip.setPosition({ ...car }, movement.endPosition.x, movement.endPosition.y)
this.positions = this.cachePositions.concat({ ...car })
})
this.event.mouse_right(rightEvent)
this.event.gesture_pinck_start((movement, cartesian) => {
let startTime = new Date()
let pos = {
position: {
x: (movement.position1.x + movement.position2.x) / 2,
y: (movement.position1.y + movement.position2.y) / 2
}
}
this.event.gesture_pinck_end(() => {
let endTime = new Date()
if (endTime - startTime >= 500) {
// 长按取消
rightEvent(pos, cartesian)
}
else {
leftEvent(pos, cartesian)
}
})
})
}
}
/**
* 清除测量
*/
destroy() {
[this.polygon_id, ...this.ids].forEach(id => {
this.remove_entity(id)
})
super.destroy()
}
/**
* 结束测量
*/
end() {
super.end()
}
}
export default MeasureTdArea