wangrong
2025-09-23 40634ebaf5863a599bba8ca2c0575ca079fb8e15
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"use script" //开发环境建议开启严格模式
;(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends es5widget.BaseWidget {
    //弹窗配置
    get view() {
      return {
        type: "window",
        url: "view.html",
        style: "dark",
        windowOptions: {
          skin: "layer-mars-dialog animation-scale-up",
          width: 315,
          position: {
            top: 10,
            left: 5,
            bottom: 30
          }
        }
      }
    }
 
    //初始化[仅执行1次]
    create() {}
 
    //每个窗口创建完成后调用
    winCreateOK(opt, result) {
      this.viewWindow = result
    }
    //激活插件
    activate() {}
    //释放插件
    disable() {
      let graphic = this.config.graphic
      if (graphic && graphic._minPointNum) {
        graphic.stopEditing()
 
        if (this.config.sendSaveEntity) {
          this.config.sendSaveEntity()
        }
      }
    }
    getMinPointNum() {
      let graphic = this.config.graphic
      if (graphic && graphic._minPointNum) {
        return graphic._minPointNum
      }
      return 3
    }
    getMaxPointNum() {
      let graphic = this.config.graphic
      if (graphic && graphic._maxPointNum) {
        return graphic._maxPointNum
      }
      return 999
    }
    get defaultAttrList() {
      return [
        { name: "id", label: "主键", type: "label", defval: "" },
        { name: "name", label: "名称", type: "text", defval: "" },
        { name: "remark", label: "备注", type: "textarea", defval: "" }
      ]
    }
    getAttrList() {
      return this.config.attrList || this.defaultAttrList
    }
    getLayerName() {
      let graphic = this.config.graphic
      return graphic?._layer?.name || ""
    }
    getAvailability() {
      let graphic = this.config.graphic
 
      return mars3d.Util.getAvailabilityJson(graphic.availability)
    }
 
    startEditing(graphic, lonlats) {
      if (graphic) {
        this.config.graphic = graphic
      }
      if (lonlats) {
        this.config.lonlats = lonlats
      }
 
      if (this.viewWindow == null) {
        return
      }
 
      graphic = this.config.graphic
      lonlats = this.config.lonlats
 
      let config = { ...graphic.options, type: graphic.type, style: graphic.style }
      console.log("开始编辑属性", config)
 
      this.viewWindow.plotEdit.startEditing(config, lonlats)
    }
 
    //更新样式
    updateStyle2map(style) {
      console.log("更新style样式", style)
      let graphic = this.config.graphic
      graphic.style = style
    }
    //更新坐标
    updatePoints2map(points) {
      console.log("更新坐标", points)
 
      let graphic = this.config.graphic
      graphic.positions = points
    }
    //更新属性
    updateAttr2map(attr) {
      let graphic = this.config.graphic
      graphic.attr = attr
    }
    centerCurrentEntity() {
      let graphic = this.config.graphic
      graphic.flyTo()
    }
    getAndSetMapTime(date) {
      if (!date) {
        const start = map.clock.currentTime.clone()
        const stop = Cesium.JulianDate.addSeconds(start, 10, new Cesium.JulianDate())
        return { start: this.formatDate(Cesium.JulianDate.toDate(start)), stop: this.formatDate(Cesium.JulianDate.toDate(stop)) }
      } else {
        const toJulian = Cesium.JulianDate.fromDate(new Date(date))
        const stop = Cesium.JulianDate.addSeconds(toJulian, 5, new Cesium.JulianDate())
        return this.formatDate(Cesium.JulianDate.toDate(stop))
      }
    }
 
    formatDate(time) {
      return mars3d.Util.formatDate(time, "yyyy-MM-dd HH:mm:ss")
    }
 
    deleteEntity() {
      let graphic = this.config.graphic
      if (graphic.stopEditing) {
        graphic.stopEditing()
      }
      graphic.remove()
 
      this.disableBase()
    }
 
    //文件处理
    getGeoJson() {
      let graphic = this.config.graphic
      let geojson = graphic.toGeoJSON()
      geojson.properties._layer = graphic._layer.name //记录分组信息
 
      return geojson
    }
    //时序
    availabilityChange(availability) {
      // console.log("availability", availability)
      let graphic = this.config.graphic
 
      if (availability && availability.length) {
        graphic.availability = availability
      } else {
        graphic.availability = null
      }
    }
  }
 
  //注册到widget管理器中。
  es5widget.bindClass(MyWidget)
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d)