From 42f42dc88214f283b43c422f37e10ab45c5c5578 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 12 三月 2025 17:32:13 +0800
Subject: [PATCH] 1. 新增绘图模式的切换 2. 新增行政区划的切换展示

---
 src/utils/map/toolbox.js |   70 ++++++++++++++++++++++++++++++++++
 1 files changed, 69 insertions(+), 1 deletions(-)

diff --git a/src/utils/map/toolbox.js b/src/utils/map/toolbox.js
index 23c10c5..3c24609 100644
--- a/src/utils/map/toolbox.js
+++ b/src/utils/map/toolbox.js
@@ -1,9 +1,19 @@
 /* eslint-disable no-undef */
-import { map, satellite } from './index_old';
+import { watch } from 'vue';
+import { map, satellite, onMapMounted } from './index_old';
 import { useToolboxStore } from '@/stores/toolbox';
 import { DialogUtil } from '@/utils/map/dialog';
 
 const toolboxStore = useToolboxStore();
+watch(
+  () => toolboxStore.selectedDistrict,
+  (nV, oV) => {
+    if (nV != oV && toolboxStore.districtStatus) {
+      if (activeDistrict) map.remove(activeDistrict);
+      drawDistrict(toolboxStore.selectedDistrict);
+    }
+  }
+);
 
 /**
  * 鍧愭爣鎷惧彇榧犳爣鐐瑰嚮鍥炶皟浜嬩欢
@@ -38,8 +48,66 @@
   }
 }
 
+let districtPolygonMap = new Map();
+let activeDistrict = undefined;
+// 缁樺埗鍖哄幙杈圭晫
+function drawDistrict(districtName, isNew) {
+  onMapMounted(() => {
+    if (!isNew && districtPolygonMap.has(districtName)) {
+      const districtPolygon = districtPolygonMap.get(districtName);
+      map.remove(districtPolygon);
+      map.add(districtPolygon);
+      activeDistrict = districtPolygon;
+    } else {
+      // eslint-disable-next-line no-undef
+      var district = new AMap.DistrictSearch({
+        extensions: 'all', //杩斿洖琛屾斂鍖鸿竟鐣屽潗鏍囩瓑鍏蜂綋淇℃伅
+        level: 'district' //璁剧疆鏌ヨ琛屾斂鍖虹骇鍒负鍖�
+      });
+      district.search(districtName, function (status, result) {
+        var bounds = result.districtList[0].boundaries; //鑾峰彇鏈濋槼鍖虹殑杈圭晫淇℃伅
+        if (bounds) {
+          for (var i = 0; i < bounds.length; i++) {
+            //鐢熸垚琛屾斂鍖哄垝 polygon
+            // eslint-disable-next-line no-undef
+            const districtPolygon = new AMap.Polygon({
+              map: map, //鏄剧ず璇ヨ鐩栫墿鐨勫湴鍥惧璞�
+              strokeWeight: 1, //杞粨绾垮搴�
+              path: bounds[i], //澶氳竟褰㈣疆寤撶嚎鐨勮妭鐐瑰潗鏍囨暟缁�
+              fillOpacity: 0.6, //澶氳竟褰㈠~鍏呴�忔槑搴�
+              // fillColor: '#CCF3FF', //澶氳竟褰㈠~鍏呴鑹�
+              fillColor: '#0077ff',
+              // strokeColor: '#ffffff' //绾挎潯棰滆壊
+              strokeColor: 'white', //绾挎潯棰滆壊
+              zIndex: 9
+            });
+
+            districtPolygonMap.set(districtName, districtPolygon);
+            activeDistrict = districtPolygon;
+          }
+          // map.setFitView(); //灏嗚鐩栫墿璋冩暣鍒板悎閫傝閲�
+        }
+      });
+    }
+  });
+}
+
 export default {
   /**
+   * 寮�鍏宠鏀垮尯鍒�
+   * @param {boolean} value
+   */
+  toggleDistrict(value) {
+    if (value) {
+      if (toolboxStore.selectedDistrict)
+        drawDistrict(toolboxStore.selectedDistrict);
+    } else {
+      if (activeDistrict) map.remove(activeDistrict);
+    }
+    toolboxStore.districtStatus = value;
+  },
+
+  /**
    * 寮�鍏冲湴鐗╂爣娉�
    * @param {boolean} value
    */

--
Gitblit v1.9.3