派生自 wuyushui/SewerAndRainNetwork

陈泽平
2021-05-26 33f8b1658371b0bfab97f7834286d326b2e4fadc
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
/**
 * 环境风险
 */
// const EnvironmentRiskIndex = require('@components/base-page/').default
 
// 请求接口数据
const mapApi = require('../../../api/mapApi').default
// 使用封装方法
const AnimalService = require('../service/AnimalService').default
// 引入echarts基本组件
const echarts = require('echarts/lib/echarts')
 
module.exports = function () {
  /**
   * 返回marker对象数组
   * @param L leaflet对象
   */
  this.init = async (layer, L) => {
    this.animalService = new AnimalService({
      L: L,
      layer: layer
    })
    const result = await mapApi.getRiskEnterprise()
    const features = result.features
    for (var i = 0; i < features.length; i++) {
      const feature = features[i]
      const geometry = feature.geometry
      const properties = feature.properties
      const qyId = properties.QY_ID
      // const qyJc = properties.QY_JC
      const distract = properties.DISTRACT
      const coordinates = geometry.coordinates
      if (distract !== '长江沿线') {
        continue
      }
      const bgMarker = L.marker([coordinates[1], coordinates[0]], {
        icon: L.divIcon({
          className: '',
          iconAnchor: [15, 45],
          iconSize: [40, 40],
          html: '<div style="width: 40px; height: 40px; background-color: rgba(255,255,255,1); position: relative; border-radius: 50%;"></div>'
        })
      })
      layer.addLayer(bgMarker)
      const chartMarker = L.marker([coordinates[1], coordinates[0]], {
        icon: L.divIcon({
          className: '',
          iconAnchor: [30, 60],
          iconSize: [70, 70],
          html: '<div id="qy_id_' + qyId + '" style="width: 70px; height: 70px; background-color: transparent; position: relative; border-radius: 50%;"></div>'
        })
      })
      layer.addLayer(chartMarker)
      chartRender(properties)
    }
  }
 
  /**
   * tips
   * @param layer
   * @returns {string}
   */
  this.bindTooltip = (layer) => {
 
  }
 
  /**
   * 点击弹窗
   * @param e
   */
  this.clickListener = (e) => {
 
  }
 
  /**
   * 环形饼图
   * @param properties
   */
  function chartRender (properties) {
    const qyId = properties.QY_ID
    const qyjc = properties.QY_JC
    // const qyQc = properties.QY_QC
    const num = properties.QY_NUM
    const oneLevel = properties.QY_ONELEVEL
    const twoLevel = properties.QY_TWOLEVEL
    const threeLevel = properties.QY_THREELEVEL
    const o = echarts.init(document.getElementById('qy_id_' + qyId))
    const option = {
      tooltip: {
        trigger: 'item',
        formatter: function (e) {
          return '<div style="background-color: #0c5460; padding: 5px;">' +
              '<div style="color: #63EEF5; font-size: 18px; font-weight: 500; text-align: center">' + qyjc + '</div>' +
              '<div>一级风险:<span style="color: red">' + oneLevel + '个</span></div>' +
              '<div>二级风险:<span style="color: yellow">' + twoLevel + '个</span></div>' +
              '<div>三级风险:<span style="color: lawngreen">' + threeLevel + '个</span></div>' +
              '</div>'
        }
      },
      color: ['red', 'yellow', 'lawngreen'], // 设置饼图各块颜色
      graphic: [ // 为环形图中间添加文字
        {
          type: 'text',
          left: 'center',
          top: '43%', // 设置环形文字的top位置
          style: {
            text: num,
            textAlign: 'center',
            fill: '#000',
            fontSize: 12
          }
        }],
      series: [{
        name: qyjc,
        type: 'pie',
        radius: ['35%', '65%'],
        label: {
          normal: {
            show: false,
            position: 'center',
            formatter: function (t) {
              return num
            },
            textStyle: {
              fontSize: 12,
              color: '#000000'
            }
          }
        },
        data: [{
          value: oneLevel,
          name: '一级风险'
        }, {
          value: twoLevel,
          name: '二级风险'
        }, {
          value: threeLevel,
          name: '三级风险'
        }]
      }]
    }
    o.setOption(option)
    /* o.on('click', function (params) {
        map.flyTo(L.latLng([params.data.y, params.data.x]), 15)
    }) */
  }
}