Skip to content

Bug: _leftOrRight forces ramp modifiers to 'Right', ignoring 'straight' #719

@DennisOSRM

Description

@DennisOSRM

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions