zhaoxing
2022-10-19 6c1b125337b8a53e57151f36661ded58daf4d534
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
(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //弹窗配置
    get view() {
      return {
        type: "window",
        url: "view.html",
        windowOptions: {
          width: 350,
        },
      };
    }
 
    reloadData(new_taxi_sn) {
      // this.viewWindow.resetStartQueryTaxiDataText(new_taxi_sn);
      this.taxi_sn = new_taxi_sn;
 
      if (this.startGraphic) {
        this.startGraphic.remove();
        this.startGraphic = null;
      }
      if (this.endGraphic) {
        this.endGraphic.remove();
        this.endGraphic = null;
      }
      this.routeLayer.clear();
    }
 
    clearReplayLayers() {
      this.pointLayer.clear();
      this.routeLayer.clear();
    }
 
    addTaxiReplayGraphic(points) {
 
      this.startGraphic = new mars3d.graphic.BillboardEntity({
        position: points[0],
        style: {
          image: this.path + "img/start.png",
          scale: 1,
          horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
          verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
          clampToGround: true,
        },
      });
      this.pointLayer.addGraphic(this.startGraphic);
 
      this.endGraphic = new mars3d.graphic.BillboardEntity({
        position: points[points.length - 1],
        style: {
          image: this.path + "img/end.png",
          scale: 1,
          horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
          verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
          clampToGround: true,
        },
      });
      this.pointLayer.addGraphic(this.endGraphic);
 
 
 
      let Pointsdata = mars3d.global_variables.singleTaxiReplayData
      for (var i = 0, len = Pointsdata.length; i < len-1; i++) {
        var item = Pointsdata[i];
        var item2 = Pointsdata[i+1];
        var lng = Number(item["lon"]); //经度
        var lat = Number(item["lat"]); //纬度
        var lng2 = Number(item2["lon"]); //经度
        var lat2 = Number(item2["lat"]); //纬度
        var position = null;
        var position2 = null;
        if (lng && lat&&lng2&&lat2) {
          position = Cesium.Cartesian3.fromDegrees(lng, lat);
          position2 = Cesium.Cartesian3.fromDegrees(lng2, lat2);
        }
        item = changeNullAndundefinedToEmpty(item)
      let graphic = new mars3d.graphic.PolylineEntity({
        positions: [position,position2],
        style: {
          width: 10,
          material: new mars3d.material.LineFlowMaterialProperty({
            color:this.viewWindow.getLayerPointColorByQindexandValue(1004,this.qindex, item[this.qindex]),
            image: "./img/textures/arrow2.png",
            repeat: new Cesium.Cartesian2(1, 1),
            speed: 40, //速度,建议取值范围1-100
          })
        },
      });
      this.routeLayer.addGraphic(graphic);
      }
      // console.log(items,"items")
      // let graphic = new mars3d.graphic.PolylineEntity({
      //   positions: points,
      //   style: {
      //     width: 10,
      //     material: new mars3d.material.LineFlowMaterialProperty({
      //       color: Cesium.Color.AQUA,
      //       image: "./img/textures/arrow2.png",
      //       repeat: new Cesium.Cartesian2(50, 1),
      //       speed: 40, //速度,建议取值范围1-100
      //     })
      //   },
      // });
      // this.routeLayer.addGraphic(graphic);
      this.routeLayer.flyTo();
    }
 
    addTaxiPointInfoGraphic() {
        var Pointsdata = mars3d.global_variables.singleTaxiReplayData
        for (var i = 0, len = Pointsdata.length; i < len-1; i++) {
          var item = Pointsdata[i];
          var item2 = Pointsdata[i+1];
          var lng = Number(item["lon"]); //经度
          var lat = Number(item["lat"]); //纬度
          var lng2 = Number(item2["lon"]); //经度
          var lat2 = Number(item2["lat"]); //纬度
          var position = null;
          var position2 = null;
          if (lng && lat&&lng2&&lat2) {
            position = Cesium.Cartesian3.fromDegrees(lng, lat);
            position2 = Cesium.Cartesian3.fromDegrees(lng2, lat2);
          }
          item = changeNullAndundefinedToEmpty(item)
          var CircleEntity = new mars3d.graphic.CorridorEntity({
            positions: [position,position2],
            style: {
              // length: 60.0,
              width: 10.0,
              height: 0,
              cornerType: Cesium.CornerType.BEVELED,
              // radius: 8.0,
              diffHeight: this.qindex == "co" ? 300 * item[this.qindex] :  item[this.qindex]  || item[this.qindex] == "/" ? 500 : item[this.qindex], //高度
              color:this.viewWindow.getLayerPointColorByQindexandValue(1004,this.qindex, item[this.qindex]),
              opacity: 0.6,
              // rotationDegree: 45,
              highlight: {
               opacity: 1
              }
            },
            item: item,
            popup:"编号:" +
            item["code"] +
            "<br />时间:" +
            item["datatime"] +
            "<br />车速:" +
            item["speed"] +
            "<table>" +
            "<tr><td>PM₂.₅:</td><td align= right>" + item["pm25"] + '&nbsp' + "</td><td>μg/m³</td></tr>" +
            "<tr><td>PM₁₀:</td><td align= right>" + item["pm10"] + '&nbsp' + "</td><td>μg/m³</td></tr>" +
            "<tr><td>NO:</td><td align= right>" + item["no"] + '&nbsp' + "</td><td>μg/m³</td></tr>" +
            "<tr><td>NO₂:</td><td align= right>" + item["no2"] + '&nbsp' + "</td><td>μg/m³</td></tr>" +
            "<tr><td>NOₓ: </td><td align= right>" + item["nox"] + '&nbsp' + "</td><td>μg/m³</td></tr>" +
            "<tr><td>CO:</td><td align= right>" + item["co"] + '&nbsp' + "</td><td>mg/m³</td></tr>" +
            "</table>" 
          });
          this.routeLayer.addGraphic(CircleEntity);
        }
        this.routeLayer.flyTo();
    }
 
    setSingleTaxiReplayData(datas) {
      mars3d.global_variables.singleTaxiReplayData = datas;
    }
 
    refreshDetailTable(tmpattr) {
      this.viewWindow.refreshDetailTable(tmpattr);
    }
 
    //初始化[仅执行1次]
    create() {
 
      this.gaodeRoute = new mars3d.query.GaodeRoute({
        // key: ['ae29a37307840c7ae4a785ac905927e0'],
      });
      this.gaodePOI = new mars3d.query.GaodePOI({
        // key: ['ae29a37307840c7ae4a785ac905927e0'],
      });
 
      //图层管理使用的分组
      this.groupLayer = new mars3d.layer.GroupLayer({
        name: this.config.name,
        pid: 50, //图层管理 中使用,父节点id
      });
 
      //创建矢量数据图层
      this.pointLayer = new mars3d.layer.GraphicLayer({
        name: this.config.name + "-起止点",
      });
      this.groupLayer.addLayer(this.pointLayer); //加入分组
 
      this.routeLayer = new mars3d.layer.GraphicLayer({
        name: this.config.name + "-路线",
      });
      this.groupLayer.addLayer(this.routeLayer); //加入分组
    }
    //每个窗口创建完成后调用
    winCreateOK(opt, result) {
      this.viewWindow = result;
      this.appDateHourStart = mars3d.global_variables.queryDataTStartTaxi;
      this.appDateHourEnd = mars3d.global_variables.queryDataTEnd;
      this.nodejs_url_predix = mars3d.global_variables.nodejs_url_predix;
      this.taxi_sn = this.config.params;
      this.viewWindow.resetStartQueryTaxiDataText(this.taxi_sn);
 
    }
    //打开激活
    activate() {
      this.map.addLayer(this.groupLayer);
      this.map.clock.shouldAnimate = false;
      this.old_map_clock_startTime = this.map.clock.startTime;
      this.old_map_clock_currentTime = this.map.clock.currentTime;
      this.old_map_clock_stopTime = this.map.clock.stopTime;
      this.old_map_clock_multiplier = this.map.clock.multiplier;
      mars3d.global_variables.is_single_taxi_replaying = true;
      this.qindex = mars3d.global_variables.style_selected;
    }
    //关闭释放
    disable() {
      this.map.clock.shouldAnimate = true;
      this.map.clock.startTime = this.old_map_clock_startTime;
      this.map.clock.currentTime = this.old_map_clock_currentTime;
      this.map.clock.stopTime = this.old_map_clock_stopTime;
      this.map.clock.multiplier = this.old_map_clock_multiplier;
      mars3d.global_variables.is_single_taxi_replaying = false;
 
      if (this.startGraphic) {
        this.startGraphic.remove();
        this.startGraphic = null;
      }
      if (this.endGraphic) {
        this.endGraphic.remove();
        this.endGraphic = null;
      }
      this.map.removeLayer(this.groupLayer);
 
    }
    
    //漫游自动结束 或点击 停止导航按钮 后,重置界面和操作
    pauseReplay() {
      // 暂停回放
      this.map.clock.shouldAnimate = false;
    }
 
    ContinueReplay() {
      // 继续回放
      this.map.clock.shouldAnimate = true;
    }
 
    //取消当前的视角跟随
    removeTrack() {
      if (this.nowFline) {
        this.nowFline.setCameraOptions({ type: "" });
      }
      this.map.trackedEntity = undefined;
    }
    //==============开始导航===================
    startDH() {
      //导航前释放之前的所有导航操作
      this.map.clock.shouldAnimate = true;
      this.map.clock.startTime = Cesium.JulianDate.fromDate(new Date(this.appDateHourStart));
      this.map.clock.currentTime = Cesium.JulianDate.fromDate(new Date(this.appDateHourStart));
      this.map.clock.stopTime = Cesium.JulianDate.fromDate(new Date(this.appDateHourEnd));
      this.map.clock.multiplier = 2.0;
 
    }
    //============开始视角跟随=============
    startGS() {
      this.nowFline.setCameraOptions({
        type: "gs",
        heading: 0,
        radius: 2500,
      });
    }
   
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget);
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d);