Skip to content

Commit 51aeb65

Browse files
committed
Add support for custom instruction compile function.
1 parent ad5415d commit 51aeb65

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/controls/instructions.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class Instructions {
2828
render() {
2929
this.store.subscribe(() => {
3030
const { hoverMarker, setRouteIndex } = this.actions;
31-
const { routeIndex, unit, directions, error } = this.store.getState();
31+
const { routeIndex, unit, directions, error, compile } = this.store.getState();
3232
const shouldRender = !isEqual(directions[routeIndex], this.directions);
3333

3434
if (error) {
@@ -38,6 +38,15 @@ export default class Instructions {
3838

3939
if (directions.length && shouldRender) {
4040
const direction = this.directions = directions[routeIndex];
41+
42+
if (compile) {
43+
direction.legs.forEach(function(leg) {
44+
leg.steps.forEach(function(step) {
45+
step.maneuver.instruction = compile('en', step);
46+
});
47+
});
48+
}
49+
4150
this.container.innerHTML = instructionsTemplate({
4251
routeIndex,
4352
routes: directions.length,

src/directions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Instructions from './controls/instructions';
2626
* @param {String} [options.profile="mapbox/driving-traffic"] Routing profile to use. Options: `mapbox/driving-traffic`, `mapbox/driving`, `mapbox/walking`, `mapbox/cycling`
2727
* @param {Boolean} [options.alternatives=true] Whether to enable alternatives.
2828
* @param {String} [options.unit="imperial"] Measurement system to be used in navigation instructions. Options: `imperial`, `metric`
29+
* @param {Function} [options.compile=null] Provide a custom function for generating instruction, compatible with osrm-text-instructions.
2930
* @param {Object} [options.geocoder] Pass options available to mapbox-gl-geocoder as [documented here](https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#mapboxglgeocoder).
3031
* @param {Object} [options.controls]
3132
* @param {Boolean} [options.controls.inputs=true] Hide or display the inputs control.
@@ -110,7 +111,7 @@ export default class MapboxDirections {
110111
}
111112

112113
mapState() {
113-
const { profile, alternatives, styles, interactive } = store.getState();
114+
const { profile, alternatives, styles, interactive, compile } = store.getState();
114115

115116
// Emit any default or option set config
116117
this.actions.eventEmit('profile', { profile });

src/reducers/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const initialState = {
77
profile: 'mapbox/driving-traffic',
88
alternatives: false,
99
unit: 'imperial',
10+
compile: null,
1011
proximity: false,
1112
styles: [],
1213

0 commit comments

Comments
 (0)