riku
2024-02-27 7578c3ff65329b2269f099475eb687e963efac1c
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
function CompanyLayer(options) {
  // 信访企业
  this.companys = []
  // 信访企业地图标记
  this.companyMarker = []
  this.companyInfoWindow = []
  this.isCompanyShow = false
 
  this.factor = 'VOC'
  this.startTime = '00:00:00'
  this.endTime = '05:59:59'
 
  this.deviceCode = '0d0000000001'
  this.epwResult
 
  this.zoomEvent = false
  this.lastZoom
  this.zoomLevel = 17
 
  this.searched = false
}
 
CompanyLayer.prototype = {
  init: function () {
    this.searchBox()
  },
  enable: function () {
    this.isEnable = true
    this.uiChange(true)
    this.zoomEvent = false
  },
  disable: function () {
    this.isEnable = false
    MapUtil._map.off('zoomend', this._onZoom)
    MapUtil.removeViews(this.companyMarker)
  },
  /**
   * UI显示隐藏变化
   */
  uiChange: function (isShow) {
    if (isShow) {
      $('#epw_model').slideDown("fast")
    }
  },
  searchBox: function () {
    var that = this
 
    var time = new Date();
    var day = ("0" + time.getDate()).slice(-2);
    var month = ("0" + (time.getMonth() + 1)).slice(-2);
    var today = time.getFullYear() + "-" + (month) + "-" + (day);
    $('#epw_date').val(today)
 
    $('.epw_radio').on('click', function () {
      var type = this.value
      switch (type) {
        case '0':
          that.startTime = '00:00:00'
          that.endTime = '05:59:59'
          break;
        case '1':
          that.startTime = '06:00:00'
          that.endTime = '08:59:59'
          break;
        case '2':
          that.startTime = '09:00:00'
          that.endTime = '11:59:59'
          break;
        case '3':
          that.startTime = '12:00:00'
          that.endTime = '13:59:59'
          break;
        case '4':
          that.startTime = '14:00:00'
          that.endTime = '16:59:59'
          break;
        case '5':
          that.startTime = '17:00:00'
          that.endTime = '19:59:59'
          break;
        case '6':
          that.startTime = '20:00:00'
          that.endTime = '23:59:59'
          break;
        default:
          break;
      }
    })
 
    $('.epw_f_radio').on('click', function () {
      that.factor = this.value
      if (that.searched) {
        that.refreshEPW() 
      }
    })
 
    $('#btn_search_epw').on('click', function () {
      that.searched = true
      that.getEPWResult()
    })
  },
  /**
   * 获取当前数据对应的权重分析结果
   */
  getEPWResult: function (callback) {
    var date = $('#epw_date').val()
    var st = date + ' ' + this.startTime
    var et = date + ' ' + this.endTime
 
    DataUtil.toggleLoading()
    HttpService.getEPWResult(this.deviceCode, st, et, undefined, function (data) {
      this.epwResult = data
      if (!this.isCompanyShow) {
        this.toggleCompany()
      } else {
        this.refreshEPW()
      }
    }.bind(this))
  },
  /**
   * 显示或隐藏信访企业
   */
  toggleCompany: function () {
    this.isCompanyShow = !this.isCompanyShow
 
    if (!this.isCompanyShow) {
      MapUtil.removeViews(this.companyMarker)
      return
    }
 
    this.refreshEPW()
  },
  refreshEPW: function () {
    var that = this
    if (this.companys.length == 0) {
      HttpService.getCompanyInfo(function (data) {
        this.companys = data
        var datas = []
        var index = 1
        var lnglats = []
        this.companys.forEach(element => {
          if (element.ciLongitude != undefined) {
            datas.push({
              id: index,
              name: element.ciName,
            })
            lnglats.push([element.ciLongitude, element.ciLatitude])
            index++
          }
        });
        MapUtil.convertFromGPS(lnglats, function (gd) {
 
          for (let i = 0; i < datas.length; i++) {
            const element = datas[i];
 
            var mContent = that.getLabelContent(element.name)
            if (mContent == undefined) {
              break
            }
 
            var icon = new AMap.Icon({
              size: new AMap.Size(30, 30),
              imageSize: new AMap.Size(22, 22),
              image: "./asset/mipmap/company.png",
              // imageOffset: new AMap.Pixel(-16, -16) // 相对于基点的偏移位置
            })
 
            var marker = new AMap.Marker({
              position: new AMap.LngLat(gd[i][0], gd[i][1]), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
              // label: {
              //   content: labelContent,
              //   offset: 0,
              //   direction: "top"
              // },
              title: element.name,
              content: mContent[0],
              // icon: icon,
              animation: "AMAP_ANIMATION_DROP"
            });
 
            var w = new AMap.InfoWindow({
              isCustom: true, //使用自定义窗体
              content: that.createInfoWindow(element.name, i),
              offset: new AMap.Pixel(16, -45)
            })
            this.companyInfoWindow.push(w)
 
            //鼠标点击marker弹出自定义的信息窗体
            AMap.event.addListener(marker, 'click', function () {
              that.companyInfoWindow[i].open(MapUtil._map, that.companyMarker[i].getPosition());
            });
 
            this.companyMarker.push(marker)
          }
 
          MapUtil.addViews(this.companyMarker)
          DataUtil.toggleLoading()
        }.bind(this))
      }.bind(this))
    } else {
      for (let i = 0; i < this.companyMarker.length; i++) {
        var m = this.companyMarker[i]
        var element = m.getTitle()
        this.companyInfoWindow[i].setContent(this.createInfoWindow(element, i))
        var labelContent = that.getLabelContent(element)
        if (labelContent == undefined) {
          return
        }
        if (this.lastZoom >= this.zoomLevel) {
          m.setContent(labelContent[0])
        } else {
          m.setContent(labelContent[1])
        }
      }
      MapUtil.addViews(this.companyMarker, false)
      DataUtil.toggleLoading(false)
    }
 
    if (!this.zoomEvent) {
      MapUtil._map.on('zoomend', this._onZoom)
      this.zoomEvent = true
    }
  },
  _onZoom: function () {
    var zoom = MapUtil._map.getZoom()
    if (this.lastZoom  == undefined || (this.lastZoom >= this.zoomLevel && zoom < this.zoomLevel) 
      || (this.lastZoom < this.zoomLevel && zoom >= this.zoomLevel)) {
      if (this.companyMarker != undefined) {
        this.companyMarker.forEach(m => {
          var element = m.getTitle()
          var labelContent = this.getLabelContent(element)
          if (labelContent == undefined) {
            return
          }
          if (zoom >= this.zoomLevel) {
            m.setContent(labelContent[0])
          } else {
            m.setContent(labelContent[1])
          }
        });
        MapUtil.addViews(this.companyMarker, false)
      }
    }
    this.lastZoom = zoom
  },
  getLabelContent: function (company) {
    // var labelContent0 = `<div>${company}</div>`
    var labelContent0 = ''
    var labelContent1 = ''
 
    var icon = "./asset/mipmap/c_level_no.png"
 
    if (this.epwResult != undefined) {
      for (const key in this.epwResult) {
        // if (this.epwResult[key][this.factor] === undefined) {
        //   return undefined
        // }
        var cName = key.split(';')[0]
        if (company === cName) {
          const r = this.epwResult[key]
          var epw = '/', period = "数据无效"
          if (r[this.factor] != undefined) {
            for (const p in r[this.factor]) {
              period = p
              epw = r[this.factor][p]['average']
              break
            } 
          }
          var level = '',
            color = 'green'
          if (epw < 15) {
            level = '低风险'
            color = 'green'
            icon = "./asset/mipmap/c_level_0.png"
          } else if (epw < 20) {
            level = '中风险'
            color = 'rgb(187, 108, 4)'
            icon = "./asset/mipmap/c_level_1.png"
          } else if (epw >= 20){
            level = '高风险'
            color = 'red'
            icon = "./asset/mipmap/c_level_2.png"
          }
          // labelContent0 += `<div>${period}: ${epw}</div>`
          // labelContent0 += `<div style='color: ${color};'>${level}</div>`
 
          // labelContent1 += `<div style='color: ${color};'>${level}</div>`
          // labelContent1 += `<div>${epw} ${Util.factorUnit2[this.factor]}</div>`
 
          break
        }
      }
    }
 
    var mContent0 = '<div>'
    mContent0 += `<img src="${icon}" style="width: 30px;height: 30px"/>`
    // mContent0 += '<div class="marker-content">'
    // mContent0 += labelContent0
    // mContent0 += '</div>'
    mContent0 += '</div>'
 
    var mContent1 = '<div>'
    mContent1 += `<img src="${icon}" style="width: 30px;height: 30px"/>`
    // mContent1 += '<div class="marker-content">'
    // mContent1 += labelContent1
    // mContent1 += '</div>'
    mContent1 += '</div>'
 
    return [mContent0, mContent1]
  },
 
 
 
 
 
 
 
 
 
  /**
   * 站点标记信息窗体
   */
  createInfoWindow: function (cName, index) {
    var that = this
    var c
    for (let i = 0; i < this.companys.length; i++) {
      const e = this.companys[i];
      if (e.ciName === cName) {
        c = e
        break
      }
    }
    //实例化信息窗体
    var title = '<div>' + c.ciName + '</div>' + '<div class="sub-title">经营地址:' + c.ciAddress + '</div>',
      content = '';
    tag = ''
 
    // 遍历站点数据中的每一项监测因子,生成页面
    // content += "<table class='text-table'>"
 
    if (this.epwResult != undefined) {
      for (const key in this.epwResult) {
        // if (this.epwResult[key][this.factor] === undefined) {
        //   return undefined
        // }
        var cName = key.split(';')[0]
        if (c.ciName === cName) {
          const r = this.epwResult[key]
          var epw = '/', period = "数据无效"
          if (r[this.factor] != undefined) {
            for (const p in r[this.factor]) {
              period = p
              epw = r[this.factor][p]['average']
              break
            } 
          }
          var level = '',
            color = '#26e23f'
          if (epw < 15) {
            level = '低风险'
            color = '#26e23f'
            icon = "./asset/mipmap/c_level_0.png"
          } else if (epw < 20) {
            level = '中风险'
            color = '#e6d436'
            icon = "./asset/mipmap/c_level_1.png"
          } else if (epw >= 20){
            level = '高风险'
            color = 'red'
            icon = "./asset/mipmap/c_level_2.png"
          }
          content += `<div>${period}: ${epw} ${Util.factorUnit2[this.factor]}</div>`
          content += `<div style='color: ${color};'>${level}</div>`
 
          // labelContent1 += `<div style='color: ${color};'>${level}</div>`
          // labelContent1 += `<div>${epw} ${Util.factorUnit2[this.factor]}</div>`
 
 
          break
        }
      }
    }
 
    // content += "</table>"
 
    var info = document.createElement("div");
    // info.className = "custom-info input-card content-window-card";
    info.className = "flexbox-col";
 
    //可以通过下面的方式修改自定义窗体的宽高
    //info.style.width = "400px";
    // 定义顶部标题
    var top = document.createElement("div");
    // top.className = "info-top";
    top.className = "ff-content ff-content-top-left ff-content-small-borderless-t info-top";
    var top_b = document.createElement("div");
    top_b.className = "ff-border-bottom"
    var top_t = document.createElement("div");
    top_t.className = "ff-border-top"
    var top_c = document.createElement("div");
    top_c.className = "ff-border-content flexbox flex-space-between"
 
 
    var titleD = document.createElement("div");
    var closeX = document.createElement("i");
    titleD.innerHTML = title;
    closeX.className = "fa fa-times margin-left-8"
    // $(closeX).attr('aria-hidden', 'true')
    closeX.onclick = function () {
      that.closeInfoWindow(index);
    }
 
    top_c.appendChild(titleD);
    top_c.appendChild(closeX);
 
    top_t.appendChild(top_c)
    top.appendChild(top_b)
    top.appendChild(top_t)
 
    info.appendChild(top);
 
    // 定义中部内容
    var m_top = document.createElement("div");
    m_top.className = "ff-content ff-content-left ff-content-medium";
    var m_top_b = document.createElement("div");
    m_top_b.className = "ff-border-bottom"
    var m_top_t = document.createElement("div");
    m_top_t.className = "ff-border-top"
    var m_top_c = document.createElement("div");
    m_top_c.className = "ff-border-content"
    var m_top_f = document.createElement("div");
    m_top_f.className = "ff-footer flexbox-col flex-center"
    var m_top_tr = document.createElement("div");
    m_top_tr.className = "ff-triangle"
    var m_top_trb = document.createElement("div");
    m_top_trb.className = "ff-triangle-border"
 
    // $(refresh).on('click', site.code, function(event) {
    //   $(this).addClass('loading-pic')
    //   that.fetchingData(event.data, function() {
    //     $(this).removeClass('loading-pic')
    //   })
    // });
 
    var middle = document.createElement("div");
    // middle.className = "info-middle";
    middle.innerHTML = content;
    m_top_f.innerHTML = tag
 
    m_top_c.appendChild(middle);
 
 
    m_top_t.appendChild(m_top_c)
    m_top_tr.appendChild(m_top_trb)
 
    m_top.appendChild(m_top_b)
    m_top.appendChild(m_top_t)
    m_top.appendChild(m_top_f)
    m_top.appendChild(m_top_tr)
 
    info.appendChild(m_top);
 
 
    // 定义底部内容
    var bottom = document.createElement("div");
    bottom.className = "info-bottom";
    bottom.style.position = 'relative';
    bottom.style.top = '0px';
    bottom.style.margin = '0 auto';
    var sharp = document.createElement("img");
    sharp.src = "https://webapi.amap.com/images/sharp.png";
    bottom.appendChild(sharp);
    info.appendChild(bottom);
    return info;
  },
  closeInfoWindow: function (index) {
    this.companyInfoWindow[index].close()
  },
}