Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion frontend/src/components/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +1517 to +1520

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;

}, [trainPosition, trainFeature]);

const getLinearFeatureStyle = useCallback((feature, isSelected) => {
Expand Down
Loading