Leaflet Routing Machine - 选项的使用

Leaflet Routing Machine - Usage of options

我不太明白如何将选项应用于传单路由机。这是使用路由的基本代码:

var map = L.map('map');

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

L.Routing.control({
waypoints: [
    L.latLng(57.74, 11.94),
    L.latLng(57.6792, 11.949)
]
}).addTo(map);

现在,我想做的是,隐藏行程文本,根据我在 API 中写的内容,它应该如下所示:

L.Routing.itinerary({
  show: false
 }).addTo(map); 

但这不起作用,当我尝试使标记不可拖动并使路线不可更改时,它也不起作用,我认为我做错了什么,因为我可以改变任何东西我想要代码,它不会改变显示的任何内容...

基本上我想做的是显示一条无法通过拖动标记更改的路线并且没有行程文本,换句话说,您无法更改原始显示。

感谢您的宝贵时间!

您可以直接将选项应用到 L.Routing.Control:

var routingControl = new L.Routing.Control({
    waypoints: [
        L.latLng(57.74, 11.94),
        L.latLng(57.6792, 11.949)
    ],
    show: false
}).addTo(map);

L.Routing.itineraryL.Routing.Control 的基类。无需创建它的实例。您已经将 L.Routing.Control 添加到您的地图中。由于 L.Routing.Control 是从 L.Routing.Itinerary 扩展而来的,它也继承了 show 选项。见 API:

L.Routing.Control: Combining the other classes into a full routing user interface. The main class of the plugin. Extends L.Routing.Itinerary and implements IControl.

http://www.liedman.net/leaflet-routing-machine/api/#l-routing-control

我通过覆盖 control.plan 中的 createMarker 函数并将 draggable: false 传递给标记来禁用可拖动标记。这是 只读传单映射 控制路由机器配置的片段。

var control, waypoints;

waypoints = [];

control = L.Routing.control({
  waypoints: waypoints,
  plan: L.Routing.plan(waypoints, {
    createMarker: function(i, wp) {
      return L.marker(wp.latLng, {
        draggable: false
      });
    }
  }),
  addWaypoints: false,
  routeWhileDragging: false,
  show: false
}).addTo(map);

另一个类似的答案:

无需创建新的 L.Routing.plan,因为 L.Routing.control() 接受 draggableWaypoints 选项,

let waypoints = [...]
L.Routing.control({
    waypoints: waypoints,
    draggableWaypoints : false,//to set draggable option to false
    addWaypoints : false //disable adding new waypoints to the existing path 
}).addTo(map);