/**
|
* @Author: Caven
|
* @Date: 2020-01-31 19:45:32
|
*/
|
|
import { PlotEventType } from '@/utils/event/index.js'
|
|
class Draw {
|
constructor(style) {
|
this._style = style
|
this._viewer = undefined
|
this._layer = undefined
|
this._delegate = undefined
|
this._options = {}
|
this._positions = []
|
}
|
|
get curDrawTool () {
|
return this._viewer.curDrawTool
|
}
|
|
/**
|
* The hook for mount viewer
|
* Subclasses need to be overridden
|
* @private
|
*/
|
_mountedHook () { }
|
|
/**
|
* The hook for mount stop
|
* Subclasses need to be overridden
|
* @private
|
*/
|
_stopdHook () { }
|
|
/**
|
*
|
* @param position
|
* @private
|
*/
|
_onDrawAnchor (position) { }
|
|
/**
|
*
|
* @param position
|
* @private
|
*/
|
_onAnchorMoving (position) {
|
this._positions.pop()
|
this._positions.push(position)
|
}
|
|
/**
|
*
|
* @private
|
*/
|
_onDrawStop () {
|
this._unbindEvent()
|
this._viewer.curDrawTool.deactivate()
|
this._layer.entities.remove(this._delegate)
|
this._stopdHook()
|
}
|
|
/**
|
*
|
* @private
|
*/
|
_bindEvent () {
|
this.curDrawTool.on(PlotEventType.DRAW_ANCHOR, this._onDrawAnchor, this)
|
this.curDrawTool.on(PlotEventType.ANCHOR_MOVING, this._onAnchorMoving, this)
|
this.curDrawTool.on(PlotEventType.DRAW_STOP, this._onDrawStop, this)
|
}
|
|
/**
|
*
|
* @private
|
*/
|
_unbindEvent () {
|
this.curDrawTool.off(PlotEventType.DRAW_ANCHOR, this._onDrawAnchor, this)
|
this.curDrawTool.off(PlotEventType.ANCHOR_MOVING, this._onAnchorMoving, this)
|
this.curDrawTool.off(PlotEventType.DRAW_STOP, this._onDrawStop, this)
|
}
|
|
/**
|
*
|
* @param plot
|
* @param options
|
* @returns {Draw}
|
*/
|
start (plot, options) {
|
this._viewer = plot.viewer
|
this._layer = plot.layer
|
this._options = options
|
this._viewer.editTool.deactivate()
|
this._viewer.curDrawTool.activate(options)
|
this._mountedHook()
|
this._unbindEvent()
|
this._bindEvent()
|
return this
|
}
|
}
|
|
export default Draw
|