clearLayers throws an error: Cannot read property 'length' of null
See original GitHub issueWhen 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!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Cannot read property 'length' of null, javascript. Check if ...
The error means that you're trying to access the .length property of something without first determining that the something is not null ....
Read more >Cannot read property "length" from null
I have written a script to find some specific content from all HTML fields from knowledge articles but getting below error when there...
Read more >Cannot Read Property Length of Undefined in JavaScript
The JavaScript TypeError: Cannot read property 'length' of undefined occurs when the length property is read on an undefined variable.
Read more >Cannot Read Property 'Length' Of Undefined On Leafletjs
Getting Uncaught Typeerror: Cannot Read Property 'Length' Of Undefined On ... When calling LayerGroup#clearLayers an exception is thrown on this line: ...
Read more >[Solved] TypeError: Cannot read property 'length' of null
The TypeError: Cannot read property 'length' of null occurs if you are trying find the length of an object on a null value...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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);
Sorry for promotion but:
I recommend to use new plugin leaflet.pm In our project it was best choice