wangzhibo
2021-09-06 2efb5d2a02ce47a9fd6f1cec138496aba72f0815
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
(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //外部资源配置
    get resources() {
      return ["view.css"];
    }
 
    //弹窗配置
    get view() {
      return {
        type: "append",
        url: "view.html",
      };
    }
 
    //初始化[仅执行1次]
    create() {
      this.isAnimate = this.map.clock.shouldAnimate;
    }
    //每个窗口创建完成后调用
    winCreateOK(opt, result) {
      var that = this;
      //此处可以绑定页面dom事件
 
      this.$start = $("#btn-animation-start");
      this.$time = $("#btn-animation-time");
      this.$speed = $("#txt-animation-speed");
 
      $("#btn-animation-now").click(function (e) {
        that.map.clock.currentTime = Cesium.JulianDate.fromDate(new Date());
      });
 
      this.$start.click(function (e) {
        that.map.clock.shouldAnimate = !that.map.clock.shouldAnimate;
        that.updateStatus();
      });
 
      this.$speed.val(this.map.clock.multiplier);
      this.$speed.change(function (e) {
        var val = Number(that.$speed.val());
        if (!isNaN(val)) {
          that.map.clock.multiplier = val;
        } //飞行速度
      });
 
      //this.map.clock.onTick.addEventListener(this.clock_onTickHandler, this);
      setInterval(function () {
        that.clock_onTickHandler();
      }, 1000);
      that.clock_onTickHandler();
    }
    //激活插件
    activate() {
      $(".distance-legend").css({
        bottom: "25px",
      });
      $(".cesium-viewer-timelineContainer").css({ left: "290px" });
    }
    //释放插件
    disable() {}
 
    updateStatus() {
      if (!this.$start || this.isAnimate === this.map.clock.shouldAnimate) {
        return;
      }
      this.isAnimate = this.map.clock.shouldAnimate;
 
      if (this.isAnimate) {
        this.$start.attr("title", "暂停").html('<i class="fa fa-pause"></i>');
      } else {
        this.$start.attr("title", "继续").html('<i class="fa fa-play"></i>');
      }
    }
    clock_onTickHandler() {
      this.updateStatus();
 
      if (this.$time) {
        var str = Cesium.JulianDate.toDate(this.map.clock.currentTime).format("yyyy-MM-dd HH:mm:ss");
        this.$time.html(str);
      }
    }
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget);
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d);