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/util.js |   95 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 90 insertions(+), 5 deletions(-)

diff --git a/src/utils/map/util.js b/src/utils/map/util.js
index 27871e9..1b7b3a6 100644
--- a/src/utils/map/util.js
+++ b/src/utils/map/util.js
@@ -1,14 +1,76 @@
 import { map, isDragging } from '@/utils/map/index_old';
+import marks from '@/utils/map/marks';
+import Layer from '@/utils/map/3dLayer';
+
+/**
+ * 鍧愭爣闆嗗悎鐨勬渶瑗垮崡瑙掑拰鏈�涓滃寳瑙�
+ * @param {*} list
+ *  list 鏄帴鍙h幏鍙栫殑鐐� 鐨勬暟缁�
+ */
+const getBound = (list) => {
+  const offset = 0.005;
+  let south = null;
+  let west = null;
+  let north = null;
+  let east = null;
+  for (let item of list) {
+    // 鎺掗櫎鏃犳晥缁忕含搴�
+    if (item[0] == 0 && item[1] == 0) {
+      continue;
+    }
+    if ((west && item[0] < west) || !west) {
+      west = item[0] - offset;
+    }
+    if ((south && item[1] < south) || !south) {
+      south = item[1] - offset;
+    }
+    if ((east && item[0] > east) || !east) {
+      east = item[0] + offset;
+    }
+    if ((north && item[1] > north) || !north) {
+      north = item[1] + offset;
+    }
+  }
+  if (!south || !west || !north || !east) {
+    return { sw: null, ne: null };
+  } else {
+    return { sw: [west, south], ne: [east, north] };
+  }
+};
+
+/**
+ * 鏍规嵁涓績鐐瑰嚭鍙戠殑鍗婂緞锛屽緱鍒板悎閫傜殑鍦板浘缂╂斁绯绘暟
+ * 楂樺痉鍦板浘缂╂斁绯绘暟姣忓噺灏�1锛屽垯鍦板浘灞曠ず鐨勫疄闄呰窛绂绘斁澶�1鍊�
+ * 楂樺痉鍦板浘缂╂斁绯绘暟鑼冨洿[3, 18]
+ * @param {*} d
+ */
+const distanceToZoom = (d) => {
+  let baseDis = 250,
+    z = 0;
+  while (baseDis < d) {
+    baseDis *= 2;
+    z++;
+  }
+
+  // 澶氫綑鐨勫湴鍥剧缉鏀剧郴鏁�
+  const x = (baseDis - d) / (baseDis / 2);
+  z -= x;
+  z = z < 0 ? 0 : z;
+
+  z = 18 - z;
+  z = z < 3 ? 3 : z;
+  return z;
+};
 
 export default {
-  setCenter(lnglat) {
-    if (isDragging) {
+  setCenter(lnglat, ignore = false) {
+    if (!ignore && isDragging) {
       return;
     }
     var now = new Date();
     if (
       this.lasttime == undefined ||
-      now.getTime() - this.lasttime.getTime() >= 1000
+      now.getTime() - this.lasttime.getTime() >= 200
     ) {
       map.setCenter(lnglat);
       this.lasttime = now;
@@ -20,7 +82,30 @@
   removeViews(view) {
     map.remove(view);
   },
-  setFitView() {
-    map.setFitView();
+  clearMap() {
+    marks.clearMassMarks();
+    map.clearMap();
+    Layer.clear();
+  },
+  setFitView(views) {
+    if (views) {
+      map.setFitView(views);
+    } else {
+      map.setFitView();
+    }
+  },
+  setFitSector({ p, r }) {
+    this.setCenter(p);
+    const z = distanceToZoom(r);
+    map.setZoom(z);
+  },
+  setBound(lnglats_GD) {
+    const { sw, ne } = getBound(lnglats_GD);
+    if (!sw || !ne) {
+      return;
+    }
+    // eslint-disable-next-line no-undef
+    var mybounds = new AMap.Bounds(sw, ne); // sw, ne > [xxx,xxx], [xxx,xxx]
+    map.setBounds(mybounds);
   }
 };

--
Gitblit v1.9.3