Leaflet - 启用/禁用控件

时间:2014-10-14 16:06:04

标签: javascript leaflet openstreetmap

我想问你是否有某种方法可以禁用/启用routing plugin

以这种方式将控件添加到传单中:

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);

有人知道如何动态禁用/启用此控件吗?

1 个答案:

答案 0 :(得分:2)

看起来L.Routing.Control扩展了L.Routing.Itinerary implements show()和hide()方法。所以你应该能够做到这样的事情:

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

//.. Some other code ..

if(hide)
   routeControl.hide();
else
   routeControl.show();