From 2030a7c8a63e2a7f2f565cfaa548865cf52fa79a Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 19 Feb 2026 18:20:41 -0600 Subject: [PATCH] Fix trail hover showing wrong igate RF path Use mousemove instead of mouseover so the RF path updates as the cursor moves along the trail. Send the mouse position rather than the nearest-position's coordinates so the path line anchors where the user is actually hovering. Debounce and deduplicate events to avoid flooding the server. --- assets/js/features/trail_manager.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/assets/js/features/trail_manager.ts b/assets/js/features/trail_manager.ts index 016691e..2995414 100644 --- a/assets/js/features/trail_manager.ts +++ b/assets/js/features/trail_manager.ts @@ -54,6 +54,8 @@ export class TrailManager { private minSegmentPoints: number = 3; // minimum points in a segment to draw it private onTrailHover?: (lat: number, lng: number, path: string) => void; private onTrailHoverEnd?: () => void; + private trailHoverDebounceTimer?: ReturnType; + private lastHoveredPath?: string; constructor( trailLayer: LayerGroup, @@ -423,18 +425,35 @@ export class TrailManager { const hoverCb = this.onTrailHover; const hoverEndCb = this.onTrailHoverEnd; - trailState.trail.on("mouseover", (e: L.LeafletMouseEvent) => { + trailState.trail.on("mousemove", (e: L.LeafletMouseEvent) => { const nearest = this.findNearestPositionWithPath( e.latlng.lat, e.latlng.lng, positions, ); - if (nearest) { - hoverCb(nearest.lat, nearest.lng, nearest.path!); + if (!nearest) return; + + if (this.trailHoverDebounceTimer) { + clearTimeout(this.trailHoverDebounceTimer); + } + const mouseLat = e.latlng.lat; + const mouseLng = e.latlng.lng; + const path = nearest.path!; + // Only push to server when the path changes; just reposition locally otherwise + if (path !== this.lastHoveredPath) { + this.lastHoveredPath = path; + this.trailHoverDebounceTimer = setTimeout(() => { + hoverCb(mouseLat, mouseLng, path); + }, 50); } }); trailState.trail.on("mouseout", () => { + this.lastHoveredPath = undefined; + if (this.trailHoverDebounceTimer) { + clearTimeout(this.trailHoverDebounceTimer); + this.trailHoverDebounceTimer = undefined; + } hoverEndCb(); }); }