From 2592dc279ec82bf3649a4dbe644c6416263a10ef Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 07 三月 2025 17:10:25 +0800
Subject: [PATCH] 各模块功能新增

---
 src/utils/map/line.js |   67 ++++++++++++++++++---------------
 1 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/src/utils/map/line.js b/src/utils/map/line.js
index 57869ac..39dbccc 100644
--- a/src/utils/map/line.js
+++ b/src/utils/map/line.js
@@ -2,7 +2,8 @@
 import calculate from './calculate';
 import { getHexColor } from '../color';
 
-var _polylineArr = [];
+// var _polylineArr = [];
+const lineMap = new Map();
 
 function newPolyline(path, color) {
   // eslint-disable-next-line no-undef
@@ -21,10 +22,11 @@
 
 export default {
   drawLine(fDatas, factor) {
+    const _polylineArr = [];
     const lnglats_GD = fDatas.lnglats_GD;
     const colors = factor.colors;
 
-    this.hideLine();
+    // this.hideLine();
 
     var path = calculate.parse2LngLat(lnglats_GD);
 
@@ -38,40 +40,31 @@
       const lastC = colors[i - 1];
       if (distance > 500 || c != lastC) {
         let _path, _color;
+        _path = path.slice(sIndex, i);
+        _color = getHexColor(
+          lastC.map((v, index) => {
+            if (index < lastC.length - 1) {
+              return v * 255;
+            } else {
+              return v;
+            }
+          })
+        );
         // 褰撲袱鐐硅窛绂昏秴杩�500鏃讹紝璁や负涓ょ偣涓嶈繛缁紝涓嶇粯鍒惰繛绾�
         if (distance > 500) {
-          _path = path.slice(sIndex, i);
-          _color = getHexColor(
-            lastC.map((v, index) => {
-              if (index < lastC.length - 1) {
-                return v * 255;
-              } else {
-                return v;
-              }
-            })
-          );
+          sIndex = i;
         } else {
-          _path = path.slice(sIndex, i + 1);
-          _color = getHexColor(
-            c.map((v, index) => {
-              if (index < c.length - 1) {
-                return v * 255;
-              } else {
-                return v;
-              }
-            })
-          );
+          sIndex = i - 1;
         }
 
         // 鍒涘缓鎶樼嚎瀹炰緥
         const polyline = newPolyline(_path, _color);
         _polylineArr.push(polyline);
-
-        sIndex = i;
       }
     }
-    if (sIndex == 0) {
-      const c = colors[sIndex];
+    if (sIndex < path.length - 1) {
+      const c = colors[path.length - 1];
+      const _path = path.slice(sIndex, path.length);
       const _color = getHexColor(
         c.map((v, index) => {
           if (index < c.length - 1) {
@@ -81,7 +74,7 @@
           }
         })
       );
-      const polyline = newPolyline(path, _color);
+      const polyline = newPolyline(_path, _color);
       _polylineArr.push(polyline);
     }
     // 灏嗘姌绾挎坊鍔犺嚦鍦板浘瀹炰緥
@@ -89,10 +82,24 @@
     return _polylineArr;
   },
 
-  hideLine() {
-    if (_polylineArr) {
+  drawTagLine(tag, fDatas, factor) {
+    if (lineMap.has(tag)) {
+      const _polylineArr = lineMap.get(tag);
+      map.add(_polylineArr);
+    } else {
+      const _polylineArr = this.drawLine(fDatas, factor);
+      lineMap.set(tag, _polylineArr);
+    }
+  },
+
+  hideLine(tag) {
+    if (tag && lineMap.has(tag)) {
+      const _polylineArr = lineMap.get(tag);
       map.remove(_polylineArr);
-      _polylineArr = [];
+    } else {
+      lineMap.forEach((v) => {
+        map.remove(v);
+      });
     }
   }
 };

--
Gitblit v1.9.3