From 4bf99ece0279cedde3b1f6c888b64265534640c0 Mon Sep 17 00:00:00 2001
From: 徐旺旺 <11530253@qq.com>
Date: 星期日, 07 三月 2021 12:47:02 +0800
Subject: [PATCH] 修改图层控制

---
 src/components/panel/topicSearch/SewersSearch.vue |    4 ++++
 src/components/helpers/ServiceLayerHelper.js      |   18 ++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/components/helpers/ServiceLayerHelper.js b/src/components/helpers/ServiceLayerHelper.js
index 3e22efe..a38ef6c 100644
--- a/src/components/helpers/ServiceLayerHelper.js
+++ b/src/components/helpers/ServiceLayerHelper.js
@@ -25,7 +25,18 @@
   }
 
   getByLayerId (layerId) {
-
+    for (var k in this.layerArray) {
+      var layer = this.layerArray[k]
+      var geojson = layer.toGeoJSON()
+      var features = geojson.features
+      for (var j = 0; j < features.length; j++) {
+        var feature = features[j]
+        if (feature.id === layerId) {
+          return layer
+        }
+      }
+    }
+    return null
   }
 
   initDisplayZoom (layerConfig) {
@@ -129,7 +140,6 @@
   loadGeojson (res, opt) {
     var that = this
     var icon = opt.icon
-    const featureGroup = that.L.featureGroup().addTo(that.map)
     const geojson = that.L.geoJSON(res.features, {
       style: function (feature) {
         return {
@@ -205,14 +215,14 @@
             }
           })
         }
-      }).addTo(featureGroup)
+      }).addTo(that.map)
     store.commit('addSewersDatas', geojson)
     if (Object.prototype.hasOwnProperty.call(res, 'features') && res.features.length > 0 && (res.features[0].geometry.type === 'LineString' || res.features[0].geometry.type === 'MultiLineString')) {
       geojson.bringToBack()
     } else {
       geojson.bringToFront()
     }
-    return featureGroup
+    return geojson
   }
 
   removeLayer (item) {
diff --git a/src/components/panel/topicSearch/SewersSearch.vue b/src/components/panel/topicSearch/SewersSearch.vue
index ba83a11..a3987bf 100644
--- a/src/components/panel/topicSearch/SewersSearch.vue
+++ b/src/components/panel/topicSearch/SewersSearch.vue
@@ -173,6 +173,7 @@
       wfsHelper.addLike(this.form.query.key, this.form.keyword)
       // const _this = this
       AjaxUtils.GetDataAsynByUrl(wfsHelper.getUrl(), {}, (res) => {
+        console.log(res)
         this.list = res.features
       })
     },
@@ -180,6 +181,9 @@
       console.log(val)
       const bound = this.L.geoJSON([val], {}).getBounds()
       console.log(bound)
+      var layer = window.serviceLayerHelper.getByLayerId(val.id)
+      console.log(layer)
+      layer && layer.openPopup()
       this.$store.state.map.map.flyToBounds(bound)
     }
   }

--
Gitblit v1.8.0