I want to change the routing vehicle when clicked on a button. The default routing vehicle is "car" ("auto") when clicked a button routing vehicle should change to "foot" ("pedestrian").

I am using leaflet.easy.button and leaflet.routing.machine plugins, as routeservice I use mapzen.


My code:

  1. Routing.control :

    var myRouter = L.Routing.control({
        router: L.Routing.mapzen('valhalla-ABCDEFG', {
        routeWhileDragging: true,
        geocoder: L.Control.Geocoder.nominatim(),
        formatter: new L.Routing.mapzenFormatter()
  2. Easy.Button :

    L.easyButton('<img src="pic.png">', function(btn,map){
        myRouter.route({costing: "pedestrian"});

Any ideas what could be wrong? Or maybe a different way to approach this problem.

1 Answer 1


The route method does not pass any options on to the router. You'll want to use the getRouter method to set the router options first. Then you can recalculate using route:

L.easyButton('<img src="pic.png">', function(btn,map){
  myRouter.getRouter().options.costing = "pedestrian";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.