New file |
| | |
| | | import { FlueGas } from '@/api/request' |
| | | import defaultImg from '@components/flueGas/green_airquality_2.png' |
| | | import Setting from '@components/flueGas/green_airquality_3.png' |
| | | // 图片 |
| | | |
| | | class AddGasHelper { |
| | | constructor (options) { |
| | | this.map = options.map |
| | | this.L = window.L |
| | | this.FlueGasLayerGroup = this.L.layerGroup().addTo(this.map) |
| | | this.FlueGasPopup = null |
| | | this.L.sgis = this.L.sgis || this.L |
| | | this.FlueGasMarkersLabels = [] |
| | | this.pulseHeighLightMarker = null |
| | | } |
| | | |
| | | // 获取数据 |
| | | requestData (data) { |
| | | FlueGas(data).then(res => { |
| | | console.log(res) |
| | | this.DrawFlueGasContent(res.Result.DataInfo) |
| | | }).catch(err => { |
| | | console.log(err) |
| | | }) |
| | | } |
| | | |
| | | // 根据获取数据 画出 内容 |
| | | DrawFlueGasContent (data) { |
| | | // 图标样式扩展 |
| | | var FlueGasIcon = this.PlueGasIcon() |
| | | |
| | | // //加载数据前如果存在图层组 那么清除掉 |
| | | if (this.FlueGasLayerGroup) { |
| | | this.FlueGasLayerGroup.clearLayers() |
| | | } |
| | | for (let i = 0; i < data.length; i++) { |
| | | // 经纬度 位置 |
| | | const positionX = data[i].Latitude |
| | | const positionY = data[i].Longitude |
| | | |
| | | // 判断 经纬度位置信息是否存在 |
| | | // if (positionX != null && positionY != null) { |
| | | // 用于 判断 => 判断是否展示脉冲效果 => temp(临时) |
| | | const determineValueOne = data[i].LongDayWarning |
| | | var determineValueTwo = data[i].StorageQty |
| | | const positionArea = [positionX, positionY] |
| | | |
| | | // 图标展示 |
| | | var iconUrl = this.PlueGasIconUrl(determineValueOne, determineValueTwo, positionArea) |
| | | var Icon = new FlueGasIcon({ iconUrl: iconUrl }) |
| | | // var url = Icon.options.iconUrl |
| | | |
| | | const marker = this.L.marker([positionX, positionY], { icon: Icon }) |
| | | // const latlngs = positionArea[2] |
| | | // // 线 |
| | | // var polyline = this.L.polyline(latlngs, { color: 'red' }).addTo(this.map) |
| | | // console.log(polyline) |
| | | marker.bindPopup(() => { |
| | | return this.FlueGasPopup.$el |
| | | }, { |
| | | className: 's-map-popup', |
| | | minWidth: 1548, |
| | | closeButton: true, |
| | | autoClose: false |
| | | }) |
| | | // 划过出现 展示数据 |
| | | marker.bindTooltip(data[i].porltName, { |
| | | permanent: true, |
| | | offset: [0, -16], |
| | | direction: 'top', |
| | | className: '' |
| | | }) |
| | | // 点击 事件 |
| | | marker.on('click', (e) => { |
| | | try { |
| | | // console.log(e) |
| | | this.EffectOfPulse(e.target.getLatLng()) |
| | | this.FlueGasPopup.setDate(data[i]) |
| | | } catch (error) { |
| | | console.log(error) |
| | | } |
| | | }) |
| | | // 设置内容添加到图层 |
| | | this.FlueGasLayerGroup.addLayer(marker) |
| | | // } |
| | | } |
| | | } |
| | | |
| | | // 点击进行的 内容的设置 |
| | | SetPlueGasContent (config, containerPopup) { |
| | | this.FlueGasPopup = containerPopup |
| | | } |
| | | |
| | | // 图标样式扩展 => 光圈 图标脉冲 |
| | | PlueGasIcon () { |
| | | return this.L.Icon.extend({ |
| | | options: { |
| | | iconSize: [50, 50], |
| | | iconAnchor: [25, 25] |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // 根据类型返回图片加载url |
| | | PlueGasIconUrl (determineValueOne, determineValueTwo, position) { |
| | | var EffectOfChange |
| | | if (determineValueOne === 1 || determineValueTwo === 1) { |
| | | EffectOfChange = defaultImg |
| | | this.EffectOfPulse(position, this.FlueGasMarkersLabels, this.pulseHeighLightMarker) |
| | | } else { |
| | | EffectOfChange = Setting |
| | | } |
| | | return EffectOfChange |
| | | } |
| | | |
| | | // 脉冲效果设置实现 |
| | | EffectOfPulse (position, markers, layerGroup) { |
| | | // // 区分直接执行 和判断执行的不同区别 |
| | | let differentColor = '' |
| | | if (markers) { |
| | | differentColor = '#ff0000' |
| | | } else { |
| | | differentColor = '#98FB98' |
| | | } |
| | | // 坐标数据:报警传进来的是数组 / 点击传进来的是object |
| | | var FinalPosition = position instanceof Array ? { |
| | | lat: position[0], |
| | | lng: position[1] |
| | | } : position |
| | | // 插件 效果实现 |
| | | var pulsingIcon = this.L.icon.pulse({ |
| | | iconSize: [20, 20], |
| | | color: differentColor, |
| | | fillColor: '' |
| | | }) |
| | | if (markers) { |
| | | // markers.push(this.L.marker(FinalPosition, { icon: pulsingIcon })) |
| | | // this.L.layerGroup(markers).addLayer(layerGroup) |
| | | } else { |
| | | var picGroupMarker = new this.L.FeatureGroup() |
| | | this.L.marker(FinalPosition, { icon: pulsingIcon }).addTo(picGroupMarker) |
| | | this.pulseHeighLightMarker = picGroupMarker.addTo(this.FlueGasLayerGroup) |
| | | this.PulseCountSetting() |
| | | } |
| | | } |
| | | |
| | | PulseCountSetting () { |
| | | var HeightLightTime = 5 |
| | | var PulseNumber = 5 |
| | | const pulseinterver = setInterval(() => { |
| | | if (PulseNumber > 0) { |
| | | PulseNumber-- |
| | | } else { |
| | | this.pulseClear(pulseinterver) |
| | | PulseNumber = HeightLightTime |
| | | } |
| | | }, 1000) |
| | | } |
| | | |
| | | // 清除 图层 |
| | | pulseClear (pulseinterver) { |
| | | clearInterval(pulseinterver) |
| | | pulseinterver = null |
| | | |
| | | if (this.PlueGasLayerGroup) { |
| | | // this.PlueGasLayerGroup.clearLayers() |
| | | } else { |
| | | this.PlueGasLayerGroup = this.L.layerGroup().addTo(this.map) |
| | | } |
| | | if ((this.pulseHeighLightMarker)) { |
| | | this.pulseHeighLightMarker.remove() |
| | | } |
| | | } |
| | | } |
| | | |
| | | export default AddGasHelper |