在Leaflet地图上显示方向路线

时间:2017-09-07 15:23:57

标签: leaflet leaflet-routing-machine

如何通过Leaflet地图上的Waypoint显示方向。

我使用“传单路由机”,但我无法查看路线

L.Routing.control({
   waypoints: [
      L.latLng(52.5002237, -2.94),
      L.latLng(52.5002237, -0.949),
      L.latLng(52.5002237, -1.949)
   ], 
   autoRoute: true,
   routeWhileDragging: true,
}).addTo(map);

任何想法或示例plz

你可以在这里找到一个完整的例子(https://codepen.io/mahmoud-nb/pen/RZzNYr

2 个答案:

答案 0 :(得分:1)

您应该检查控制台错误。对router.project-osrm.org的请求失败:

  

无法加载资源:服务器响应状态为503(服务不可用:后端服务器处于容量状态)

答案 1 :(得分:0)

  • 首先,在项目中安装了Leaflet-routing-machine之后,您必须像这样在leaflet-routing-machine.css中添加其他样式到angular.json文件中:
"styles": [
              "node_modules/leaflet-routing-machine/dist/leaflet-routing-machine.css"
          ]
  • 然后在您的组件中导入LRM import 'leaflet-routing-machine';并将路由控件添加为波纹管:
L.Routing.control({
    waypoints: [
    L.latLng(57.74, 11.94),
    L.latLng(57.6792, 11.949)
    ],
    collapsible: true, // hide/show panel routing
    routeWhileDragging: true
    // ...
    }).addTo(this.map);