From 755baaf11dd4e5c8eb7a5c2aa0ea23732fe47c85 Mon Sep 17 00:00:00 2001
From: 徐旺旺 <11530253@qq.com>
Date: 星期二, 18 五月 2021 15:16:53 +0800
Subject: [PATCH] 弹窗信息补全

---
 src/components/helpers/LocateHelper.js |   71 ++++++++++++++++++++++++++++++++---
 1 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/src/components/helpers/LocateHelper.js b/src/components/helpers/LocateHelper.js
index 4160b89..2454138 100644
--- a/src/components/helpers/LocateHelper.js
+++ b/src/components/helpers/LocateHelper.js
@@ -1,6 +1,33 @@
 import { pulseEffect, reversePolyLine } from '../../utils/utils'
 import Popup from '@views/popup/Popup'
 import { LAYERPROPS, LAYERS } from '../../conf/Constants'
+
+/**
+ * 鏁村悎瀹氫綅銆侀珮浜�佸脊绐�
+ * @param feature  geojson
+ * @param config   鍥惧眰鐨刢onfig
+ */
+export const locate = function (feature, config, filter) {
+  fitBounds(feature)
+  highlight(feature, config)
+  setTimeout(() => {
+    const centerPoint = getCenterPoint(feature)
+    const params = { LAYERS: config.layerGroup || config.typeName, QUERY_LAYERS: config.layerGroup || config.typeName }
+    const filters = []
+    if (config.filter) {
+      filters[filters.length] = config.filter
+    }
+    if (filter) {
+      filters[filters.length] = filter
+    }
+    if (filters.length > 0) {
+      params.CQL_FILTER = filters.join(' AND ')
+    }
+    window.mapManager.loadWfsDatas(centerPoint, params).then((res) => {
+      openPropsPopup(centerPoint, res.features)
+    })
+  }, 1000)
+}
 /**
  * 鏍规嵁浼犵殑 feature瀵硅薄瀹氫綅锛�
  * @param code
@@ -23,7 +50,7 @@
   }
 }
 
-export const highlight = function (feature, config) {
+export const highlight = function (feature, icon) {
   const L = window.L
   const type = feature.geometry.type
   window.mapManager.clearHighlight()
@@ -42,26 +69,30 @@
     let point = feature.geometry.coordinates
     point = [point[1], point[0]]
 
-    if (config) {
+    if (icon) {
       L.marker(point, {
         icon: L.icon({
-          iconUrl: '/assets/images/map/' + config.icon,
+          iconUrl: '/assets/images/map/' + icon,
           iconSize: [30, 30],
           iconAnchor: [15, 15]
         })
       }).addTo(highlightLayer)
     }
     pulseEffect(point)
-    const features = window.mapManager.loadWfsDatas(point)
-    openPopup(point, features)
   } else if (type === 'LineString') {
     L.polyline(reversePolyLine(feature), { color: 'red' }).addTo(highlightLayer)
   }
 }
 
-export const openPopup = function (xy, features) {
+/**
+ * 寮瑰嚭灞炴�у垪琛ㄥ睍绀虹獥鍙�
+ * @param xy      寮瑰嚭绐楀彛璺熼殢瑕佺礌鐨勭粡绾害
+ * @param layer   鏌ヨ鎸囧畾鐨勫浘灞傘�備笉鎸囧畾鏃讹紝榛樿涓哄嬀閫夌殑鍥惧眰
+ */
+export const openPropsPopup = function (xy, features) {
   const lt = window.map.latLngToContainerPoint(xy)
   const datas = popupDatas(features)
+  console.log(datas)
   if (datas.length > 0) {
     window.$layer.open({
       content: {
@@ -77,6 +108,31 @@
   }
 }
 
+export const getCenterPoint = function (feature) {
+  const type = feature.geometry.type
+  var point = []
+  switch (type) {
+    case 'Point':
+      point = feature.geometry.coordinates
+      break
+    case 'MultiLineString':
+      var coordinates = feature.geometry.coordinates
+      var coordinate = coordinates[parseInt(coordinates.length / 2)][0]
+      if (coordinate.length > 2) {
+        point = [coordinate[0], coordinate[1]]
+      }
+      break
+    case 'LineString':
+      var lineString = feature.geometry.coordinates
+      point = lineString[parseInt(lineString.length / 2)][0]
+      break
+  }
+  if (point.length > 2) {
+    point.splice(2, 1)
+  }
+  return point.reverse()
+}
+
 const popupDatas = function (features) {
   const datas = []
   if (features) {
@@ -88,6 +144,9 @@
 
       const propValues = LAYERPROPS[ids[0]]
       const contents = {}
+      if (!propValues) {
+        continue
+      }
       for (const k in properties) {
         if (propValues[k]) {
           contents[propValues[k]] = properties[k]

--
Gitblit v1.8.0