i have been trying to get this working for quite some time now, but cyclic references from the routes objects, asynchronous execution and whatnot made it hard for me to see the bigger picture.
I am also new to this, as one might have guessed.
So i try to get the closest three parkhouses from a START. So i calculate the routes to extract the e.routes.summary.totalDistance from them. However, i do not want them to be shown in the map just yet, because i want the three closest parkhouses and not every single one.
On the other hand, Leaflet Routing Machine does not calculate these routes if i do not route.addTo(map).
It is a really hard time with this because it does defy all basics i have learned until now. Can someone give me a hint how to do it?
route = L.Routing.control({
name: id,
serviceUrl: 'http://router.project-osrm.org/route/v1',
waypoints: coords,
plan: L.Routing.plan(coords, {
createMarker: function() {
return null;
}
}),
addWaypoints: false,
draggableWaypoints: false,
show: false,
showAlternatives: true
}).on('routesfound', function(e) {
for (let index = 0; index < e.routes.length; index++) {
tmpRoutes.push(e);
tmpDistances.push(e.routes[index].summary.totalDistance);
tmpWayPoints.push(e.routes[index].waypoints)
}
map.removeControl(e.routes);
}).addTo(map);
//map.removeControl(route);
}