From 87e19b5a396ac8fed6a551828b87d263f6425c31 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期四, 16 十月 2025 10:26:12 +0800
Subject: [PATCH] 2025.10.16 修改季度报告生成逻辑
---
src/utils/map/line.js | 126 +++++++++++++++++++++++++++++++++--------
1 files changed, 100 insertions(+), 26 deletions(-)
diff --git a/src/utils/map/line.js b/src/utils/map/line.js
index 5334f3a..a4395dd 100644
--- a/src/utils/map/line.js
+++ b/src/utils/map/line.js
@@ -2,43 +2,117 @@
import calculate from './calculate';
import { getHexColor } from '../color';
-var _polylineArr = [];
+var defaultPolylineArr = [];
+const lineMap = new Map();
+
+function newPolyline(path, color) {
+ // eslint-disable-next-line no-undef
+ return new AMap.Polyline({
+ path: path,
+ // strokeStyle: 'solid',
+ strokeStyle: 'dashed',
+ isOutline: true,
+ borderWeight: 1,
+ outlineColor: 'white',
+ strokeWeight: 4, // 绾挎潯瀹藉害锛岄粯璁や负 1
+ strokeColor: color, // 绾挎潯棰滆壊
+ lineJoin: 'round', // 鎶樼嚎鎷愮偣杩炴帴澶勬牱寮�
+ showDir: true
+ });
+}
+
+function drawDirection(path) {
+ const polyline = newPolyline(path, '#ffd82a');
+ map.add(polyline);
+ return polyline;
+}
export default {
drawLine(fDatas, factor) {
+ if (defaultPolylineArr.length > 0) {
+ map.remove(defaultPolylineArr);
+ defaultPolylineArr = [];
+ }
+
const lnglats_GD = fDatas.lnglats_GD;
const colors = factor.colors;
- if (_polylineArr) {
- map.remove(_polylineArr);
- _polylineArr = [];
- }
+ // this.hideLine();
+
var path = calculate.parse2LngLat(lnglats_GD);
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
- });
- _polylineArr.push(polyline);
+ var distance = AMap.GeometryUtil.distance(r, lastP);
+ const c = colors[i];
+ 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) {
+ sIndex = i;
+ } else {
+ sIndex = i - 1;
+ }
+
+ // 鍒涘缓鎶樼嚎瀹炰緥
+ const polyline = newPolyline(_path, _color);
+ defaultPolylineArr.push(polyline);
+ }
+ }
+ 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) {
+ return v * 255;
+ } else {
+ return v;
+ }
+ })
+ );
+ const polyline = newPolyline(_path, _color);
+ defaultPolylineArr.push(polyline);
}
// 灏嗘姌绾挎坊鍔犺嚦鍦板浘瀹炰緥
- map.add(_polylineArr);
- return _polylineArr;
- }
+ map.add(defaultPolylineArr);
+ return defaultPolylineArr;
+ },
+
+ 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);
+ } else {
+ lineMap.forEach((v) => {
+ map.remove(v);
+ });
+ }
+ },
+
+ drawDirection
};
--
Gitblit v1.9.3