From 794b74cadb4a1c152ae2cb613d6c361845b7e600 Mon Sep 17 00:00:00 2001 From: artem Date: Mon, 21 Sep 2026 10:27:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=BF=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=BA=D1=80=D1=83=D0=B6=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=BA=D0=BB=D0=B8=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/workouts/components/WorkoutItem.vue | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/pages/workouts/components/WorkoutItem.vue b/src/pages/workouts/components/WorkoutItem.vue index 10cd2fb..44b18ce 100644 --- a/src/pages/workouts/components/WorkoutItem.vue +++ b/src/pages/workouts/components/WorkoutItem.vue @@ -28,16 +28,17 @@
1
@@ -518,17 +519,30 @@ const group = new ChartGroup([]); const mapX = ref>([]); let currentCoordinates = ref | null>([]); let clickCoordinates = ref([]); -let coordWithIndex: Map = new Map(); let showModalTitle = ref(false); const showModalLink = ref(false); -const getKey = (x: number, y: number) => { - x = Math.round(x * 1000) / 1000; - y = Math.round(y * 1000) / 1000; - return `${x}-${y}`; +const CLICK_TRACK_RADIUS_M = 40; +/** + * Finds the nearest track point index within CLICK_TRACK_RADIUS_M (metres) + * of the clicked lng/lat using an equirectangular approximation. Returns -1 + * when the click is farther than the radius from every track point. + */ +const findNearestTrackIndex = (lng: number, lat: number): number => { + let bestIdx = -1; + let bestDist = Infinity; + for (let i = 0; i < lineCoordinates.length; i++) { + const [pLng, pLat] = lineCoordinates[i]; + const midLatRad = ((lat + pLat) / 2) * (Math.PI / 180); + const dx = (pLng - lng) * 111320 * Math.cos(midLatRad); + const dy = (pLat - lat) * 110540; + const dist = Math.hypot(dx, dy); + if (dist < bestDist) { + bestDist = dist; + bestIdx = i; + } + } + return bestDist <= CLICK_TRACK_RADIUS_M ? bestIdx : -1; }; -for (let i = 0; i < lineCoordinates.length; i++) { - coordWithIndex.set(getKey(lineCoordinates[i][0], lineCoordinates[i][1]), i); -} ChartJS.register( Title, Tooltip,