perliedman/leaflet-routing-machine

How to select route?

16bc opened this issue · 2 comments

16bc commented

How to select route (to fire 'routeselected') by index?
this way partly working:

control._routeSelected({route: routes[idx]});

but hides altroutes on map.
routes variable got by 'routesfound' event.
What is the right way?

You're on the right track!

_routeSelected accepts a second event argument called alternatives that updates the alternative routes.

control._routeSelected({route: routes[idx], alternatives: routes.filter((r, i) => routes.indexOf(r) !== i)});

should work, hopefully

16bc commented

You're on the right track!

Thanks, i replace i to idx, and it works!
control._routeSelected({route: routes[idx], alternatives: routes.filter((r, i) => routes.indexOf(r) !== idx)});