From 32c49e86a7876f9252b0a88a0685c203830476f1 Mon Sep 17 00:00:00 2001
From: 陈泽平 <chenzeping>
Date: 星期五, 28 五月 2021 16:40:23 +0800
Subject: [PATCH] 企业应急-事件上报-搜索定位

---
 src/components/helpers/LocateHelper.js |  172 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 132 insertions(+), 40 deletions(-)

diff --git a/src/components/helpers/LocateHelper.js b/src/components/helpers/LocateHelper.js
index 4160b89..9e346c1 100644
--- a/src/components/helpers/LocateHelper.js
+++ b/src/components/helpers/LocateHelper.js
@@ -1,6 +1,43 @@
-import { pulseEffect, reversePolyLine } from '../../utils/utils'
+import { pulseEffect } 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.icon)
+  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 ')
+  }
+  console.log(centerPoint)
+  loadPointWfs(centerPoint, params)
+}
+
+/**
+ * 鍔犺浇鐐硅寖鍥寸殑wfs鏁版嵁骞跺脊绐�
+ * @param latlng  鐐圭殑缁忕含搴﹀潗鏍�
+ * @param params
+ */
+export const loadPointWfs = function (latlng, params) {
+  setTimeout(() => {
+    window.mapManager.loadWfsDatas(latlng, params).then((res) => {
+      openPropsPopup(latlng, res.features)
+    })
+  }, 1000)
+}
 /**
  * 鏍规嵁浼犵殑 feature瀵硅薄瀹氫綅锛�
  * @param code
@@ -8,58 +45,67 @@
  */
 export const fitBounds = function (feature) {
   const type = feature.geometry.type
-  switch (type) {
-    case 'Point':
-      var point = feature.geometry.coordinates
-      point = [point[1], point[0]]
-      window.map.setView(point, 17)
-      break
-    case 'MultiLineString':
-      window.map.fitBounds(window.L.geoJSON(feature).getBounds())
-      break
-    case 'LineString':
-      window.map.fitBounds(window.L.polyline(reversePolyLine(feature)).getBounds())
-      break
+  if (type === 'Point') {
+    var point = feature.geometry.coordinates
+    point = [point[1], point[0]]
+    window.map.setView(point, 19)
+  } else {
+    window.map.fitBounds(window.L.geoJSON(feature).getBounds())
   }
 }
 
-export const highlight = function (feature, config) {
+export const highlight = function (feature, icon) {
+  /* if (Array.isArray(feature)) {
+    for (let i = 0; i < feature.length; i++) {
+      highlight(feature[i], icon)
+    }
+  } else { */
+  window.mapManager.clearHighlight()
   const L = window.L
   const type = feature.geometry.type
-  window.mapManager.clearHighlight()
   const highlightLayer = window.mapManager.hightlightLayer
-  if (type === 'MultiLineString') {
+  if (type === 'Point') {
+    // 鍙犲姞涓�涓ぇ灏哄鐨勫浘鏍�
+    let point = feature.geometry.coordinates
+    point = [point[1], point[0]]
+    pointZoom(point, icon)
+    pulseEffect(point)
+  } else {
     L.geoJSON(feature, {
       style: function () {
         return {
-          fillColor: 'red',
           color: 'red'
         }
       }
     }).addTo(highlightLayer)
-  } else if (type === 'Point') {
-    // 鍙犲姞涓�涓ぇ灏哄鐨勫浘鏍�
-    let point = feature.geometry.coordinates
-    point = [point[1], point[0]]
-
-    if (config) {
-      L.marker(point, {
-        icon: L.icon({
-          iconUrl: '/assets/images/map/' + config.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 latlng  缁忕含搴�
+ * @param icon    鍥炬爣
+ */
+export const pointZoom = function (latlng, icon) {
+  const L = window.L
+  const highlightLayer = window.mapManager.hightlightLayer
+  if (icon) {
+    L.marker(latlng, {
+      icon: L.icon({
+        iconUrl: '/assets/images/map/' + icon,
+        iconSize: [30, 30],
+        iconAnchor: [15, 15]
+      })
+    }).addTo(highlightLayer)
+  }
+}
+
+/**
+ * 寮瑰嚭灞炴�у垪琛ㄥ睍绀虹獥鍙�
+ * @param xy      寮瑰嚭绐楀彛璺熼殢瑕佺礌鐨勭粡绾害
+ * @param layer   鏌ヨ鎸囧畾鐨勫浘灞傘�備笉鎸囧畾鏃讹紝榛樿涓哄嬀閫夌殑鍥惧眰
+ */
+export const openPropsPopup = function (xy, features) {
   const lt = window.map.latLngToContainerPoint(xy)
   const datas = popupDatas(features)
   if (datas.length > 0) {
@@ -77,8 +123,24 @@
   }
 }
 
+export const getCenterPoint = function (feature) {
+  const L = window.L
+  const type = feature.geometry.type
+  var coordinates = feature.geometry.coordinates
+
+  if (type === 'Point') {
+    return [coordinates[1], coordinates[0]]
+  } else {
+    return L.geoJSON(feature, {}).getBounds().getSouthWest()
+    // return [center.lat, center.lng]
+
+    // return turf.centerOfMass(L.geoJSON(feature, {}).toGeoJSON())
+  }
+}
+
 const popupDatas = function (features) {
   const datas = []
+  console.log(features)
   if (features) {
     for (var i = 0; i < features.length; i++) {
       const feature = features[i]
@@ -88,22 +150,52 @@
 
       const propValues = LAYERPROPS[ids[0]]
       const contents = {}
+      if (!propValues) {
+        continue
+      }
+      if (id.indexOf('pipesegment') >= 0) {
+        continue
+      }
       for (const k in properties) {
         if (propValues[k]) {
           contents[propValues[k]] = properties[k]
         }
       }
-      datas.push({
+      const data = {
         title: LAYERS[ids[0]],
         name: feature.id,
-        content: contents
-      })
+        content: contents,
+        feature: feature
+      }
+      if (id.indexOf('pipeline') >= 0) {
+        data.tableList = listPipeSection(features, properties.subchacode || properties.pipecode)
+      }
+      datas.push(data)
       console.log(properties)
     }
   }
   return datas
 }
 
+// 绠$嚎淇℃伅缁戝畾鎵�灞炵娈�
+export const listPipeSection = function (features, code) {
+  const list = []
+  if (features) {
+    for (var i = 0; i < features.length; i++) {
+      const feature = features[i]
+      const id = feature.id
+      if (id.indexOf('pipesegment') < 0) {
+        continue
+      }
+      const properties = feature.properties
+      if (properties.pipecode === code) {
+        list[list.length] = properties
+      }
+    }
+  }
+  return list
+}
+
 export const getLayer = function (layerId, id) {
   const layer = this.layers[layerId]
 

--
Gitblit v1.8.0