wangzhibo
2021-09-04 3306b9213bda4af51664db98a2d0bc1c9c02e31f
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
;(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //外部资源配置
    get resources() {
      return ['view.css']
    }
    //弹窗配置
    get view() {
      return {
        type: 'divwindow',
        url: 'view.html',
        windowOptions: {
          width: 210,
          height: 210,
        },
      }
    }
    //每个窗口创建完成后调用
    winCreateOK(opt, result) {
      var point = this.map.getCenter()
      this.showInputView(point)
 
      $('#btnCenterXY').click(() => {
        var jd = $('#point_jd').val()
        var wd = $('#point_wd').val()
        var height = $('#point_height').val()
 
        let point = new mars3d.LatLngPoint(Number(jd), Number(wd), Number(height))
        this.updateMarker(point, true)
      })
    }
    //激活插件
    activate() {
      //单击地图事件
      this.map.on(mars3d.EventType.click, this.onMapClick, this)
    }
    //释放插件
    disable() {
      //释放单击地图事件
      this.map.off(mars3d.EventType.click, this.onMapClick, this)
 
      if (this.graphic) {
        this.map.graphicLayer.removeGraphic(this.graphic, true)
        this.graphic = null
      }
    }
    onMapClick(event) {
      var cartesian = event.cartesian
      if (cartesian) {
        var point = mars3d.LatLngPoint.fromCartesian(cartesian)
 
        this.updateMarker(point)
        this.showInputView(point)
      }
    }
    updateMarker(position, iscenter) {
      if (this.graphic) {
        this.graphic.position = position
      } else {
        this.graphic = new mars3d.graphic.BillboardEntity({
          position: position,
          style: {
            image: this.path + 'img/marker.png',
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
            verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // default: CENTER
            scale: 0.6,
          },
        })
        this.map.graphicLayer.addGraphic(this.graphic)
      }
 
      if (iscenter) {
        this.map.flyToGraphic(this.graphic, { radius: 2000 })
      }
    }
    showInputView(xy) {
      $('#point_jd').val(xy.lng.toFixed(6))
      $('#point_wd').val(xy.lat.toFixed(6))
      $('#point_height').val(xy.alt.toFixed(1))
    }
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget)
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d)