Home

Awesome

<img src="https://travis-ci.org/Project-OSRM/osrm-text-instructions.svg?branch=master" align="right" alt="Build status">

OSRM Text Instructions

OSRM Text Instructions is a Node.js library that transforms route data generated by OSRM into localized turn instructions to be displayed visually or read aloud by a text-to-speech engine. OSRM Text Instructions is the basis of guidance instructions in osrm-frontend, the Mapbox Directions API, and the Mapbox Navigation SDK.

Usage

NPM

var version = 'v5';
var osrmTextInstructions = require('osrm-text-instructions')(version);

response.legs.forEach(function(leg) {
  leg.steps.forEach(function(step) {
    instruction = osrmTextInstructions.compile('en', step, options)
  });
});

If you are unsure if the user's locale is supported by osrm-text-inustrctions, use @mapbox/locale-utils for finding the best fitting language.

Parameters require('osrm-text-instructions')(version)

parameterrequired?valuesdescription
versionrequiredv5Major OSRM version

Parameters compile(language, step, options)

parameterrequired?valuesdescription
languagerequireden de zh-Hans fr nl ru and moreCompiling instructions for the selected language code.
steprequiredOSRM route step objectThe RouteStep as it comes out of OSRM
optionsoptionalObjectSee below
Options
keytypedescription
legCountintegerNumber of legs in the route
legIndexintegerZero-based index of the leg containing the step; together with legCount, this option determines which waypoint the user has arrived at
formatTokenfunctionFunction that formats the given token value after grammaticalization and capitalization but before the value is inserted into the instruction string; useful for wrapping tokens in markup
waypointNamestringOptional custom name for the leg's destination, replaces "your {nth} destination"

formatToken takes two parameters:

and returns a string.

Architecture

Contributing

We welcome feedback, code contributions, and translations! Please see CONTRIBUTING.md for details.

Transifex