wangzhibo
2021-09-26 bf2a306685c07eb5e610669a17c4dd79651ecbe7
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
'use script' //开发环境建议开启严格模式
  ;
 
function addItemToLayer(item, target_layer) {
 
  $.getJSON("http://58.246.27.194:7012/dataapi/Bdata?bid=get_1004_single_path&siteid=" + item["code"], {
    datatime1: "2021-07-01 10:00:00",
    datatime2: "2021-07-01 10:15:00"
  }, (result) => {
 
    if (result.data.result.length > 0) {
      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({
        attr: result.data.result[0],
        style: {
          url: "gltf/" + (item["code"]).substring(0, 2) + ".gltf",
          scale: 0.5,
          minimumPixelSize: 20,
          highlight: {
            type: mars3d.EventType.click,
            silhouette: true,
            silhouetteColor: "#ff0000",
            silhouetteSize: 4,
          },
          label: {
            //不需要文字时,去掉label配置即可
            text: item["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: 0,
          },
        },
      });
      graphic.position = tmpPositionProperty;
      target_layer.addGraphic(graphic);
    }
  });
 
}
(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
 
    //初始化[仅执行1次]
    create() {
 
      map.clock.shouldAnimate = true;
 
      map.clock.startTime = Cesium.JulianDate.fromDate(new Date("2021-07-01 10:00:00"));
      map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2021-07-01 10:00:00"));
      map.clock.stopTime = Cesium.JulianDate.fromDate(new Date("2021-07-01 10:15:00"));
      map.clock.multiplier = 5.0;
      map.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
 
      let taxi_layer = new mars3d.layer.GraphicLayer({
        name: '移动监测点',
        pid: 99, //图层管理 中使用,父节点id
        center: {"lat":30.62156,"lng":121.44918,"alt":48716,"heading":359,"pitch":-40},
        show: true,
        onWidget: "widgetsTS/taxi_layer_setting/widget.js",
      });
      map.addLayer(taxi_layer);
 
      taxi_layer.on(mars3d.EventType.click, function (event) {
        console.log("监听layer,单击了矢量对象", event);
        //console.log(event.graphic?.attr)
        var item = event.graphic?.attr;
        //haoutil.msg('单击了:' + item['高校名称'])
      });
      taxi_layer.bindPopup(function (event) {
        let item = event.graphic?.attr;
        var html =
          "<br/>类型:&nbsp;" +
            item["code"].substring(0, 2) == "BS" ? "公交车" : "出租车" +
            "<br />车辆编号:&nbsp;" +
            item["code"] +
            "<br/>数据时间:&nbsp;" +
            item["datatime"] +
            "<br />瞬时车速:&nbsp;&nbsp;&nbsp;" +
            item["speed"] + "&nbsp;(km/h)" +
            "<br />粉尘PM2.5:&nbsp;" +
            item["pm25"] + "&nbsp;(ug/m3)" +
            "<br />粉尘PM10:&nbsp;&nbsp;" +
            item["pm10"] + "&nbsp;(ug/m3)" +
            "<br />NO浓度:&nbsp;&nbsp;&nbsp;" +
            item["no"] + "&nbsp;(ug/m3)" +
            "<br />NO2浓度:&nbsp;&nbsp;" +
            item["no2"] + "&nbsp;(ug/m3)" +
            "<br />NO+NO2浓度:&nbsp;" +
            item["nox"] + "&nbsp;(ug/m3)" +
            "<br />CO浓度值:&nbsp;&nbsp;&nbsp;&nbsp;" +
            item["co"] +"&nbsp;&nbsp;(mg/m3)"+
            "<br /><br /><p><a href='#' onclick='javascript:showDetail(1001,\"" + item["code"] + "\")' ><span style='color:#ff00ff'>历史轨迹回放</span></a></p>";
        return html;
      });
 
      $.getJSON("http://58.246.27.194:7012/dataapi/Bdata?bid=get_1004_list_by_userid&userid=2", (result) => {
        for (var i = 0, len = result.data.result.length; i < len; i++) {
          let item = result.data.result[i];
          addItemToLayer(item, taxi_layer);
        }
      });
 
    }
 
 
    //每个窗口创建完成后调用
    winCreateOK(opt, result) {
 
    }
    //打开激活
    activate() {
 
    }
    //关闭释放
    disable() { }
 
 
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget)
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d)