2

I am going to use my local osrm server in order to do routing in a map based on mapbox GL. In mapbox-gl-directions.js there is a server part:

var initialState = {      
   api: 'https://api.mapbox.com/directions/v5/',
   profile: 'driving-traffic',
   unit: 'imperial',
   proximity: false,
   styles: [],
  controls: {
     inputs: true,
     instructions: true
  },

I would like to replace api with 'localhost:5000/route/v1/' but it is not working. Thanks.

rahram
  • 560
  • 1
  • 7
  • 21

1 Answers1

2

OK. There are two lines that should be modified in mapbox-gl-directions.js.

First: change

api: 'https://api.mapbox.com/directions/v5/',

to

api: 'localhost:5000/route/v1/driving/',

Second: change

request.open('GET', api + 'mapbox/' + profile + '/' + query + '.json?' + options.join('&'), true);

to

request.open('GET', api + query + '?alternatives=true&steps=true&geometries=polyline&overview=full&annotations=true', true); 
rahram
  • 560
  • 1
  • 7
  • 21
  • 1
    Directions version v3.1.3 do it slightly different in concatenating API and query. Now they put 'mapbox/' as part of profile name. You do not need to change anything in request anymore, instead change two lines in initialState: api - replace with 'localhost:5000/route/v1/', and below it profile - replace with 'driving'. Much cleaner that way. – Sanctus Sep 25 '18 at 17:29