派生自 wuyushui/SewerAndRainNetwork

chenyabin
2021-03-31 97e8d550c9867f7a92c56060835db2969e6fca2e
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
/**
 * 废气
 */
const AnimalService = require('../service/AnimalService').default
// const AjaxUtils = require('../../../utils/AjaxUtils').default
 
// 区分不同类型 使用不同img
const ImgBlue = '/assets/images/map/exhaust/fq_blue.png'
const ImgGray = '/assets/images/map/exhaust/fq_gray.png'
const ImagGreen = '/assets/images/map/exhaust/fq_green.png'
const ImagBright = '/assets/images/map/exhaust/fq_bright_green.png'
 
const mapApi = require('../../../api/mapApi').default
module.exports = function () {
  /**
   * 返回marker对象数组
   * @param L leaflet对象
   */
  this.init = async (layer, L) => {
    this.animalService = new AnimalService({ L: L, layer: layer })
    const res = await mapApi.GetWasteGas()
    const data = res.Result.DataInfo || {}
    console.log(data)
    for (let i = 0; i < data.length; i++) {
      // 经纬度 位置
      const positionX = data[i].Latitude
      const positionY = data[i].Longitude
      // 定义类型 用来区分数据
      const ContrLevel = data[i].ContrLevel
      var iconUrl = this.differentTypes(ContrLevel)
 
      const marker = L.marker.magic([positionX, positionY], {
        icon: L.icon({
          iconUrl: iconUrl,
          iconSize: [50, 50],
          iconAnchor: [25, 25]
        })
      })
      layer.addLayer(marker)
      // layer.addLayer(L.marker([positionX, positionY], {}))
    }
  }
 
  this.bindTooltip = (layer) => {
    console.log(layer)
    return '测试废气'
  }
 
  this.clickListener = (e) => {
    console.log(e)
    this.animalService.pulseEffect(e.latlng)
  }
  // 不同类型图片封装
  this.differentTypes = (ContrLevel) => {
    var effectOfChange
    if (ContrLevel === 1) {
      effectOfChange = ImgBlue
    } else if (ContrLevel === 2) {
      effectOfChange = ImagGreen
    } else if (ContrLevel === 3) {
      effectOfChange = ImagBright
    } else {
      effectOfChange = ImgGray
    }
    return effectOfChange
  }
}