From f305077e82b1eb1edc45da2d206e976fdb89f66b Mon Sep 17 00:00:00 2001
From: 徐旺旺 <11530253@qq.com>
Date: 星期二, 30 三月 2021 17:04:55 +0800
Subject: [PATCH] 新的图层控制逻辑
---
src/components/LayerController/logic/WasteGas.js | 46 +++++++++++++++
src/components/LayerController/service/WmsLayerService.js | 6 +-
src/components/LayerController/service/AnimalService.js | 37 ++++++++++++
src/components/LayerController/service/WfsLayerService.js | 14 +++-
src/conf/Constants.js | 3
src/components/LayerController/logic/Sample.js | 4
src/components/LayerController/service/BusiLayerService.js | 13 ++-
src/components/LayerController/service/LayerFactory.js | 27 +++-----
8 files changed, 118 insertions(+), 32 deletions(-)
diff --git a/src/components/LayerController/logic/Sample.js b/src/components/LayerController/logic/Sample.js
index 687b0e7..063123f 100644
--- a/src/components/LayerController/logic/Sample.js
+++ b/src/components/LayerController/logic/Sample.js
@@ -1,9 +1,9 @@
module.exports = function () {
- this.init = (layer) => {
+ this.init = (L) => {
console.log('sample init !!!')
}
- this.clickListener = (list) => {
+ this.clickListener = (e, data) => {
console.log('sample clickListener !!!')
}
}
diff --git a/src/components/LayerController/logic/WasteGas.js b/src/components/LayerController/logic/WasteGas.js
new file mode 100644
index 0000000..2744f36
--- /dev/null
+++ b/src/components/LayerController/logic/WasteGas.js
@@ -0,0 +1,46 @@
+/**
+ * 搴熸皵
+ */
+const AnimalService = require('../service/AnimalService').default
+const AjaxUtils = require('../../../utils/AjaxUtils').default
+
+module.exports = function () {
+ /**
+ * 杩斿洖marker瀵硅薄鏁扮粍
+ * @param L leaflet瀵硅薄
+ */
+ this.init = (layer, L) => {
+ this.animalService = new AnimalService({ L: L, layer: layer })
+ AjaxUtils.get4JsonDataByUrl('http://10.246.162.140:8080/EPInterface/DataService/EPMapService.asmx/ObtainningConInfo', {
+ companyId: 3900100145,
+ id: '',
+ monType: 1,
+ userCode: 'wenchun.deng',
+ monDuration: '',
+ epName: '',
+ secdDeptId: '',
+ contrLevel: '',
+ dataStatus: '',
+ dataFlag: '',
+ runStatus: '',
+ emissTypeId: ''
+ }, function (res) {
+ const data = res.data.Result.DataInfo
+ for (let i = 0; i < data.length; i++) {
+ // 缁忕含搴� 浣嶇疆
+ const positionX = data[i].Latitude
+ const positionY = data[i].Longitude
+ layer.addLayer(L.marker([positionX, positionY], {}))
+ }
+ })
+ }
+
+ this.bindTooltip = (layer) => {
+ return '娴嬭瘯搴熸皵'
+ }
+
+ this.clickListener = (e) => {
+ console.log(e)
+ this.animalService.pulseEffect(e.latlng)
+ }
+}
diff --git a/src/components/LayerController/service/AnimalService.js b/src/components/LayerController/service/AnimalService.js
new file mode 100644
index 0000000..9a80b7f
--- /dev/null
+++ b/src/components/LayerController/service/AnimalService.js
@@ -0,0 +1,37 @@
+/**
+ * 鍔ㄦ�佹晥鏋滃皝瑁�
+ */
+class AnimalService {
+ constructor (config) {
+ this.intervals = [] // 瀹氭椂鍣ㄥ垪琛�
+ this.L = config.L
+ this.layer = config.layer
+ this.times = config.times || 5
+ this.colors = ['#98FB98', '#ff0000']
+ }
+
+ /**
+ * 鑴夊啿鏁堟灉
+ */
+ pulseEffect (xy) {
+ // 鎻掍欢 鏁堟灉瀹炵幇
+ var pulsingIcon = this.L.icon.pulse({
+ iconSize: [20, 20],
+ color: this.colors[0],
+ fillColor: ''
+ })
+ var picGroupMarker = this.L.marker(xy, { icon: pulsingIcon }).addTo(this.layer)
+ var times = this.times
+ // 瀹氭椂
+ var timeInterval = setInterval(() => {
+ if (times > 0) {
+ times--
+ } else {
+ clearInterval(timeInterval)
+ picGroupMarker.remove()
+ }
+ }, 1000)
+ }
+}
+
+export default AnimalService
diff --git a/src/components/LayerController/service/BusiLayerService.js b/src/components/LayerController/service/BusiLayerService.js
index 254a819..d63962e 100644
--- a/src/components/LayerController/service/BusiLayerService.js
+++ b/src/components/LayerController/service/BusiLayerService.js
@@ -13,18 +13,21 @@
init (layer) {
// 寮曞叆 鍏宠仈鐨刯s锛屽湪constant.js涓牴鎹甤onfig閰嶇疆鐨刬d寰楀埌澶勭悊js
const id = this.config.code
- console.log(logicMapper)
const file = logicMapper[id]
if (!file) {
console.log('鎵句笉鍒伴�昏緫澶勭悊js!!!')
} else {
- console.log('-----' + file)
var BusiLayer = require('../logic/' + file)
- console.log(BusiLayer)
var busiLayer = new BusiLayer()
- // 璋冪敤init
- busiLayer.init(layer)
+ busiLayer.init(layer, this.L)
+ if (busiLayer.bindTooltip) {
+ layer.bindTooltip(busiLayer.bindTooltip(layer))
+ }
// 璋冪敤click浜嬩欢
+ if (busiLayer.clickListener) {
+ layer.on('click', busiLayer.clickListener)
+ }
+ layer.addTo(this.map)
}
}
}
diff --git a/src/components/LayerController/service/LayerFactory.js b/src/components/LayerController/service/LayerFactory.js
index 7626125..e7a585c 100644
--- a/src/components/LayerController/service/LayerFactory.js
+++ b/src/components/LayerController/service/LayerFactory.js
@@ -2,15 +2,12 @@
import WfsLayerService from './WfsLayerService'
import BusiLayerService from './BusiLayerService'
import WmsLayerService from './WmsLayerService'
+
class LayerFactory {
constructor (options) {
this.L = options.L
this.map = window.map
this.layers = {}
- }
-
- createLayerGroup () {
- return this.L.layerGroup().addTo(this.map)
}
init () {
@@ -25,28 +22,26 @@
var wfs = childConfig.wfs
var wms = childConfig.wms
var url = childConfig.url
- // 鍒ゆ柇鏄惁宸茬粡鍔犺浇杩囷紝鍔犺浇杩囧氨 蹇界暐鎺�
- const layer = this.layers[code]
+ // 鍒ゆ柇鏄惁宸茬粡鍔犺浇杩囷紝鍔犺浇杩囧氨 鐩存帴寰楀埌瀵硅薄璋冪敤 鏄剧ず鍑芥暟
+ var layer = this.layers[code]
if (!layer) {
- const newLayer = this.createLayerGroup()
- this.layers[code] = newLayer
+ layer = this.L.featureGroup({}).addTo(this.map)
// 2. 鍒ゆ柇绫诲瀷
if (wfs) {
// 3. 瀹炰緥鍖栧叿浣搒ervice
- // var busiLayerService = new BusiLayerService()
- // busiLayerService.init()
var wfsLayerService = new WfsLayerService(childConfig)
- wfsLayerService.init(newLayer)
+ wfsLayerService.init(layer)
}
if (wms) {
var wmsLayerService = new WmsLayerService(childConfig)
- wmsLayerService.init(newLayer)
+ wmsLayerService.init(layer)
}
// 璇锋眰涓氬姟鏁版嵁鎺ュ彛
if (url) {
var busiLayerService = new BusiLayerService(childConfig)
- busiLayerService.init(newLayer)
+ busiLayerService.init(layer)
}
+ layer ? (this.layers[code] = layer) : console.log('LayerFactory锛歯ewLayer is null锛宲lease check !!!')
} else {
this.show(code)
}
@@ -69,9 +64,9 @@
}
/**
- * 璁剧疆index,绾垮湪鏈�涓嬮潰锛岀偣鍦ㄤ笂闈�
- * @param layerGroup 鍥惧眰缁�
- */
+ * 璁剧疆index,绾垮湪鏈�涓嬮潰锛岀偣鍦ㄤ笂闈�
+ * @param layerGroup 鍥惧眰缁�
+ */
setZIndex (layerGroup) {
var layers = layerGroup.getLayers()
if (layers.length > 0) {
diff --git a/src/components/LayerController/service/WfsLayerService.js b/src/components/LayerController/service/WfsLayerService.js
index e5a175d..8d55234 100644
--- a/src/components/LayerController/service/WfsLayerService.js
+++ b/src/components/LayerController/service/WfsLayerService.js
@@ -21,15 +21,20 @@
}
init (layer) {
+ this.layer = layer
const wfsUrl = this.config.wfs
if (wfsUrl) {
- AjaxUtils.get4JsonDataByUrl(wfsUrl, this.params, (res) => this.draw(layer, res.data.features))
+ this.loadData(wfsUrl)
}
}
- draw (layer, features) {
+ loadData (wfsUrl) {
+ AjaxUtils.get4JsonDataByUrl(wfsUrl, this.params, (res) => this.draw(res.data.features))
+ }
+
+ draw (features) {
const icon = this.config.icon
- const geojson = this.L.geoJSON(features, {
+ this.L.geoJSON(features, {
style: function (feature) {
return {
fill: styles.defaultLineStyle.fill,
@@ -66,8 +71,7 @@
.bindTooltip((layer) => this.tooltipListener(layer), { direction: 'bottom', offset: [0, 15], sticky: true })
.on('mouseover', (e) => this.mouseOverListener(e, layer)).on('mouseout', (e) => this.mouseOutListener(e, layer))
}
- }).addTo(layer)
- return geojson
+ }).addTo(this.layer)
}
mouseOverListener (e, layer) {
diff --git a/src/components/LayerController/service/WmsLayerService.js b/src/components/LayerController/service/WmsLayerService.js
index b818aec..859334d 100644
--- a/src/components/LayerController/service/WmsLayerService.js
+++ b/src/components/LayerController/service/WmsLayerService.js
@@ -1,11 +1,11 @@
-class WfsLayerService {
+class WmsLayerService {
constructor (config) {
this.config = config
}
- init () {
+ init (layer) {
}
}
-export default WfsLayerService
+export default WmsLayerService
diff --git a/src/conf/Constants.js b/src/conf/Constants.js
index cef757c..97a3af7 100644
--- a/src/conf/Constants.js
+++ b/src/conf/Constants.js
@@ -7,7 +7,8 @@
export const logicMapper = {
fsqy: 'Sample.js',
fspfk: 'Sample.js',
- fsjcd: 'Sample.js'
+ fsjcd: 'Sample.js',
+ wasteGasJcd: 'WasteGas.js'
}
export const props = {
--
Gitblit v1.8.0