/** * 环境风险 */ // const EnvironmentRiskIndex = require('@components/BaseNav/').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: '
' }) }) layer.addLayer(bgMarker) const chartMarker = L.marker([coordinates[1], coordinates[0]], { icon: L.divIcon({ className: '', iconAnchor: [30, 60], iconSize: [70, 70], html: '
' }) }) 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 '
' + '
' + qyjc + '
' + '
一级风险:' + oneLevel + '个
' + '
二级风险:' + twoLevel + '个
' + '
三级风险:' + threeLevel + '个
' + '
' } }, 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) }) */ } }