81 lines
1.9 KiB
JavaScript
81 lines
1.9 KiB
JavaScript
|
import MouseEvent from "../Event";
|
|||
|
import MouseTip from "../MouseTip";
|
|||
|
import Tools from "../Tools";
|
|||
|
|
|||
|
/**
|
|||
|
* @name: measure
|
|||
|
* @author: Administrator
|
|||
|
* @date: 2022-07-11 10:52
|
|||
|
* @description:measure
|
|||
|
* @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
|