From 9521ae4a43b22846da593abbabfd5d644421e7a4 Mon Sep 17 00:00:00 2001
From: xiebin <123456>
Date: Thu, 25 Aug 2022 09:05:30 +0800
Subject: [PATCH] 农场地块列表点击地块显示白边

---
 src/components/map/index.vue |   65 ++++++++++++++++++++++++--------
 1 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/src/components/map/index.vue b/src/components/map/index.vue
index a4a9654..48d17c6 100644
--- a/src/components/map/index.vue
+++ b/src/components/map/index.vue
@@ -5,7 +5,7 @@
 
 <script>
 // import axios from 'axios'
-import NCregion from "@/assets/region"
+import NCregion from '@/assets/region'
 
 // 图层变量做声明
 var farmRegionLayer = null
@@ -32,7 +32,7 @@
         }
     },
     watch: {
-        'polyline' (newObj,oldObj) {
+        'polyline' (newObj, oldObj) {
             if (newObj && oldObj) {
                 plotRegionLayer.removeOverlay(oldObj)
             }
@@ -328,23 +328,29 @@
             })
 
             polygon.on(global.DC.MouseEventType.CLICK, (e) => {
-
-                // 画线
-                this.polyline = new global.DC.Polyline(positions)
-                this.polyline.setStyle({
-                    width: 4,
-                    material: global.DC.Namespace.Cesium.Color.fromBytes(
-                            200, 255, 255,
-                            200
-                    ),
-                    clampToGround: true
-                })
-                plotRegionLayer.addOverlay(this.polyline)
+                that.drawLandPolyLine(positions)
                 that.$parent.plotDetailsPopupShow(e.overlay.attrParams)
             })
 
             plotRegionLayer.addOverlay(polygon)
             addPlotLayers.push({ center, name: item.landName })
+        },
+        /**
+         * 地块画线
+         * @param positions
+         */
+        drawLandPolyLine (positions) {
+            // 画线
+            this.polyline = new global.DC.Polyline(positions)
+            this.polyline.setStyle({
+                width: 4,
+                material: global.DC.Namespace.Cesium.Color.fromBytes(
+                        200, 255, 255,
+                        200
+                ),
+                clampToGround: true
+            })
+            plotRegionLayer.addOverlay(this.polyline)
         },
 
         /**
@@ -417,6 +423,27 @@
         },
 
         /**
+         * 将数据库保存值转换成Map使用坐标
+         * @param landRange 数据库的值
+         * @returns {*[]} Map使用坐标
+         */
+        setPositionByLandRange (landRange) {
+            if (landRange) {
+                landRange = landRange.replace(/POLYGON\(\(/g, '')
+                landRange = landRange.replace(/\)\)/g, '')
+
+                const arr = landRange.split(',')
+                var brr = []
+                arr.forEach(it => {
+                    brr.push(it.split(' '))
+                })
+
+                return brr
+            }
+            return null
+        },
+
+        /**
          * 设置中心点
          * @param {*} name 对应站点(基地范围)的中心点 --- 对应的名字
          */
@@ -457,13 +484,19 @@
          * @param {*} name 对应站点(地块范围)的中心点 --- 对应的名字
          */
 
-        setPlotCenter (name) {
+        setPlotCenter (landObj) {
+            console.log(landObj,11111111)
             let center
             addPlotLayers.forEach(item => {
-                if (name == item.name) {
+                if (landObj.landName == item.name) {
                     center = item.center
                 }
             })
+            // 根据坐标画线
+            const positions = this.setPositionByLandRange(landObj.landRange)
+            if (positions) {
+                this.drawLandPolyLine(positions)
+            }
 
             global.viewer.camera.flyTo({
                 // Cesium的坐标是以地心为原点,一向指向南美洲,一向指向亚洲,一向指向北极州

--
Gitblit v1.9.3