赣州市洪水风险预警系统二维版本
xiebin
2023-03-02 b39483c96ae572121d3c619c0b9d37634e682cc4
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
$(function(){
    var bmapChart = echarts.init(document.getElementById('map'))
      bmapChart.setOption({
    bmap: {
      center: [115.93675,28.701835],
      zoom: 12,
      roam: true,
      mapStyle: {
        styleJson: [{
          'featureType': 'water',
          'elementType': 'all',
          'stylers': {
            'color': '#234768'
          }
        }, {
          'featureType': 'land',
          'elementType': 'all',
          'stylers': {
            'color': '#183a5f'
          }
        }, {
          'featureType': 'railway',
          'elementType': 'all',
          'stylers': {
            'visibility': 'on'
          }
        }, {
          'featureType': 'highway',
          'elementType': 'all',
          'stylers': {
            'color': '#3f65ad',
            'visibility': 'off'
          }
        }, {
          'featureType': 'highway',
          'elementType': 'labels',
          'stylers': {
            'visibility': 'off'
          }
        }, {
          'featureType': 'arterial',
          'elementType': 'geometry',
          'stylers': {
            'color': '#175fff'
          }
        }, {
          'featureType': 'arterial',
          'elementType': 'geometry.fill',
          'stylers': {
            'color': '#173758'
          }
        }, {
          'featureType': 'poi',
          'elementType': 'all',
          'stylers': {
            'visibility': 'on'
          }
        }, {
          'featureType': 'green',
          'elementType': 'all',
          'stylers': {
            'visibility': 'off'
          }
        }, {
          'featureType': 'subway',
          'elementType': 'all',
          'stylers': {
            'visibility': 'off'
          }
        }, {
          'featureType': 'manmade',
          'elementType': 'all',
          'stylers': {
            'color': '#1e4584'
          }
        }, {
          'featureType': 'local',
          'elementType': 'all',
          'stylers': {
            'color': '#183a5f'
          }
        }, {
          'featureType': 'arterial',
          'elementType': 'labels',
          'stylers': {
            'visibility': 'on'
          }
        }, {
          'featureType': 'boundary',
          'elementType': 'all',
          'stylers': {
            'color': '#1d4570'
          }
        }, {
          'featureType': 'building',
          'elementType': 'all',
          'stylers': {
            'color': '#1d4570'
          }
        },  // 行政标注
          {
              "featureType": "label",
              "elementType": "labels.text.fill",
              "stylers": {
                  "color": "#ffffff",
                  "visibility": "on"
              }
          },
          {
              "featureType": "label",
              "elementType": "labels.text.stroke",
              "stylers": {
                  "color": "#444444",
                  "visibility": "on"
              }
          }]
      }
    },
    tooltip:{
      trigger: 'item',
    },
    series: []
    });
    
 
    //echart获取百度地图实例对象
    var ecModel = bmapChart._model;
    var bmap = null;
    ecModel.eachComponent('bmap', function (bmapModel) {            
        if(bmap == null){
             bmap = bmapModel.__bmap;
        }
    });
    var infoBoxTemp = null;
    bmap.enableScrollWheelZoom(true);
    //********************     江西省边界线           *******************
    getBoundary();
    function getBoundary(){       
        var bdary = new BMap.Boundary();
        var name = "江西省";
        bdary.get(name, function(rs){       //获取行政区域
            var count = rs.boundaries.length; //行政区域的点有多少个
            for(var i = 0; i < count; i++){
                var ply = new BMap.Polygon(rs.boundaries[i], 
                          {
                              strokeWeight: 4, //设置多边形边线线粗
                               strokeOpacity: 1, //设置多边形边线透明度0-1
                               StrokeStyle: "solid", //设置多边形边线样式为实线或虚线,取值 solid 或 dashed
                               strokeColor: "#378eef", //设置多边形边线颜色
                               fillColor: "#ffffff",
                               fillOpacity:0.01
                              }); //建立多边形覆盖物
                bmap.addOverlay(ply);  //添加覆盖物
                bmap.setViewport(ply.getPath());    //调整视野         
            }                
        });   
    }
 
    
    siteQuery("W", "switchWater"); //水质
    siteQuery("A", "switchAir"); //空气
    siteQuery("S", "switchSoil"); //土壤
    siteQuery("M", "switchWeater"); //气象
    function siteQuery(elementType, switchtest){
        $.ajax({
            url: getNativePath() + "naturalFactors/findStationEleInfoByType.do",
            type: "get",
            data:{"elementType":elementType},
            dataType: "json",
            success: function(result) {
                var markArr = [];
                if(switchtest == "switchWater"){
                    siteQueryData(result, markArr, elementType);
                }
                layui.use(['form', 'layedit', 'laydate'], function(){
                      var form = layui.form, layer = layui.layer, layedit = layui.layedit, laydate = layui.laydate;
                      //监听指定开关
                      form.on('switch('+switchtest+')', function(data){
                          //判断上一个窗体是否存在,若存在则执行close
                          if(infoBoxTemp){ infoBoxTemp.close(); }
                          if(this.checked){
                              form.render();
                              siteQueryData(result, markArr, elementType);
                          }else{
                              for(var i=0; i<markArr.length; i++){
                                  bmap.removeOverlay(markArr[i]);
                              }
                          }
                      });
                });
            }
        });
    }
    
    function siteQueryData(result, markArr, elementType){
        var myIcon = new BMap.Icon("images/water1.png", new BMap.Size(75, 75));
        if(elementType == "A"){
            myIcon = new BMap.Icon("images/default1.png", new BMap.Size(75, 75));
        }else if(elementType == "S"){
            myIcon = new BMap.Icon("images/soil1.png", new BMap.Size(75, 75));
        }else if(elementType == "M"){
            myIcon = new BMap.Icon("images/weather1.png", new BMap.Size(75, 75));
        }
        
        if(result.data.length <= 0){
            return false;
        }
        for(var i=0; i<result.data.length; i++){
             var point = new BMap.Point(result.data[i].lon, result.data[i].lat); 
            var mylable = new BMap.Label(result.data[i].stationName, {
                 offset:new BMap.Size(45, 27)
            });
            mylable.setStyle({ color : "#1bd0ad", fontSize : "14px", border:"0px", "background":"transparent"})
            var marker = new BMap.Marker(point, {icon: myIcon}); 
            var stcd = result.data[i].stationName;
                 marker.setLabel(mylable);
                  bmap.addOverlay(marker);
                  markArr.push(marker);
                  addClickHandler(stcd,marker, result.data[i]);
            if(i == 0){
                bmap.centerAndZoom(new BMap.Point(result.data[i].lon, result.data[i].lat), 8);
            }
        } 
    }
    
    function addClickHandler(stcd, marker, result){
        marker.addEventListener("click",function(e){
            openInfo(stcd,e, result)
        });
    }
    
    function openInfo(stcd,e, data){
//        console.log(data)
        //添加更新时间,根据图片路径进行判断
        var uptime = data.valueList['0'].uptime;
        var p = e.target;
        var src = e.currentTarget.Bc.childNodes[0].childNodes[0].src;
        if(src.indexOf('water') != -1){
            var sthtml = '<div style="color: #56cedf;font-weight: bold;"><label>水环境:</label><span>'+ uptime + '</span></div>';
        }else if(src.indexOf('default') != -1){
            var sthtml = '<div style="color: #1bd0ad;font-weight: bold;"><label>空气:</label><span>'+ uptime + '</span></div>';
        }else if(src.indexOf('soil') != -1){
            var sthtml = '<div style="color: #fca501;font-weight: bold;"><label>土壤:</label><span>'+ uptime + '</span></div>';
        }else if(src.indexOf('weather') != -1){
            var sthtml = '<div style="color: #df5f13;font-weight: bold;"><label>气象:</label><span>'+ uptime + '</span></div>';
        }        
        var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
            for(var j=0; j<data.valueList.length; j++){
                if(data.valueList[j].unit == "无"){
                    data.valueList[j].unit = "";
                }
                if(typeof data.valueList[j].value != 'number'){
                    data.valueList[j].value = 0;
                }
                
                sthtml += '<div><label>'+data.valueList[j].fieldname+':</label><span>'+parseFloat(data.valueList[j].value).toFixed(2)+data.valueList[j].unit+'</span></div>'
            }
            sthtml = '<div class="map-pup-til">'+data.stationName+'</div><div class="map-pup">'+sthtml+'<div class="jiao-icon"><span></span></div></div>';
         var infoBox = new BMapLib.InfoBox(bmap, sthtml, {
                boxStyle:{
                    width: "260px",
                    height: "200px",
                    marginBottom: "35px",
                    marginleft:"6px",
                    backgroundColor:"#253b75",
                    color:"#fff",
                    border:"1px solid #188488",
                    borderRadius:"3px"
                },
                closeIconUrl: "images/close-pup.png",
                closeIconMargin:'4px',
                closeIconZIndex:1,
                enableAutoPan: true,
                align: INFOBOX_AT_TOP
            });
               //判断上一个窗体是否存在,若存在则执行close
              if(infoBoxTemp){ infoBoxTemp.close(); }
            infoBoxTemp = infoBox;
            infoBox.open(point);    
            $('.map-pup').niceScroll({
                        cursorcolor: "#ccc",//#CC0071 光标颜色
                        cursoropacitymax: 1, //改变不透明度非常光标处于活动状态(scrollabar“可见”状态),范围从1到0
                        touchbehavior: false, //使光标拖动滚动像在台式电脑触摸设备
                        cursorwidth: "5px", //像素光标的宽度
                        cursorborder: "0", // 游标边框css定义
                        cursorborderradius: "5px",//以像素为光标边界半径
                        autohidemode: false //是否隐藏滚动条
                    });
            $(".infoBox").hover(function(){
                bmap.disableScrollWheelZoom();
            }, function(){
                bmap.enableScrollWheelZoom();
            })
    }
    
});