question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

clearLayers throws an error: Cannot read property 'length' of null

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
aolszakcommented, Jun 7, 2018

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);

2reactions
TravnikovDevcommented, Apr 6, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found