传单路由机 - IRoute.summary.totalDistance
leaflet routing machine - IRoute.summary.totalDistance
我正在使用 Leaflet 1.2.0 和 Leaflet Routing Machine 3.2.12。
我的代码在地图上绘制了正确的路线,但是,当我想访问摘要和摘要中的总距离时,两者都未定义。这是为什么?
function createRoute(id, coords) {
route = L.Routing.control({
name: id,
serviceUrl: 'http://router.project-osrm.org/route/v1',
//router: L.Routing.graphHopper('apiKey');
waypoints: coords, //way_points,
addWaypoints: false,
draggableWaypoints: false,
show: false,
}).on('routesfound', function(e) {
console.log(this.summary.totalDistance);
// console.log(route.summary.totalDistance);
})
//.on('routesfound', function(e) {
// routes = e.routes; //is declared and instantiated before the function
// // createRoute
// RouteLength = routes[0].summary.totalDistance;
//});
.addTo(map);
}
错误: 路由错误:状态 -3 TypeError:无法读取未定义的属性(读取 'totalDistance')。
从控制台我得到升级:
fire @ leaflet.js:5
(anonym) @ leaflet-routing-machine.js:16166
(anonym) @ leaflet-routing-machine.js:18004
loaded @ leaflet-routing-machine.js:46
load (asynchron)
corslite @ leaflet-routing-machine.js:53
route @ leaflet-routing-machine.js:17977
route @ leaflet-routing-machine.js:16151
onAdd @ leaflet-routing-machine.js:15919
addTo @ leaflet.js:5
createRoute @ POI-Dash implement Routing.html:586
有人了解更多吗?
this
没有 summary
。您将需要参考 e.routes
,例如 e.routes[0].summary.totalDistance
。
我正在使用 Leaflet 1.2.0 和 Leaflet Routing Machine 3.2.12。
我的代码在地图上绘制了正确的路线,但是,当我想访问摘要和摘要中的总距离时,两者都未定义。这是为什么?
function createRoute(id, coords) {
route = L.Routing.control({
name: id,
serviceUrl: 'http://router.project-osrm.org/route/v1',
//router: L.Routing.graphHopper('apiKey');
waypoints: coords, //way_points,
addWaypoints: false,
draggableWaypoints: false,
show: false,
}).on('routesfound', function(e) {
console.log(this.summary.totalDistance);
// console.log(route.summary.totalDistance);
})
//.on('routesfound', function(e) {
// routes = e.routes; //is declared and instantiated before the function
// // createRoute
// RouteLength = routes[0].summary.totalDistance;
//});
.addTo(map);
}
错误: 路由错误:状态 -3 TypeError:无法读取未定义的属性(读取 'totalDistance')。
从控制台我得到升级:
fire @ leaflet.js:5
(anonym) @ leaflet-routing-machine.js:16166
(anonym) @ leaflet-routing-machine.js:18004
loaded @ leaflet-routing-machine.js:46
load (asynchron)
corslite @ leaflet-routing-machine.js:53
route @ leaflet-routing-machine.js:17977
route @ leaflet-routing-machine.js:16151
onAdd @ leaflet-routing-machine.js:15919
addTo @ leaflet.js:5
createRoute @ POI-Dash implement Routing.html:586
有人了解更多吗?
this
没有 summary
。您将需要参考 e.routes
,例如 e.routes[0].summary.totalDistance
。