Leaflet.draw
Leaflet.draw copied to clipboard
clearLayers throws an error: Cannot read property 'length' of null
When calling LayerGroup#clearLayers
, an exception is thrown on this line:
https://github.com/Leaflet/Leaflet.draw/blob/c6af99b761c5d9900bf5a3e2e1d8827bbde29542/src/edit/handler/Edit.SimpleShape.js#L66
Error:
TypeError: Cannot read property 'length' of null
at NewClass.removeHooks (leaflet.draw-src.js:2379)
at NewClass.eval (leaflet.draw-src.js:2795)
at NewClass.fire (leaflet-src.js:593)
at NewClass.removeLayer (leaflet-src.js:6573)
at NewClass.removeLayer (leaflet-src.js:6715)
at NewClass.removeLayer (leaflet-src.js:6861)
at NewClass.eachLayer (leaflet-src.js:6774)
at NewClass.clearLayers (leaflet-src.js:6735)
Can you check first for null, before iterating the _resizeMarkers
, please?
Environment:
leaflet: 1.3.1
leaflet-draw: 1.0.2
Thanks!
I have changed the source code and another error appears, mentioning that the this._map
is null.
The fix consists in replacing this line with: if (shape._map && this._map)
.
I can confirm that critical bug. It seems like removeHooks() is being called two times and the second time it just can't find the previously removed stuff anymore. CircleMarker and and Circle both register the same listener on remove. I guess that is the reason.
Sorry for promotion but:
As leaflet.draw development seemed to came to a halt
I recommend to use new plugin leaflet.pm In our project it was best choice
I created a second pull request regarding this issue, I think @cazacugmihai solution is more a workaround than a bugfix. RemoveHooks should be called only once (i guess). https://github.com/Leaflet/Leaflet.draw/pull/853
@eisverticker: I've tested your fix and it works. I'll delete my PR. Thank you!
I had same error during adding/removing shapes.
I've fixed the error by disabling editing mode before removing the layer.
layer.editing.disable(); that.drawGroup.removeLayer(layer);
I have the same problem. Will have any solution for this? @aolszak your tip works, thanks!
doesn't work still :(
used the if (shape._map && this._map)
solution