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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//公共处理js
 
//数据处理,及自动播放
var dataWork = {
  alltimes: 0,
  arrNode: [],
  analysisData: function (arr) {
    for (var i = 0; i < arr.length; i++) {
      var item = arr[i];
      // item.state = { disabled: true }; //前端播放时禁用单击
 
      if (item.widget) {
        item.index = this.arrNode.length; //this.getNextId();
        item.id = item.index;
        item.times = item.times || 60;
        item.text = item.text + "(" + item.times + "秒)";
        item.icon = "fa fa-tag";
        this.arrNode.push(item);
        this.alltimes += item.times;
      }
 
      if (item.children) {
        this.analysisData(item.children);
      }
    }
  },
  steptimes: 0,
  initData: function (data) {
    this.analysisData(data);
    $("#alltimes").html(haoutil.str.formatTime(this.alltimes));
 
    setInterval(() => {
      if (!this._isStart) {
        return;
      }
      this.steptimes++;
      $("#thistimes").html(this.steptimes + "秒");
    }, 1000);
 
    $("#treeOverlays").jstree({
      core: {
        data: data,
        themes: {
          name: "default-dark",
          dots: true,
          icons: true,
        },
      },
    });
 
    $("#treeOverlays").on("changed.jstree", (e, data) => {
      var node = data.node.original;
      if (node && node.widget) {
        this.start(node);
      }
    });
  },
  _isStart: false,
  selectdNode: null,
  //开始
  start: function (node) {
    this.stop();
 
    $("#btn_start").hide();
    $("#btn_pause").show();
    $("#btn_proceed").hide();
    $("#btn_stop").show();
    // $("#treeOverlays").jstree().close_all();
 
    this._isStart = true;
    map.clock.shouldAnimate = true;
    dataWork.activateNode(node || this.arrNode[0]);
  },
  //暂停
  pause: function () {
    $("#btn_start").hide();
    $("#btn_pause").hide();
    $("#btn_proceed").show();
    $("#btn_stop").show();
 
    this._isStart = false;
    map.cancelFlight();
    JB.stopRotatePoint();
    map.clock.shouldAnimate = false;
 
    if (this.timeIdx && this.timeIdx != -1) {
      clearTimeout(this.timeIdx);
      this.timeIdx = -1;
    }
  },
  //继续
  proceed: function () {
    $("#btn_start").hide();
    $("#btn_pause").show();
    $("#btn_proceed").hide();
    $("#btn_stop").show();
 
    map.clock.shouldAnimate = true;
 
    var node = this.selectdNode;
    if (node) {
      var that = this;
      this.timeIdx = setTimeout(function () {
        that.activateNextNode(node.index);
      }, (node.times - this.steptimes) * 1000);
    } else {
      this.start();
    }
    this._isStart = true;
  },
 
  //停止
  stop: function () {
    this.pause();
    $("#btn_start").show();
    $("#btn_pause").hide();
    $("#btn_stop").hide();
    $("#btn_proceed").hide();
 
    $("#thisStep").html("无");
    $("#thistimes").html("");
    $("#treeOverlays").jstree("deselect_all", true);
 
    if (this.selectdNode) {
      this.selectdNode.widget.disable();
    }
    dataWork.selectdNode = null;
    this._isStart = false;
  },
  activateNode: function (node) {
    this.selectdNode = node;
    $("#stopRoate").val("暂停");
    this.steptimes = 0;
    $("#thisStep").html(node.text);
    $("#treeOverlays").jstree("deselect_all", true);
    $("#treeOverlays").jstree("select_node", node.id, true);
    node.widget.activate(node);
 
    // $("#treeOverlays").jstree().close_all(); //收起树
 
    var that = this;
    this.timeIdx = setTimeout(function () {
      node.widget.disable();
      that.activateNextNode(node.index);
    }, node.times * 1000);
  },
  activateNextNode: function (index) {
    index++;
    if (index < 0 || index >= this.arrNode.length) {
      this.stop();
      this.selectdNode = null;
      return;
    }
    var node = this.arrNode[index];
    this.activateNode(node);
  },
};
 
var timeColor = {
  color: Cesium.Color.YELLOW.withAlpha(0),
  start: function (clr, max) {
    clr = clr || Cesium.Color.YELLOW;
    this.colorBack = Cesium.Color.clone(clr);
    this.max = max;
 
    this.stop();
 
    var time = 30;
    var setp = max / time;
 
    var alpha = 0;
    this.interVal = setInterval(() => {
      alpha += setp;
      if (alpha > max) {
        alpha = 0;
      }
      this.color = clr.withAlpha(alpha);
    }, time);
  },
  stop: function () {
    clearInterval(this.interVal);
    this.color = this.colorBack.withAlpha(this.max);
  },
};
 
//循环执行数组或对象,参数支持
function loopArrayForFun(opts, callback) {
  if (opts == null) {
    return;
  }
  if (haoutil.isutil.isArray(opts)) {
    var arr = [];
    for (var i = 0, len = opts.length; i < len; i++) {
      arr.push(callback(opts[i]));
    }
    return arr;
  } else {
    return callback(opts);
  }
}
 
//脚本列表
var JB = {
  removeGraphic(opts) {
    return loopArrayForFun(opts, function (graphic) {
      graphic.remove(true);
    });
  },
  changeGraphicShow(opts, show) {
    return loopArrayForFun(opts, function (graphic) {
      graphic.show = show;
    });
  },
 
  //添加GeoJSON
  addGeoJSON(geojson) {
    return map.graphicLayer.loadGeoJSON(geojson);
  },
 
  //添加注记,参数支持数组或单个
  addLabel(opts) {
    return loopArrayForFun(opts, this._addLabelItem);
  },
  _addLabelItem(opts) {
    var html = opts.html;
    if (!html) {
      html = `<div class="divpoint1">
                  <div class="title">${opts.name || ""}</div>
              </div >`;
    }
    //文字注记
    var graphic = new mars3d.graphic.DivGraphic({
      position: opts.point,
      style: {
        html: html,
        anchor: opts.anchor,
        heightReference: opts.heightReference,
        horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
        verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
      },
    });
    map.graphicLayer.addGraphic(graphic);
 
    return graphic;
  },
 
  //====================自定义面板=========================
  showPanel(html) {
    $("#viewResult").remove();
    var innerHTML = `<div id="viewResult" class="infoview viewResult" >
            ${html}
        </div>`;
    $("body").append(innerHTML);
  },
  closePanel() {
    $("#viewResult").remove();
  },
  playMP3(src) {
    var mp3 = new Audio(src);
    mp3.play(); //播放 mp3这个音频对象
    return mp3;
  },
  //绕点飞行
  startRotatePoint(center) {
    if (!this.rotatePoint) {
      this.rotatePoint = new mars3d.thing.RotatePoint({
        direction: false, //方向 true逆时针,false顺时针
        time: 50, //给定飞行一周所需时间(单位 秒),控制速度
        // autoStopAngle: 360, //到达指定角度后自动停止
      });
      map.addThing(this.rotatePoint);
    }
 
    //开启旋转
    this.rotatePoint.start(center);
  },
  stopRotatePoint() {
    if (this.rotatePoint) {
      this.rotatePoint.stop();
    }
  },
};