Kaynağa Gözat

fix: 干线系统和勤务路线线路上的路口数据减少20%

sequoia tungfang 3 hafta önce
ebeveyn
işleme
1a6ccbef0e
1 değiştirilmiş dosya ile 19 ekleme ve 2 silme
  1. 19 2
      src/components/TongzhouTrafficMap.vue

+ 19 - 2
src/components/TongzhouTrafficMap.vue

@@ -459,9 +459,9 @@ export default {
         overlays.push(polyline);
 
         const totalPoints = segmentPath.length;
-        const stepSize = Math.max(Math.floor(totalPoints / 10), 1);
+        const indices = this.pickEvenlySpacedIndices(totalPoints, 8);
 
-        for (let i = 0; i < totalPoints; i += stepSize) {
+        for (const i of indices) {
           const p = segmentPath[i];
           const lng = p && typeof p.lng === 'number' ? p.lng : (Array.isArray(p) ? Number(p[0]) : NaN);
           const lat = p && typeof p.lat === 'number' ? p.lat : (Array.isArray(p) ? Number(p[1]) : NaN);
@@ -479,6 +479,23 @@ export default {
       return overlays;
     },
 
+    pickEvenlySpacedIndices(totalPoints, count) {
+      const total = Math.max(Number(totalPoints) || 0, 0);
+      const target = Math.max(Number(count) || 0, 0);
+      if (total <= 0) return [];
+      if (target <= 0) return [];
+      if (target >= total) return Array.from({ length: total }, (_, i) => i);
+      if (target === 1) return [0];
+
+      const set = new Set();
+      const last = total - 1;
+      for (let k = 0; k < target; k += 1) {
+        const idx = Math.round((k * last) / (target - 1));
+        set.add(idx);
+      }
+      return Array.from(set).sort((a, b) => a - b);
+    },
+
     buildFallbackLinePath(start, end, pointCount) {
       const sLng = Number(start && start[0]);
       const sLat = Number(start && start[1]);