117 lines
3.0 KiB
JavaScript
117 lines
3.0 KiB
JavaScript
import MouseTip from '../MouseTip'
|
|
import MouseEvent from '../Event'
|
|
import Draw from "./draw";
|
|
|
|
|
|
class DrawPoint extends Draw {
|
|
/**
|
|
* @constructor
|
|
* @desc 获取坐标点
|
|
* */
|
|
constructor(sdk, options = {}, is2D = false) {
|
|
super(sdk, options, is2D)
|
|
}
|
|
|
|
/**
|
|
* @desc 开始动态获取坐标点
|
|
* @method start
|
|
* @param cb {function} 回调函数
|
|
* @memberOf DrawPoint
|
|
* @example draw.start((err,position)=>{
|
|
*
|
|
* })
|
|
* */
|
|
|
|
start(cb) {
|
|
if (YJ.Measure.GetMeasureStatus()) {
|
|
cb('上一次测量未结束')
|
|
} else {
|
|
let car = undefined
|
|
YJ.Measure.SetMeasureStatus(true)
|
|
this.tip = new MouseTip(this.tipText || '左键确定,右键结束;', this.sdk)
|
|
this.event = new MouseEvent(this.sdk)
|
|
this.event.mouse_left((movement, cartesian) => {
|
|
this.end()
|
|
let p = this.cartesian3Towgs84(car || cartesian, this.viewer)
|
|
cb(null, p, Cesium)
|
|
})
|
|
this.event.mouse_right((movement, cartesian) => {
|
|
this.end()
|
|
cb(false)
|
|
})
|
|
this.event.mouse_move((movement, cartesian) => {
|
|
car = cartesian
|
|
this.tip.setPosition(
|
|
cartesian,
|
|
movement.endPosition.x,
|
|
movement.endPosition.y
|
|
)
|
|
})
|
|
|
|
this.event.gesture_pinck_start((movement, cartesian) => {
|
|
let startTime = new Date()
|
|
this.event.gesture_pinck_end(() => {
|
|
let endTime = new Date()
|
|
if (endTime - startTime >= 500) {
|
|
this.end()
|
|
cb(false)
|
|
}
|
|
else {
|
|
this.end()
|
|
let p = this.cartesian3Towgs84(car || cartesian, this.viewer)
|
|
cb(null, p)
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
|
|
if (!this._is2D && this._sdk2D) {
|
|
this.event2D = new MouseEvent(this._sdk2D)
|
|
this.event2D.mouse_left((movement, cartesian) => {
|
|
this.end()
|
|
let p = this.cartesian3Towgs84(car || cartesian, this.viewer)
|
|
cb(null, p, Cesium)
|
|
})
|
|
this.event2D.mouse_right((movement, cartesian) => {
|
|
this.end()
|
|
cb(false)
|
|
})
|
|
this.event2D.mouse_move((movement, cartesian) => {
|
|
car = cartesian
|
|
this.tip.setPosition(
|
|
cartesian,
|
|
movement.endPosition.x + this.viewer.canvas.width,
|
|
movement.endPosition.y
|
|
)
|
|
})
|
|
|
|
this.event2D.gesture_pinck_start((movement, cartesian) => {
|
|
let startTime = new Date()
|
|
this.event2D.gesture_pinck_end(() => {
|
|
let endTime = new Date()
|
|
if (endTime - startTime >= 500) {
|
|
this.end()
|
|
cb(false)
|
|
}
|
|
else {
|
|
this.end()
|
|
let p = this.cartesian3Towgs84(car || cartesian, this.viewer)
|
|
cb(null, p)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
end() {
|
|
YJ.Measure.SetMeasureStatus(false)
|
|
this.event && this.event.destroy()
|
|
this.event2D && this.event2D.destroy()
|
|
this.tip && this.tip.destroy()
|
|
}
|
|
}
|
|
|
|
export default DrawPoint
|