From 3c21fb0cefd62dd0fa890c23e0fa2c96bcc463b5 Mon Sep 17 00:00:00 2001 From: Scott McCarty Date: Thu, 25 Jun 2026 19:53:53 -0400 Subject: [PATCH] fix: flip CVSR train icon based on GPS heading (#532) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The train icon was always pointing in the direction the track linestring was digitized, regardless of which way the train was actually traveling. Now compares the snap-to-line bearing against the GPS heading from the USFT tracker — if they differ by more than 90°, the bearing is flipped 180° so the icon faces the direction of travel. Co-Authored-By: Claude Opus 4.6 (1M context) --- frontend/src/components/Map.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/Map.jsx b/frontend/src/components/Map.jsx index 1a3a519..dd6eab5 100644 --- a/frontend/src/components/Map.jsx +++ b/frontend/src/components/Map.jsx @@ -1510,10 +1510,14 @@ function Map({ destinations, selectedPoi, selectedIsLinear, onSelectPoi, isAdmin const snappedTrain = useMemo(() => { if (!trainPosition || !trainFeature?.geometry?.coordinates) return null; - return snapToLine( + const snap = snapToLine( [trainPosition.latitude, trainPosition.longitude], trainFeature.geometry.coordinates ); + const gpsHeading = trainPosition.heading || 0; + const diff = Math.abs(((snap.bearing - gpsHeading + 540) % 360) - 180); + if (diff > 90) snap.bearing = (snap.bearing + 180) % 360; + return snap; }, [trainPosition, trainFeature]); const getLinearFeatureStyle = useCallback((feature, isSelected) => {