wangzhibo
2021-09-27 0bfff4dc529cc7c20e1cad96e570bf61f3809e9b
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
"use script"; //开发环境建议开启严格模式
//系统 功能入口
 
 
var allLayer_color_nodata = '#C0C0C0';
var guokong_color_list = ['#0EE839', '#FEFE23', '#FD9D00', '#F70F0D', '#8A0B73', '#88041E'];
var guokong_qindex_color_list = { 'pm25': [35, 75, 115, 150, 250], 'pm10': [50, 150, 250, 350, 420], 'no2': [100, 200, 700, 1200, 2340], 'co': [5, 10, 35, 60, 90] };
var guokong_data_list;
 
 
function addWMSLayer(item) {
 
  var wmsLyer = new mars3d.layer.WmsLayer({
    id: item.id,
    pid: item.pid,
    name: item.name,
    type: "wms",
    url: mars3d.global_variables.geoserver_url_predix + "/geoserver/konglu_58/wms",
    layers: "konglu_58:" + item.geoname_prefix + mars3d.global_variables.queryDataType,
    crs: "EPSG:4326",
    parameters: {
      "styles": item.style_prefix + item.style_selected,
      "transparent": "true",
      "format": "image/png",
      "viewparams": "userid:" + mars3d.global_variables.userid + ";datatime:" + mars3d.global_variables.queryDataTStartGeo
    },
    center: { "lat": 30.487351, "lng": 121.613269, "alt": 54033, "heading": 359, "pitch": -40 },
    noCenter: true,
    maxLength: 35000,
    getFeatureInfoParameters: {
      feature_count: 10
    },
    //单击高亮及其样式
    highlight: {
      type: "wallP",
      diffHeight: 300,
      material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.LineFlow, {
        image: "img/textures/fence.png",
        color: "#ffff00",
        speed: 10, //速度,建议取值范围1-100
        axisY: true,
      }),
    },
    popup: "all",
    show: item.show,
    geoname_prefix: item.geoname_prefix,
    style_prefix: item.style_prefix,
    style_selected:item.style_selected,
    style_options: item.styleoptions,
    flyTo: false
  });
 
  //单击事件
  wmsLyer.on(mars3d.EventType.click, function (event) {
    console.log("单击了矢量数据,共" + event.features.length + "条", event);
    console.log(event.layer.options.style_selected);
 
 
    console.log(event.graphic);
    /*
    event.graphic.style.diffHeight = 
 
      diffHeight: 300,
      material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.LineFlow, {
        image: "img/textures/fence.png",
        color: "#ffff00",
        speed: 10, //速度,建议取值范围1-100
        axisY: true,
      }),
      */
  });
 
  map.addLayer(wmsLyer);
 
}
 
function addGuokongLayerDIV(item) {
 
  var guokongLayer = new mars3d.layer.DivLayer({
    id: item.id,
    pid: item.pid, //图层管理 中使用,父节点id
    name: item.name,
    style_selected: item.style_selected,
    style_options: item.styleoptions,
    show: item.show
  });
  map.addLayer(guokongLayer);
 
  guokongLayer.on(mars3d.EventType.click, function (event) {
    console.log("监听layer,单击了矢量对象", event);
    console.log(event.graphic?.attr)
    var item = event.graphic?.attr;
    //haoutil.msg('单击了:' + item['高校名称'])
  });
 
  guokongLayer.bindPopup(function (event) {
    let item = event.graphic?.attr;
    //console.log(item);
    var html =
      "站点编号:" +
      item["code"] +
      "<br />站点名称:" +
      item["name"] +
      "<br />数据时间:" +
      item["datatime"] +
      "<br />PM2.5:" +
      item["PM25"] + "ug/m3" +
      "<br />PM10:" +
      item["PM10"] + "ug/m3" +
      "<br />NO2:" +
      item["NO2"] + "ug/m3" +
      "<br />CO:" +
      item["CO"] + "ug/m3" +
      "<br />SO2:" +
      item["SO2"] + "ug/m3" +
      "<br /><br /><p><a href='#' onclick='javascript:showDetail(1001,\"" + item["code"] + "\")' >详细信息</a></p>";
    return html;
  });
 
  guokongLayer.changeColor = function () {
 
    guokongLayer.clear(true);
 
    addGuokongPointResutToLayer(this, guokong_data_list);
 
  }
  // add 国控点
  getGuokongPointFromServer(guokongLayer);
 
}
 
function getGuokongPointFromServer(tmplayer) {
 
  $.getJSON(mars3d.global_variables.nodejs_url_predix + "dataapi/Bdata?bid=get_1001_list&datatype=" + mars3d.global_variables.queryDataType + "&datatime=" + mars3d.global_variables.queryDataTStart + "&qindex=pm25&pageno=1&pagesize=1000", (result) => {
    guokong_data_list = result.data.result;
    addGuokongPointResutToLayer(tmplayer, result.data.result);
  });
 
}
 
function addGuokongPointResutToLayer(tmplayer, items) {
  for (var i = 0, len = items.length; i < len; i++) {
    var item = items[i];
    var jd = item.lon;
    var wd = item.lat;
    var clr = getGuokongPointColor(tmplayer.options.style_selected, item[(tmplayer.options.style_selected).toUpperCase()]);
    var graphic = new mars3d.graphic.DivLightPoint({
      position: Cesium.Cartesian3.fromDegrees(jd, wd),
      style: {
        color: clr,
        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
        highlight: {
          type: "divLightPoint",
          diffHeight: item[(tmplayer.options.style_selected).toUpperCase()],
          material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.CircleWave, {
            color: clr,
            count: 3,
            speed: 20,
          }),
        },
        distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 200000), //按视距距离显示
      },
      show: true,
      attr: item,
    });
    tmplayer.addGraphic(graphic);
  }
 
 
}
 
function getGuokongPointColor(qindex, value) {
 
  if (!value || value == null || value == 'null') {
    return allLayer_color_nodata;
  }
  for (var key in guokong_qindex_color_list) {
    if (key == qindex) {
      for (let i = guokong_qindex_color_list[key].length; i > -1; i--) {
        if (value > guokong_qindex_color_list[key][i]) {
          return guokong_color_list[i + 1];
        }
      }
    }
  }
}