I'm using the leaflet-routing library https://github.com/perliedman/leaflet-routing-machine/releases/tag/v3.1.1

How can I limit the amount of routes the L.Routing.control returns.

I'm using this code:

fDirectionService = new L.Routing.control({
    waypoints: [
        new L.latLng(-27.1216666667, -52.6213888889),
        new L.latLng(-27.5963, -48.5491)
}).addTo(map).on('routesfound', function(e) {
    console.log(e.routes); // e.routes have length 2

After the 'routesfound' event it returns 2 routes (fDirectionService._routes.length == 2)

Can I request only one? Or at least hide all except the first?

L.Routing.control with two routes

Edit: There is an option showAlternatives: http://www.liedman.net/leaflet-routing-machine/api/ but even that doesn't work.

Edit 2: Days and nobody answered, that's odd. Anyway, I've tested with Mapbox e with the same coordinates it returns only one route, could it be that it must be configured on the server side only?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.