From 071cbd45b47629736a983ed9acb90343430778c3 Mon Sep 17 00:00:00 2001
From: 陈泽平 <chenzeping>
Date: 星期五, 21 五月 2021 09:01:53 +0800
Subject: [PATCH] Merge branch 'develop' of http://xearth.cn:6600/r/wuyushui/SewerAndRainNetwork into develop

---
 /dev/null                                                       |  117 -----------------------
 src/components/LayerController/service/WmsLayerService.js       |   44 ++++++--
 src/components/LayerController/dataset/WmsLayerList.js          |   18 ++-
 src/components/LayerController/modules/LcServiceLayerFilter.vue |   30 ++++-
 src/components/LayerController/service/LayerFactory.js          |   19 +++
 src/components/LayerController/modules/LcServiceLayer.vue       |   35 +++++--
 6 files changed, 112 insertions(+), 151 deletions(-)

diff --git a/src/components/LayerController/dataset/WmsLayerList.js b/src/components/LayerController/dataset/WmsLayerList.js
index fc0e782..3aaeb12 100644
--- a/src/components/LayerController/dataset/WmsLayerList.js
+++ b/src/components/LayerController/dataset/WmsLayerList.js
@@ -1,5 +1,8 @@
 import clone from '../../../utils/utils'
 
+/**
+ * 缁勮wms鍔犺浇鎵�闇�鐨刲ayers浠ュ強filters鍙傛暟
+ */
 class WmsLayerList {
   constructor () {
     // [{鍥惧眰鍚嶇О锛歔{typeName:xxx,filter:yyy}]}]
@@ -10,7 +13,7 @@
     const typeName = config.typeName
     const layerGroup = config.layerGroup || typeName
     const filter = config.filter
-    const index = config.index || 9
+    const index = config.index
     if (layerGroup) {
       this.addLayer(layerGroup, typeName, filter, index)
     }
@@ -18,7 +21,6 @@
 
   addLayer (layerGroup, typeName, filter, index) {
     const layer = this._getLayer(layerGroup)
-
     if (layer) {
       const offset = this.indexOf(typeName, filter)
       if (offset < 0) {
@@ -28,7 +30,11 @@
     } else {
       const layerConfig = {}
       layerConfig[layerGroup] = [{ typeName: typeName, filter: filter || 'INCLUDE' }]
-      this.layers.push(layerConfig)
+      if (index) {
+        this.layers[index] = layerConfig
+      } else {
+        this.layers.push(layerConfig)
+      }
     }
   }
 
@@ -36,7 +42,7 @@
     const layers = this.layers
     for (let i = 0; i < layers.length; i++) {
       const lay = layers[i]
-      if (lay[layer]) {
+      if (lay && lay[layer]) {
         return lay
       }
     }
@@ -112,7 +118,9 @@
           }
         }
       }
-      cqlFilters.push(filters.join(' OR '))
+      if (filters.length > 0) {
+        cqlFilters.push(filters.join(' OR '))
+      }
     }
     return cqlFilters.join(';')
   }
