jxdnsong
2023-04-05 be147d2a99d60a30b20fade742e85b45f06172ae
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2023-03-23 11:22:18
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2023-03-24 10:02:32
 * @FilePath: \forest-fire\src\utils\plot\draw\DrawPolygon.js
 * @Description: 
 * 
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
 */
/**
 * @Author: Caven
 * @Date: 2020-08-29 20:55:14
 */
 
import Draw from './Draw'
import { PlotEventType } from '@/utils/event/index.js'
 
const DEF_STYLE = {
    material: global.DC.Namespace.Cesium.Color.YELLOW.withAlpha(0.6),
    fill: true
}
 
class DrawPolygon extends Draw {
    constructor(style) {
        super()
        this._style = {
            ...DEF_STYLE,
            ...style
        }
    }
 
    /**
     *
     * @private
     */
    _mountedHook () {
        this.curDrawTool.tooltipMess = '左击选择点位,右击结束'
        this._delegate = new global.DC.Namespace.Cesium.Entity({
            polygon: {
                ...this._style,
                hierarchy: new global.DC.Namespace.Cesium.CallbackProperty(() => {
 
                    if (this._positions.length > 2) {
                        return new global.DC.Namespace.Cesium.PolygonHierarchy(this._positions)
                    } else {
                        return null
                    }
                }, false)
            }
        })
 
        this._layer.entities.add(this._delegate)
 
    }
 
    /**
     *
     * @private
     */
    _stopdHook () {
        let polygon = new global.DC.Polygon(
            global.DC.Transform.transformCartesianArrayToWGS84Array(this._positions)
        ).setStyle(this._style)
        this._options.onDrawStop && this._options.onDrawStop(polygon)
    }
 
    /**
     *
     * @param position
     * @private
     */
    _onDrawAnchor (position) {
        this._positions.push(position)
        this.curDrawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
    }
}
 
export default DrawPolygon