Javascript 传单-启用/禁用控制

Javascript 传单-启用/禁用控制,javascript,leaflet,openstreetmap,Javascript,Leaflet,Openstreetmap,我想问你是否有办法禁用/启用 通过以下方式将控件添加到传单中: 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.c

我想问你是否有办法禁用/启用

通过以下方式将控件添加到传单中:

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);
var-map=L.map('map');
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png'{
属性:“©;贡献者”
}).addTo(地图);
路由控制({
航路点:[
L.latLng(57.74,11.94),
L.latLng(57.6792,11.949)
]
}).addTo(地图);

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

它看起来像
L.Routing.control
扩展了
L.Routing.inventary
的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();