Files
sdk4.0/src/Measure/index.js
2025-07-03 13:54:01 +08:00

81 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import MouseEvent from "../Event";
import MouseTip from "../MouseTip";
import Tools from "../Tools";
/**
* @name: measure
* @author: Administrator
* @date: 2022-07-11 10:52
* @descriptionmeasure
* @update: 2022-07-11 10:52
*/
class Measure extends Tools {
constructor(sdk, options = {text: "左键开始,右键结束;"}) {
super(sdk, options)
this.options = {...options}
this.event = new MouseEvent(sdk)
this.tip = new MouseTip(options.text, sdk)
this.viewer = sdk.viewer
this.defaultColor = 'rgba(246,49,49,0.55)'
this.ids = []
YJ.Measure.Measures.push(this)
this._isDestroy = false
// this.pickStatus = {pick: YJ.getEarth().interaction.picking.enabled}
}
start() {
this.setPickStatus(false)
YJ.Measure.SetMeasureStatus(true)
}
destroy() {
// YJ.Measure.Measures.pop()
this._isDestroy = true
this.end()
this.ids.forEach(id => {
this.remove_entity(id)
})
}
end() {
// this.ids.forEach(id => {
// this.remove_entity(id)
// })
//还原上一次的状态
// this.setPickStatus(this.pickStatus.pick)
YJ.Measure.SetMeasureStatus(false)
this.tip && this.tip.destroy()
this.event && this.event.destroy()
this.tip = null
this.event = null
}
create_point(cartesian,show = true) {
let id = this.randomString()
let p = this.cartesian3Towgs84(cartesian, this.viewer)
this.viewer.entities.add(
new Cesium.Entity({
id: id,
position: Cesium.Cartesian3.fromDegrees(p.lng, p.lat, p.alt),
billboard: {
show: show,
image: this.getSourceRootPath() + '/img/point.png',
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
}
})
)
return id
}
remove_entity(id) {
this.viewer.entities.removeById(id)
}
}
export default Measure