派生自 wuyushui/SewerAndRainNetwork

zhangshuaibao
2021-04-07 4378ba833ffd5262c78a8c6c8b92d8c1c744d379
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
/**
 * 废水
 */
const AnimalService = require('../service/AnimalService').default
const mapApi = require('../../../api/mapApi').default
// 弹窗数据引进
const publicBounced = require('../../BaseNav/PublicBounced/PublicBounced').default
 
const NormalImg = '/assets/images/map/wastewater/fs_green.png' // 正常
const OffImg = '/assets/images/map/wastewater/fs_gray.png' // 停运
const AbnormalImg = '/assets/images/map/wastewater/fs_blue.png' // 异常
const MissImg = '/assets/images/map/wastewater/fs_yellow.png' // 缺失
const AlarmImg = '/assets/images/map/wastewater/fs_red.png' // 报警闪烁
const WarnImg = '/assets/images/map/wastewater/fs_orange.png' // 预警闪烁
 
module.exports = function () {
  /**
   * 返回marker对象数组
   * @param L leaflet对象
   */
  this.init = async (layer, L) => {
    this.animalService = new AnimalService({
      L: L,
      layer: layer
    })
    const res = await mapApi.getWasteWater()
    const data = res.Result.DataInfo || {}
    for (let i = 0; i < data.length; i++) {
      // 经纬度 位置
      const positionX = data[i].Latitude
      const positionY = data[i].Longitude
 
      // 定义类型 用来区分数据的不同
      const testValue = data[i].ContrLevel
      const iconUrl = this.differentTypes(testValue)
      const marker = L.marker.magic([positionX, positionY], {
        test: data[i],
        icon: L.icon({
          iconUrl: iconUrl,
          iconSize: [50, 50],
          iconAnchor: [25, 25]
        })
      })
      layer.addLayer(marker)
    }
  }
 
  this.bindTooltip = (layer) => {
    return layer.options.test.Name
  }
 
  this.clickListener = async (e) => {
    // console.log(e)
    this.animalService.pulseEffect(e.latlng)
    const dataValue = {
      StoragePlaceId: e.layer.options.test.StoragePlaceId
    }
    const drawback = await mapApi.getWasteWaterMonitoring()
    console.log(drawback)
    const result = await mapApi.getWasteWaterMonitoringDetails(dataValue)
    const PublicBounced = window.Vue.extend(publicBounced)
    const instance = new PublicBounced()
    instance.setWaterData(e.layer.options.test, result.Result.DataInfo, drawback.Result.DataInfo, 'feishui')
    console.log(e.layer.options.test)
    instance.$mount()
    document.body.appendChild(instance.$el)
    this.setPanTo(e.latlng, 240)
  }
 
  // 根据返回值的不同标记不同图片
  this.differentTypes = (testValue) => {
    let testChange
    switch (testValue) {
      case 1:
        testChange = NormalImg
        break
      case 2:
        testChange = OffImg
        break
      case 3:
        testChange = AbnormalImg
        break
      case 4:
        testChange = MissImg
        break
      case 5:
        testChange = NormalImg
        break
      case 6:
        testChange = AlarmImg
        break
      case 7:
        testChange = AbnormalImg
        break
      case 8:
        testChange = WarnImg
        break
    }
    return testChange
  }
  this.setPanTo = (pos, value) => {
    var position = pos
    position = window.map.latLngToLayerPoint(position)
    position.y += value
    position = window.map.layerPointToLatLng(position)
    window.map.flyTo(position)
  }
}