吉安感知网项目-前端
chenyao
21 hours ago c567cbca3b78a7e06a827acbab56a46657e31aa1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { DrawPolygonTool } from './draw/DrawPolygonTool'
import { DrawRectangleTool } from './draw/DrawRectangleTool'
import { DrawEllipseTool } from './draw/DrawEllipseTool'
import { DrawBufferCircleTool } from './draw/DrawBufferCircleTool'
 
const DRAW_TOOL_MAP = {
    polygon: DrawPolygonTool,
    rectangle: DrawRectangleTool,
    ellipse: DrawEllipseTool,
    buffer: DrawBufferCircleTool,
}
 
export class DrawManager {
    constructor(viewer) {
        this.viewer = viewer
        this.activeTool = null
    }
 
    start(type, options = {}) {
        this.destroy()
        const Tool = DRAW_TOOL_MAP[type]
        if (!Tool) return null
        this.activeTool = new Tool(this.viewer, options)
        this.activeTool.start()
        return this.activeTool
    }
 
    destroy() {
        if (this.activeTool) {
            this.activeTool.destroy()
            this.activeTool = null
        }
    }
}