From b4fa7ad9c8e0051e9851c3bfbe398d5ff4cbfafe Mon Sep 17 00:00:00 2001
From: 陈泽平 <chenzeping>
Date: 星期三, 19 五月 2021 16:05:39 +0800
Subject: [PATCH] Merge branch 'develop' of http://xearth.cn:6600/r/wuyushui/SewerAndRainNetwork into develop

---
 src/components/LayerController/service/WmsLayerService.js |   76 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/src/components/LayerController/service/WmsLayerService.js b/src/components/LayerController/service/WmsLayerService.js
index 859334d..b64e539 100644
--- a/src/components/LayerController/service/WmsLayerService.js
+++ b/src/components/LayerController/service/WmsLayerService.js
@@ -1,10 +1,80 @@
+import { WMS_URL } from '../../../conf/Constants'
+import WmsLayerList from '../dataset/WmsLayerList'
+
+/**
+ * todo 寰楄�冭檻涓�涓浘灞傞厤缃簡澶氫釜 wmsLayers鐨勬儏鍐�
+ */
 class WmsLayerService {
-  constructor (config) {
-    this.config = config
+  constructor (layersConfig) {
+    this.L = window.L
+    this.map = window.map
+    this.popupComp = window.popupComp
+    // wms getfeatureinfo 榛樿鍙傛暟
+    this.params = {
+      VERSION: '1.1.1',
+      SERVICE: 'WMS',
+      REQUEST: 'GetFeatureInfo',
+      // bbox: bbox,
+      FORMAT: 'image/png',
+      INFO_FORMAT: 'application/json',
+      TRANSPARENT: true,
+      FEATURE_COUNT: 50,
+      maxZoom: 21,
+      SRS: 'EPSG:4326',
+      EXCEPTIONS: 'application/vnd.ogc.se_inimage'
+    }
+    this.layersConfig = layersConfig
+    // 瀛樻斁getfeatureinfo鐨勫浘灞傜粍
+    this.featureGroup = this.L.featureGroup({}).addTo(this.map)
+
+    this.wmsLayerList = new WmsLayerList()
+    if (layersConfig) {
+      for (var i = 0; i < layersConfig.length; i++) {
+        const config = layersConfig[i]
+        this.wmsLayerList.addConfig(config)
+      }
+    }
+    this.load()
   }
 
-  init (layer) {
+  init () {
+  }
 
+  add (config) {
+    this.wmsLayerList.addConfig(config)
+    const layers = this.wmsLayerList.getLayers() || ''
+    const filter = this.wmsLayerList.getFilters() || ''
+    const params = {}
+    params.cql_filter = filter
+    params.layers = layers
+    this.wmsLayer.setParams(params)
+  }
+
+  remove (config) {
+    this.wmsLayerList.remove(config.typeName, config.filter)
+    const layers = this.wmsLayerList.getLayers() || ''
+    const filter = this.wmsLayerList.getFilters() || ''
+    const params = { layers: layers }
+    params.cql_filter = filter
+    this.wmsLayer.setParams(params)
+  }
+
+  load () {
+    const layers = this.wmsLayerList.getLayers()
+    const filter = this.wmsLayerList.getFilters()
+    const params = {
+      format: 'image/png', // 杩斿洖鐨勬暟鎹牸寮�
+      transparent: true,
+      maxZoom: 21,
+      BBOX: this.map.getBounds().toBBoxString()
+    }
+    if (layers) {
+      params.layers = layers
+    }
+    if (filter.length > 0) {
+      params.cql_filter = filter
+    }
+    this.wmsLayer = this.L.tileLayer.wms(WMS_URL, params).addTo(this.map)
   }
 }
 

--
Gitblit v1.8.0