派生自 wuyushui/SewerAndRainNetwork

徐旺旺
2021-04-20 7d02699a0b2d425f3f9f3dd6af872bbc1d352710
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
/**
 * 固废
 */
const WasteSolidIndex = require('@components/BaseNav/WasteSolid/WasteSolidIndex').default
// 区分不同类型 使用不同img
const defaultImg = '/assets/images/map/solidwaste/voc.png'
const setting = '/assets/images/map/solidwaste/gf_green2.png'
 
// 请求接口数据
const mapApi = require('../../../api/mapApi').default
// 使用封装方法
const AnimalService = require('../service/AnimalService').default
 
module.exports = function () {
  /**
   * 返回marker对象数组
   * @param L leaflet对象
   */
  this.init = async (layer, L) => {
    this.animalService = new AnimalService({
      L: L,
      layer: layer
    })
    const result = await mapApi.getSolidWaste()
    const getSolidWasteData = result.Result.DataInfo || {}
    // 循环遍历数据 根据进行marker 的创建
    for (let i = 0; i < getSolidWasteData.length; i++) {
      // 经纬度 位置
      const positionX = getSolidWasteData[i].Latitude
      const positionY = getSolidWasteData[i].Longitude
 
      // 定义类型 用来区分数据的不同 1.接口接口数据来进行数据的判断 2.根据数据类型的不同,进行不同类型的图片显示
      const judgeValue = getSolidWasteData[i].StorageQty
      var iconUrl = this.differentTypes(judgeValue)
 
      const marker = L.marker([positionX, positionY], {
        totransferData: getSolidWasteData[i],
        icon: L.icon({
          iconUrl: iconUrl,
          iconSize: [30, 30],
          iconAnchor: [15, 15]
        })
      })
      layer.addLayer(marker)
    }
  }
 
  this.bindTooltip = (layer) => {
    return layer.options.totransferData.Name
  }
 
  this.clickListener = (e) => {
    // 点击marker的pulse()光波
    this.animalService.pulseEffect(e.latlng)
    /* 点击数据的接口请求 */
    this.requestSolidWasteData(e).then(e)
  }
 
  // 不同类型图片封装
  this.differentTypes = (judgeValue) => {
    var effectOfChange
    if (judgeValue === 1) {
      effectOfChange = defaultImg
    } else {
      effectOfChange = setting
    }
    return effectOfChange
  }
 
  // 根据点击不同数据 进行接口的数据请求
  this.requestSolidWasteData = async (e) => {
    // 弹框标题
    const title = e.layer.options.totransferData.Name
    /* flyTo()弹出框平移事件 */
    this.setPanTo(e.latlng, 300)
    window.$layer.open({
      content: {
        content: WasteSolidIndex, // 组件
        parent: this, // 父组件
        data: { // 传递的参数
          storagePlaceId: e.layer.options.totransferData.StoragePlaceId
        }
      },
      title: title // 标题
    })
  }
 
  // flayTo() 弹框的可滑动事件
  this.setPanTo = (pos, value) => {
    var position = pos
    position = window.map.latLngToLayerPoint(position)
    position.y += value
    position = window.map.layerPointToLatLng(position)
    window.map.flyTo(position)
  }
}