From 66090d06a87ff940fd5fc138d7260c755a5a3127 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 14 二月 2025 17:26:27 +0800
Subject: [PATCH] 新增数据平面展示方式

---
 src/utils/map/line.js |   83 +++++++++++++++++++++++++++++++++--------
 1 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/src/utils/map/line.js b/src/utils/map/line.js
index 5334f3a..6c72bb5 100644
--- a/src/utils/map/line.js
+++ b/src/utils/map/line.js
@@ -4,6 +4,21 @@
 
 var _polylineArr = [];
 
+function newPolyline(path, color) {
+  // eslint-disable-next-line no-undef
+  return new AMap.Polyline({
+    path: path,
+    strokeStyle: 'solid',
+    isOutline: true,
+    borderWeight: 1,
+    outlineColor: 'white',
+    strokeWeight: 4, // 绾挎潯瀹藉害锛岄粯璁や负 1
+    strokeColor: color, // 绾挎潯棰滆壊
+    lineJoin: 'round', // 鎶樼嚎鎷愮偣杩炴帴澶勬牱寮�
+    showDir: true
+  });
+}
+
 export default {
   drawLine(fDatas, factor) {
     const lnglats_GD = fDatas.lnglats_GD;
@@ -17,24 +32,58 @@
 
     let sIndex = 0;
     for (let i = 1; i < path.length; i++) {
-      // if (colors[i] == colors[i - 1]) {
-      // } else {
-      // }
-      const _path = [path[i], path[i + 1]];
-      const _color = getHexColor(colors[i + 1].map((v) => v * 255));
-      // 鍒涘缓鎶樼嚎瀹炰緥
+      var r = lnglats_GD[i];
+      var lastP = lnglats_GD[i - 1];
       // eslint-disable-next-line no-undef
-      const polyline = new AMap.Polyline({
-        path: _path,
-        strokeStyle: 'solid',
-        isOutline: true,
-        borderWeight: 2,
-        outlineColor: 'white',
-        strokeWeight: 4, // 绾挎潯瀹藉害锛岄粯璁や负 1
-        strokeColor: _color, // 绾挎潯棰滆壊
-        lineJoin: 'round', // 鎶樼嚎鎷愮偣杩炴帴澶勬牱寮�
-        showDir: true
-      });
+      var distance = AMap.GeometryUtil.distance(r, lastP);
+      const c = colors[i];
+      const lastC = colors[i - 1];
+      if (distance > 500 || c != lastC) {
+        let _path, _color;
+        // 褰撲袱鐐硅窛绂昏秴杩�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;
+              }
+            })
+          );
+        } else {
+          _path = path.slice(sIndex, i + 1);
+          _color = getHexColor(
+            c.map((v, index) => {
+              if (index < c.length - 1) {
+                return v * 255;
+              } else {
+                return v;
+              }
+            })
+          );
+        }
+
+        // 鍒涘缓鎶樼嚎瀹炰緥
+        const polyline = newPolyline(_path, _color);
+        _polylineArr.push(polyline);
+
+        sIndex = i;
+      }
+    }
+    if (sIndex == 0) {
+      const c = colors[sIndex];
+      const _color = getHexColor(
+        c.map((v, index) => {
+          if (index < c.length - 1) {
+            return v * 255;
+          } else {
+            return v;
+          }
+        })
+      );
+      const polyline = newPolyline(path, _color);
       _polylineArr.push(polyline);
     }
     // 灏嗘姌绾挎坊鍔犺嚦鍦板浘瀹炰緥

--
Gitblit v1.9.3