我一直试图让它工作很长一段时间,但是来自路由对象的循环引用、异步执行等等让我很难看到更大的图景。
正如人们可能已经猜到的那样,我对此也很陌生。
所以我试着从一开始就找到最近的三个公园屋。所以我计算了从中提取 e.routes.summary.totalDistance 的路线。但是,我现在还不希望它们显示在地图上,因为我想要三个最近的公园屋,而不是每一个。另一方面,如果我不计算,Leaflet Routing Machine 不会计算这些路由route.addTo(map)
。
这真的很难,因为它确实违背了我到目前为止所学的所有基础知识。有人可以给我一个提示怎么做吗?
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);
}