How can I remove the \"clear all\" action from the delete button in the leaflet-draw edit toolbar?
I know you can remove the whole delete button but still need to re
The edit toolbar tests the existence of a removeAllLayers
member on the button handler. So, a simple but probably heavy handed way to disable the clear all action is to nuke removeAllLayers
on the L.EditToolbar.Delete
module:
L.EditToolbar.Delete.include({
removeAllLayers: false
});
new L.Control.Draw({
edit: {
featureGroup: drawnItems
},
draw: {
}
}).addTo(map);
And a demo
var map = L.map(document.getElementById('map'), {zoomControl: false}).setView([48.8583736, 2.2922926], 15);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
var drawnItems = new L.geoJson().addTo(map);
map.on(L.Draw.Event.CREATED, function (event) {
var layer = event.layer;
drawnItems.addLayer(layer);
});
L.EditToolbar.Delete.include({
removeAllLayers: false
});
new L.Control.Draw({
edit: {
featureGroup: drawnItems
},
draw: {
polygon: false,
rectangle: false,
circlemarker: false
}
}).addTo(map);
html, body {
height: 100%;
margin: 0;
}
#map {
width: 100%;
height: 100%;
}