fuchengshen
2022-07-04 343ba87e09501be7a63abde000a43e13a5b4f03e
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
(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //弹窗配置
    get view() {
      return {
        type: "window",
        url: "view.html",
        windowOptions: {
          width: 230,
          height: 520,
          //maxmin: true,
        },
      };
    }
    //初始化[仅执行1次]
    create() {}
    //每个窗口创建完成后调用
    winCreateOK(opt, result) {
      //layer.min(opt._layerIdx); //最小化窗口
      this.viewWindow = result;
    }
    //激活模块之前 的钩子方法
    beforeActivate() {
      var lonlats = this.config.data.positions;
      if (!lonlats || lonlats.length < 2) {
        toastr.error("路线无坐标数据,无法漫游!");
        return;
      }
      let roamLine = new mars3d.graphic.RoamLine(this.config.data);
      this.map.graphicLayer.addGraphic(roamLine);
      this.roamLine = roamLine;
 
      this.roamLine.on(mars3d.EventType.change, (event) => {
        this.viewWindow.showRealTimeInfo(event);
        this.updateCharsWidgeFlyOk(event.len); //更新剖面图
      });
    }
    //打开激活
    activate() {
      if (this.config.data.clampToGround) {
        this.roamLine.clampToGround(() => {
          //异步计算完成贴地后再启动
          this.startFly();
        });
      } else {
        this.startFly();
      }
    }
    startFly() {
      this.roamLine.start();
 
      //显示基本信息,名称、总长、总时间
      this.viewWindow.showAllInfo({
        name: this.roamLine.name,
        alllen: this.roamLine.alllen,
        alltime: this.roamLine.alltimes,
      });
 
      if (this.map.timeline) {
        this.map.timeline.zoomTo(this.roamLine.startTime, this.roamLine.stopTime);
      }
    }
    //关闭释放
    disable() {
      this.viewWindow = null;
 
      this.roamLine.destroy();
      delete this.roamLine;
    }
    //界面更新参数
    getAttr() {
      if (this.roamLine) {
        return this.roamLine.options;
      } else {
        return this.config.data;
      }
    }
    setCameraOptions(params) {
      this.roamLine.setCameraOptions(params);
    }
 
    //返回列表widget
    toRoamLine() {
      this.roamLine.stop();
 
      mars3d.widget.activate({
        uri: "widgets/roamLine/widget.js",
      });
    }
 
    //显示剖面
    showHeightChars() {
      this.roamLine.options.splitNum = 100;
      this.roamLine.getTerrainHeight((data) => {
        this.updateCharsWidge(data);
      });
    }
    //首次激活roamChars
    updateCharsWidge(data) {
      mars3d.widget.activate({
        uri: "widgets/roamChars/widget.js",
        data: data,
      });
    }
    //持续更新调用roamChars
    updateCharsWidgeFlyOk(alllen) {
      var roamingJK = mars3d.widget.getClass("widgets/roamChars/widget.js");
      if (roamingJK && roamingJK.isActivate) {
        roamingJK.changeFlyOk(alllen);
      }
    }
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget);
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d);