Search code examples
mapboxosrm

add local osrm sever to mapbox gl direction


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.


Solution

  • 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);