Skip to content

fix: flip CVSR train icon based on GPS heading (#532)#535

Merged
fatherlinux merged 1 commit into
masterfrom
fix/532-train-icon-heading
Jun 26, 2026
Merged

fix: flip CVSR train icon based on GPS heading (#532)#535
fatherlinux merged 1 commit into
masterfrom
fix/532-train-icon-heading

Conversation

@fatherlinux

Copy link
Copy Markdown
Member

Summary

  • Train icon now faces the direction of travel instead of always following the track linestring digitization direction
  • Compares the snap-to-line bearing against the GPS heading from the USFT tracker
  • If they differ by more than 90°, flips the bearing by 180°
  • 3-line change in the snappedTrain useMemo in Map.jsx

Closes #532

Test plan

  • Verify train icon faces north when train is heading northbound
  • Verify train icon faces south when train is heading southbound
  • Verify icon still snaps to track geometry (no floating off the line)
  • Verify smooth rotation transition when direction changes

🤖 Generated with Claude Code

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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1517 to +1520
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;

@fatherlinux fatherlinux merged commit 977734a into master Jun 26, 2026
2 of 3 checks passed
@fatherlinux fatherlinux deleted the fix/532-train-icon-heading branch June 26, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CVSR train icon does not flip direction based on heading

1 participant