fix: flip CVSR train icon based on GPS heading (#532)#535
Conversation
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) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request updates the snapped train's bearing calculation in the Map component to align the train icon with its actual direction of travel based on the GPS heading. The feedback suggests only performing this bearing adjustment when a valid numeric GPS heading is present to prevent the icon from incorrectly flipping or facing North when heading data is unavailable.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| 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; |
There was a problem hiding this comment.
Defaulting to 0 when trainPosition.heading is null or undefined can cause the train icon to incorrectly flip or face North (0°) when heading data is unavailable. We should only perform the bearing adjustment if a valid numeric GPS heading is present.
if (typeof trainPosition.heading === 'number') {
const gpsHeading = trainPosition.heading;
const diff = Math.abs(((snap.bearing - gpsHeading + 540) % 360) - 180);
if (diff > 90) snap.bearing = (snap.bearing + 180) % 360;
}
return snap;
Summary
snappedTrainuseMemo in Map.jsxCloses #532
Test plan
🤖 Generated with Claude Code