perliedman / geojson-path-finder

Find shortest path through a network of GeoJSON
https://www.liedman.net/geojson-path-finder/
ISC License
301 stars 87 forks source link

How to add intermediate waypoints (via) #16

Closed s9eenk closed 7 years ago

s9eenk commented 7 years ago

Does the API support intermediate waypoints as shown in the demo ?. How to achieve ?. Imported the (leaflet-headless) and (leaflet-routing-machine) modules , done something but in vain. Any help is appreciated. Thanks in advance :)

perliedman commented 7 years ago

Hi, the API in itself only allows two waypoints. Via points is trivial, though, since you can just do multiple route queries; for example, for a route A->B->C, first query the route A->B, then query the route B->C, and concatenate the results.

The code for the demo is available in the gh-pages branch. You can see more exactly how it interacts with Leaflet Routing Machine, by adding a customer router class, here: https://github.com/perliedman/geojson-path-finder/blob/gh-pages/router.js

s9eenk commented 7 years ago

Nice. saves time. Can we find an alternative route (i.e , second shortest route) ?.

perliedman commented 7 years ago

@s9eenk nice idea, I added #17 to track this suggestion, although I can't promise I will do anything with it soon.

Note though, that more feature-full routing engines like OSRM and GraphHopper do not offer alternative routes when routing through via-points, only for A->B routing.