/** * 污染源 */ // 信息组件 const GovernEquipmentIndex = require('../../base-page/RiskSource/RiskSourceIndex.vue').default // 使用封装方法 const AnimalService = require('../service/AnimalService').default // 请求接口数据 const mapApi = require('../../../api/mapApi').default // 公共方法 panTo() 引用 const { setPanTo } = require('../../../utils/utils') const governGreen = '/assets/images/map/governEquipment/govern_green.png' module.exports = function () { /** * 初始化并加载图层 * @param L leaflet对象 */ this.init = async (layer, L) => { this.animalService = new AnimalService({ L: L, layer: layer }) const data = await mapApi.getGovernEquipment() for (let i = 0; i < data.length; i++) { const postion = [data[i].Latitude, data[i].Longitude] // 坐标 const iconUrl = this.governIconUrl(data[i].status) // 治理设施图标 const marker = L.marker(postion, { totransferData: data[i], icon: L.icon({ iconUrl: iconUrl, iconSize: [30, 30], iconAnchor: [15, 15] }) }) layer.addLayer(marker) } } /** * 提示窗 * @param layer * @returns {string} */ this.bindTooltip = (layer) => { return layer.options.totransferData.governName } /** * 信息弹窗 * @param e */ this.clickListener = (e) => { // 脉冲效果 this.animalService.pulseEffect(e.latlng) // 信息弹窗平移 setPanTo(e.latlng, 200) // 弹框标题 const title = e.layer.options.totransferData.Name window.$layer.open({ content: { comp: GovernEquipmentIndex, // 组件 parent: this, // 父组件 data: { // 传递的参数 riskSourceId: e.layer.options.totransferData.no } }, title: title // 标题 }) } /** * 治理设施图标配置 * @param t * @returns {string} */ this.governIconUrl = (t) => { let iconUrl = null switch (t) { case 1: iconUrl = governGreen break case 2: iconUrl = '' break default: iconUrl = '' break } return iconUrl } }