Description
_leftOrRight in src/osrm-v1.js is used by _maneuverToModifier for on ramp, off ramp, merge, fork, and end of road step types. The function is purely binary — anything that doesn't contain left becomes Right:
_leftOrRight: function(d) {
return d.indexOf('left') >= 0 ? 'Left' : 'Right';
}
Problem
When OSRM returns an on ramp straight step (a valid OSRM v5 maneuver), the modifier straight does not contain left, so it gets mapped to Right. Downstream, formatter.js's getIconName then renders a right-turn arrow even though the instruction text correctly says "straight".
This was reported in the osrm-frontend repo: Project-OSRM/osrm-frontend#255
Suggested Fix
Explicitly check for right as well, and fall back to passing the original modifier through unchanged for anything else:
_leftOrRight: function(d) {
if (d.indexOf('left') >= 0) return 'Left';
if (d.indexOf('right') >= 0) return 'Right';
return d; // preserves 'straight', 'uturn', etc.
}
This keeps the existing behaviour for left, slight left, sharp left, right, slight right, and sharp right, while letting straight (and any other non-directional modifier) pass through so the correct icon is rendered.
Workaround
osrm-frontend is currently working around this by monkey-patching the method on the router instance — see PR Project-OSRM/osrm-frontend#406.
Description
_leftOrRightinsrc/osrm-v1.jsis used by_maneuverToModifierforon ramp,off ramp,merge,fork, andend of roadstep types. The function is purely binary — anything that doesn't containleftbecomesRight:Problem
When OSRM returns an
on ramp straightstep (a valid OSRM v5 maneuver), the modifierstraightdoes not containleft, so it gets mapped toRight. Downstream,formatter.js'sgetIconNamethen renders a right-turn arrow even though the instruction text correctly says "straight".This was reported in the osrm-frontend repo: Project-OSRM/osrm-frontend#255
Suggested Fix
Explicitly check for
rightas well, and fall back to passing the original modifier through unchanged for anything else:This keeps the existing behaviour for
left,slight left,sharp left,right,slight right, andsharp right, while lettingstraight(and any other non-directional modifier) pass through so the correct icon is rendered.Workaround
osrm-frontend is currently working around this by monkey-patching the method on the router instance — see PR Project-OSRM/osrm-frontend#406.