diff --git a/src/components/LayerController/modules/LcServiceLayer.vue b/src/components/LayerController/modules/LcServiceLayer.vue
index 4bd7e82..ef7dc4d 100644
--- a/src/components/LayerController/modules/LcServiceLayer.vue
+++ b/src/components/LayerController/modules/LcServiceLayer.vue
@@ -40,6 +40,11 @@
 export default {
   name: 'LcServiceLayer',
   components: { LcServiceLayerFilter },
+  data () {
+    return {
+      changeList: []
+    }
+  },
   computed: {
     serviceLayers () {
       return this.$store.state.map.serviceLayers.LayerSewersLine
@@ -51,8 +56,18 @@
     swAllLayers (item) {
       // eslint-disable-next-line no-debugger
       item.checked = !item.checked
-      this.toggleLayer(item)
-      this.swLayers(item.layers, item.checked)
+      // this.toggleLayer(item)
+      if (item.layers && item.layers.length > 0) {
+        this.swLayers(item.layers, item.checked)
+        if (item.checked) {
+          window.layerFactory.showAll(this.changeList)
+        } else {
+          window.layerFactory.hideAll(this.changeList)
+        }
+        this.changeList = []
+      } else {
+        this.toggleLayer(item)
+      }
       this.serviceLayers.forEach(function (item1, index1) {
         if (item1.layers) {
           item1.istrue = 0
@@ -99,14 +114,14 @@
       })
       // console.log(this.serviceLayers)
     },
-    swLayers (layers, checked) {
-      if (layers) {
-        for (let i = 0, len = layers.length; i < len; ++i) {
-          var layer = layers[i]
-          layer.checked = checked
-          this.toggleLayer(layer)
-          if (layer.layers) {
-            this.swLayers(layer.layers, checked)
+    swLayers (configs, checked) {
+      if (configs) {
+        for (let i = 0, len = configs.length; i < len; ++i) {
+          var config = configs[i]
+          config.checked = checked
+          this.changeList.push(config)
+          if (config.layers) {
+            this.swLayers(config.layers, checked)
           }
         }
       }
diff --git a/src/components/LayerController/modules/LcServiceLayerFilter.vue b/src/components/LayerController/modules/LcServiceLayerFilter.vue
index 7b06da4..22c701b 100644
--- a/src/components/LayerController/modules/LcServiceLayerFilter.vue
+++ b/src/components/LayerController/modules/LcServiceLayerFilter.vue
@@ -24,6 +24,7 @@
     return {
       visible: {},
       layers: [],
+      changeList: [],
       filterConfig: [] // 闄勫睘瑕佺礌
     }
   },
@@ -40,17 +41,28 @@
       // eslint-disable-next-line no-debugger
       item.checked = !item.checked
       this.toggleLayer(item)
-      this.swLayers(item.layers, item.checked)
+      if (item.layers && item.layers.length > 0) {
+        this.swLayers(item.layers, item.checked)
+        if (item.checked) {
+          window.layerFactory.showAll(this.changeList)
+        } else {
+          window.layerFactory.hideAll(this.changeList)
+        }
+        this.changeList = []
+      } else {
+        this.toggleLayer(item)
+      }
     },
-    swLayers (layers, checked) {
-      if (layers) {
-        for (let i = 0, len = layers.length; i < len; ++i) {
-          var layer = layers[i]
-          layer.checked = checked
-          this.toggleLayer(layer)
-          if (layer.layers) {
-            this.swLayers(layer.layers, checked)
+    swLayers (configs, checked) {
+      if (configs) {
+        for (let i = 0, len = configs.length; i < len; ++i) {
+          const config = configs[i]
+          const layers = config.layers
+          this.changeList.push(config)
+          if (layers) {
+            this.swLayers(config, checked)
           }
+          config.checked = checked
         }
       }
     },
diff --git a/src/components/LayerController/service/LayerFactory.js b/src/components/LayerController/service/LayerFactory.js
index 68d8d64..c586a1c 100644
--- a/src/components/LayerController/service/LayerFactory.js
+++ b/src/components/LayerController/service/LayerFactory.js
@@ -106,6 +106,16 @@
     return layer
   }
 
+  showAll (configs) {
+    if (Array.isArray(configs)) {
+      for (let i = 0; i < configs.length; i++) {
+        const config = configs[i]
+        this.show(config)
+      }
+      this.wmsLayerService && this.wmsLayerService.addAll(configs)
+    }
+  }
+
   /**
    * 濡傛灉 瀛樺湪宸茬粡鍔犺浇浜嗙殑瀵硅薄锛屽氨鐩存帴鍔犲埌map
    * 濡傛灉 涓嶅瓨鍦ㄥ垯 璋冪敤 addLayer 鍙� 閫昏緫绫荤殑init 杩涜鍒濆鍖栨搷浣�
@@ -128,6 +138,15 @@
     this.wmsLayerService && this.wmsLayerService.add(config)
   }
 
+  hideAll (configs) {
+    if (Array.isArray(configs)) {
+      for (let i = 0; i < configs.length; i++) {
+        this.hide(configs[i])
+      }
+      this.wmsLayerService && this.wmsLayerService.removeAll(configs)
+    }
+  }
+
   hide (config) {
     const code = config.code
     const layer = this.layers[code]
diff --git a/src/components/LayerController/service/WmsLayerGroupService.js b/src/components/LayerController/service/WmsLayerGroupService.js
deleted file mode 100644
index 5e2599d..0000000
--- a/src/components/LayerController/service/WmsLayerGroupService.js
+++ /dev/null
@@ -1,117 +0,0 @@
-import AjaxUtils from '../../../utils/AjaxUtils'
-import { PIPELINE_WMS } from '../../../conf/Constants'
-
-/**
- * wms 鍥惧眰缁勭殑绠$悊
- */
-class WmsLayerGroupService {
-  constructor (config) {
-    this.config = config
-    this.L = window.L
-    // 瀛樻斁getfeatureinfo鐨勫浘灞傜粍
-    this.featureGroup = this.L.featureGroup({})
-    this.map = window.map
-    this.popupComp = window.popupComp
-    // {groupName:{url:'.../wms',layers:[]}}
-    this.map.on('click', (e) => this.click(e))
-  }
-
-  load () {
-    for (var k in this.groups) {
-      console.log(k)
-      this.L.tileLayer.wms(PIPELINE_WMS, {
-        format: 'image/png', // 杩斿洖鐨勬暟鎹牸寮�
-        transparent: true,
-        maxZoom: 21,
-        layers: k // todo
-      }).addTo(this.layer).bringToFront()
-    }z
-  }
-
-  init () {
-    this.layer = this.L.featureGroup({}).addTo(this.map)
-    this.initGroup(this.config)
-    this.load()
-  }
-
-  hide (config) {
-    const layerName = config.layerName
-    for (var i = 0; i < this.groups.length; i++) {
-      const group = this.groups[i]
-      for (var k in group) {
-        const v = group[k]
-        const index = v.layers.indexOf(layerName)
-        if (index >= 0) {
-          delete v.layers[index]
-        }
-      }
-    }
-  }
-
-  initGroup (config) {
-    const groupName = this.config.groupName
-    const layers = config.layers
-    layers && this.initGroup(layers)
-    for (var i = 0; i < config.length; i++) {
-      const layerConfig = config[i]
-      const layerName = layerConfig.layerName
-      const group = this.groups[groupName]
-      if (group) {
-        group.layers.push(layerName)
-      } else {
-        this.groups[groupName] = {
-          url: '',
-          layers: [layerName]
-        }
-      }
-    }
-  }
-
-  click (e) {
-    this.featureGroup.clearLayers()
-    var point = this.map.latLngToContainerPoint(e.latlng, this.map.getZoom())
-    var size = this.map.getSize()
-    // const bbox = this.L.latLngBounds(this.L.latLng(e.latlng.lng, e.latlng.lat)).toBBoxString()
-    const params = {
-      VERSION: '1.1.1',
-      SERVICE: 'WMS',
-      REQUEST: 'GetFeatureInfo',
-      // bbox: bbox,
-      FORMAT: 'image/png',
-      INFO_FORMAT: 'application/json',
-      TRANSPARENT: true,
-      LAYERS: 'sewer:pipeline_group',
-      QUERY_LAYERS: 'sewer:pipeline_group', // todo
-      FEATURE_COUNT: 50,
-      SRS: 'EPSG:4326',
-      WIDTH: size.x,
-      HEIGHT: size.y,
-      EXCEPTIONS: 'application/vnd.ogc.se_inimage',
-      X: Math.round(point.x),
-      Y: Math.round(point.y),
-      BBOX: this.map.getBounds().toBBoxString()
-    }
-
-    AjaxUtils.get4JsonDataByUrl(PIPELINE_WMS, params, (res) => {
-      let features = res.data.features
-      features = features[0]
-      var myIcon = this.L.divIcon({ className: 'my-div-icon' })
-      this.L.marker(features.geometry.coordinates.reverse(), {
-        icon: myIcon
-      }).addTo(this.featureGroup)
-        .bindPopup((layer) => {
-          this.popupComp.setDatas({ feature: features })
-          this.popupComp.setShow()
-          return this.popupComp.$el
-        }, {
-          className: 's-map-popup',
-          minWidth: 300,
-          closeButton: false,
-          autoClose: false
-        })
-        .openPopup()
-    })
-  }
-}
-
-export default WmsLayerGroupService
diff --git a/src/components/LayerController/service/WmsLayerService.js b/src/components/LayerController/service/WmsLayerService.js
index b64e539..20f2af7 100644
--- a/src/components/LayerController/service/WmsLayerService.js
+++ b/src/components/LayerController/service/WmsLayerService.js
@@ -40,23 +40,47 @@
   init () {
   }
 
+  addAll (configs) {
+    for (let i = 0; i < configs.length; i++) {
+      const config = configs[i]
+      const layers = config.layers
+      if (layers) {
+        this.addAll(layers)
+      }
+      this.wmsLayerList.addConfig(config)
+    }
+    this.reload()
+  }
+
   add (config) {
     this.wmsLayerList.addConfig(config)
+    this.reload()
+  }
+
+  removeAll (configs) {
+    for (let i = 0; i < configs.length; i++) {
+      const config = configs[i]
+      const layers = config.layers
+      if (layers) {
+        this.removeAll(layers)
+      }
+      this.wmsLayerList.remove(config.typeName, config.filter)
+    }
+    this.reload()
+  }
+
+  remove (config) {
+    this.wmsLayerList.remove(config.typeName, config.filter)
+    this.reload()
+  }
+
+  reload () {
     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)
+    this.wmsLayer.setParams(params, false)
   }
 
   load () {

--
Gitblit v1.8.0