Leaflet.draw
Leaflet.draw copied to clipboard
Stop edit mode
How can I stop the edit mode manually? There is a way to do that? If there is, I did not found it.
Thanks!
If you don't have the toolbar, you should be able to disable() the polygon.
var polygonSelection = new L.FeatureGroup();
// Add to leaflet...
var currentDrawer = new L.Draw.Rectangle(leaflet, shapeParameters);
// Create... edit...
polygonSelection.clearLayers(); // Removes layers completely
if (currentDrawer != null) {
currentDrawer.disable();
currentDrawer = null;
}
Sorry, maybe I did not explained well.
There is a situation like this :
- User click in the edit icon in the toolbar(i.e., he enters in the edit mode).
- My application pops up a modal.
- The user close the modal without selecting any operation.
In this situation I want to stop the edit mode when the user closes the modal without selecting any operation. So I have a toolbar and an icon to edit. But I want something like this :
drawControl.edit.stop();
@Greenbald Would you happen to have a jsfiddle I could take a look at?
Try this;
for (var toolbarId in map.drawControl._toolbars) {
if (map.drawControl._toolbars.hasOwnProperty(toolbarId) && map.drawControl._toolbars[toolbarId] instanceof L.EditToolbar) {
map.drawControl._toolbars[toolbarId].disable();
}
}
Hi @sstenn , how do you access drawControl from map, I can't find it in the object.
Here is my config :
"leaflet": "^1.5.1", "leaflet-draw": "^1.0.3",
Here's my code :
var drawControls = new L.Control.Draw( { my draw options } );
map.addControl(drawControls);
I actually can find elements in the drawControls object directly but when I apply your code in mine, I get this error and I suppose it is because i'm not working with the map.
app.js:55974 Uncaught TypeError: Cannot read property 'disable' of undefined
at NewClass.removeHooks (app.js:55974)
at NewClass.disable (app.js:8014)
at NewClass._disableLayerEdit (app.js:55975)
at NewClass.eachLayer (app.js:9152)
at NewClass.removeHooks (app.js:55975)
at NewClass.disable (app.js:8014)
at NewClass.disable (app.js:55975)
at NewClass.removeToolbar (app.js:55975)
at NewClass.removeToolbar (app.js:55975)
at NewClass.onRemove (app.js:55975)
If I follow your solution, I can't find the drawControl object in my map object.
Hi @Itemshopp
Try to add the drawControl like this:
map.drawControl = new L.Control.Draw( { my draw options } )
map.addControl(map.drawControls);
Thanks for your answer. It worked but the problem still persists.
The problem I get comes like this :
I draw a marker. I click on the edit button, I then click on another button that will call this function :
disableDrawControls(map)
{
Object.values(map.drawControls._toolbars.edit._modes).forEach( (mode) =>
{
if(mode.handler.enabled())
{
mode.handler.revertLayers();
mode.handler.disable();
}
});
map.removeControl(this.drawControls);
}
I then get this error :
app.js:55974 Uncaught TypeError: Cannot read property 'disable' of undefined
at NewClass.removeHooks (app.js:55974)
at NewClass.disable (app.js:8014)
at NewClass._disableLayerEdit (app.js:55975)
at NewClass.eachLayer (app.js:9152)
at NewClass.removeHooks (app.js:55975)
at NewClass.disable (app.js:8014)
at NewClass.disable (app.js:55975)
at app.js:89531
at Array.forEach (<anonymous>)
at DrawManager.disableDrawControls (app.js:89526)
Et when I go deeper in the error, it says the marker.dragging.disable() function can't be called because the dragging option doesn't exist.
Is there any error in my code ?
It is linked with this PR Remove marker.dragging when not on the map