wangzhibo
2021-10-04 1a787586549ef44775cdbd05d7150bba2cbb69f6
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
"use script"; //开发环境建议开启严格模式
//系统 功能入口
 
var data_list_1004;
var data_list_1004_paths = new Map();
var taxi_layer;
 
 
function addTaxiLayer(item) {
 
  taxi_layer = new mars3d.layer.GraphicLayer({
    id: item.id,
    name: item.name,
    pid: item.pid, //图层管理 中使用,父节点id
    center: { "lat": 30.62156, "lng": 121.44918, "alt": 48716, "heading": 359, "pitch": -40 },
    noCenter: true,
    style_selected: item.style_selected,
    style_options: item.styleoptions,
    show: item.show,
    onWidget: "widgetsTS/taxi_layer_setting/widget.js",
  });
  map.addLayer(taxi_layer);
 
  taxi_layer.on(mars3d.EventType.click, function (event) {
    console.log("监听layer,单击了矢量对象", event);
    var item = event.graphic?.attr;
    console.log(item);
  });
  taxi_layer.bindPopup(bindPopupFunction);
 
  getTaxiListFromServerByUserId(taxi_layer);
}
 
function getTaxiListFromServerByUserId(tmpLayer) {
 
  setTaxiLayerMapClock();
  $.getJSON(mars3d.global_variables.nodejs_url_predix + "dataapi/Bdata?bid=get_1004_list_by_userid&userid=" + mars3d.global_variables.userid, (result) => {
    data_list_1004 = result.data.result;
    for (var i = 0, len = result.data.result.length; i < len; i++) {
      let item = result.data.result[i];
      getTaxiPathFromServerbySN(item, tmpLayer);
    }
  });
 
}
 
function setTaxiLayerMapClock() {
  map.clock.shouldAnimate = true;
  map.clock.startTime = Cesium.JulianDate.fromDate(new Date(mars3d.global_variables.queryDataTStart));
  map.clock.currentTime = Cesium.JulianDate.fromDate(new Date(mars3d.global_variables.queryDataTStart));
  map.clock.stopTime = Cesium.JulianDate.fromDate(new Date(mars3d.global_variables.queryDataTEnd));
  map.clock.multiplier = 2.0;
  map.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
 
  var last_time_second = 0;
 
 
  map.on(mars3d.EventType.clockTick, function (event) {
 
    var current_date = new Date(Cesium.JulianDate.toDate(event._currentTime));
 
    if (current_date.getSeconds() != last_time_second) {
      last_time_second = current_date.getSeconds();
      changeTaxiLayerStyleAndAttr(getFormattedDateTime(current_date));
    }
  });
}
 
function changeTaxiLayerStyleAndAttr(current_date) {
 
  var tmpattr;
  //current_date = "2021-07-01 00:00:32";
  taxi_layer.eachGraphic(function (item) {
    tmpattr = getTaxiAttrFromTimeListData(current_date, data_list_1004_paths.get(item.options.id));
    //console.log(tmpattr);
    if (tmpattr && tmpattr != null) {
      //item.options.attr = tmpattr;
      item.setOptions({
        attr: tmpattr,
        style: {
          label: {
            color: getLayerPointColorByQindexandValue(1004, item._layer.options.style_selected, tmpattr[item._layer.options.style_selected]),
          }
        }
      })
      //item.options.style.label.color = getLayerPointColorByQindexandValue(1004, item._layer.options.style_selected, tmpattr[item._layer.options.style_selected]);
      //console.log('color has been changed.' + item.options.id);
    }
 
  });
}
function getTaxiAttrFromTimeListData(datetime, datalist) {
  for (var i = 0; i < datalist.length; i++) {
    if (datalist[i]["datatime"] == datetime) {
      return datalist[i];
    }
  }
}
 
function getTaxiPathFromServerbySN(item, target_layer) {
 
  $.getJSON(mars3d.global_variables.nodejs_url_predix + "dataapi/Bdata?bid=get_1004_single_path&siteid=" + item["code"], {
    datatime1: mars3d.global_variables.queryDataTStart,
    datatime2: mars3d.global_variables.queryDataTEnd
  }, (result) => {
 
    if (result.data.result.length > 0) {
      // 保存临时数据,为后续替换颜色做准备。
      data_list_1004_paths.set(result.data.result[0].code, result.data.result);
      var tmpPositionProperty = new Cesium.SampledPositionProperty();
      for (var i = 0, len = result.data.result.length; i < len; i++) {
        let item = result.data.result[i];
        //console.log(item);
        tmpPositionProperty.addSample(Cesium.JulianDate.fromDate(new Date(item["datatime"])), Cesium.Cartesian3.fromDegrees(item["lon"], item["lat"], 0.2))
      }
 
      let graphic = new mars3d.graphic.ModelEntity({
        id: result.data.result[0].code,
        attr: result.data.result[0],
        style: {
          url: "gltf/" + (result.data.result[0]["code"]).substring(0, 2) + ".gltf",
          scale:5,
          minimumPixelSize: 20,
          highlight: {
            type: mars3d.EventType.click,
            silhouette: true,
            silhouetteColor: "#ff0000",
            silhouetteSize: 4,
          },
          label: {
            //不需要文字时,去掉label配置即可
            text: result.data.result[0]["code"],
            font_size: 16,
            // TODO need to be changed according to qindex color.
            color: "#ff00ff",
            outline: true,
            outlineColor: "#000000",
            pixelOffsetY: -20,
            distanceDisplayCondition: true,
            distanceDisplayCondition_far: 50000,
            distanceDisplayCondition_near: 100,
          },
        },
      });
      graphic.position = tmpPositionProperty;
      target_layer.addGraphic(graphic);
    }
  });
}
 
function getFormattedDateTime(date) {
 
  var year = date.getFullYear();//年
  var month = date.getMonth();//月
  var day = date.getDate();//日
  var hours = date.getHours();//时
  var mins = date.getMinutes();//分
  var seconds = date.getSeconds();//秒
 
  return date.getFullYear() + "-" +
    ((month + 1) > 9 ? (month + 1) : "0" + (month + 1)) + "-" +
    (day > 9 ? day : ("0" + day)) + " " +
    (hours > 9 ? hours : ("0" + hours)) + ":" +
    (mins > 9 ? mins : ("0" + mins)) + ":" +
    (seconds > 9 ? seconds : ("0" + seconds));
}