leaflet-routing-machine icon indicating copy to clipboard operation
leaflet-routing-machine copied to clipboard

Compatibility with Mapbox Optimization API

Open Bigood opened this issue 5 years ago • 5 comments

Original issue

Passing alternative=(true|false) to the Mapbox Optimization API resulted as a bad request, I needed to have the option to remove the query parameter. While looking at the code, I changed a few things to be able to remove steps and pass the roundtrip parameter to the API.

Reference : https://docs.mapbox.com/api/navigation/#optimization

Usecase

  router: L.Routing.mapbox(process.env.REACT_APP_MAPBOX_API_KEY, {
      serviceUrl: 'https://api.mapbox.com/optimized-trips/v1', //Overrides the serviceUrl
      profile : 'mapbox/cycling',
      routingOptions: {
        roundtrip:true, //Wasn't used on the url construction
        steps: false,  //Will be considered as an option
        alternatives: "default" //Will remove the appended option on the URL
      }
    }),

Changes

Mainly on osrm-v1.js, to be compatible Mapbox Optimization API, see attached commits.

Bigood avatar Jun 06 '19 17:06 Bigood

Hi. Any updates on this? have the same mistake and don't want to change source code.

What do I do?

novaknole avatar Nov 26 '19 14:11 novaknole

Yeah - same here. I'd like to get some cycle routes onto the maps ....

dcrobertson01 avatar Apr 15 '20 04:04 dcrobertson01

@perliedman It's been a year since I've PR this, any plan to merge it?

Bigood avatar Apr 15 '20 11:04 Bigood

@Bigood yeah sorry about that, I don't use LRM for anything myself these days, so it's hard to find the time/energy to work on it, and easy to miss issues and PRs.

This looks good as far as I can tell, with some minor comments I made to the code. Haven't actually tested the code, but I assume you have tested it still works with "normal" routing as well as with the optimization API?

perliedman avatar Apr 15 '20 14:04 perliedman

Thanks for taking the time to review this! I'll test it again with the most recent API, double check my code, and probably correct some bits.

Bigood avatar Apr 15 '20 15:04 Bigood