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.

Leaflet throwing "Cannot read property 'max' of undefined" when adding a populated group layer to a map

See original GitHub issue

Basically, I’m making an app that, among other things, lets users insert L.Circle’s on a group layer on top of a map. Then, it saves the layers of that group layer – they are all Leaflet circles – in a variable located under an AngularJS Service. It then needs to load (add) them again into another group layer, which in turn will be added to a map. I add each of them to the group layer using groupLayer.addLayer. When I add that group layer into a map, using map.addLayer(groupLayer), Leaflet throws:

Cannot read property 'max' of undefined

The call stack:

Cannot read property 'max' of undefined
    at L.Circle.L.Path.extend._checkIfEmpty (http://.../leaflet-src.js:5918:22)
    at L.Circle.L.Path.extend.getPathString (http://.../leaflet-src.js:5881:12)
    at L.Path.L.Path.extend._updatePath (http://.../leaflet-src.js:4682:18)
    at L.Path.L.Class.extend.onAdd (http://.../leaflet-src.js:4503:8)
    at L.Map.L.Class.extend._layerAdd (http://.../leaflet-src.js:2225:9)
    at L.Map.L.Class.extend.addLayer (http://.../leaflet-src.js:1683:9)
    at L.LayerGroup.L.Class.extend.eachLayer (http://.../leaflet-src.js:4322:11)
    at L.LayerGroup.L.Class.extend.onAdd (http://.../leaflet-src.js:4307:8)
    at L.Map.L.Class.extend._layerAdd (http://.../leaflet-src.js:2225:9)
    at L.Map.L.Class.extend.addLayer (http://.../leaflet-src.js:1683:9)

From what I understood, this is related to Leaflet not managing to render the circles… But why is this happening? I made a plunker (updated), trying to show what I am doing in my app. However, in the plunker everything is working fine. It may still be useful by kinda showing what steps I’m taking, and what I’m trying to do. In my app things are structured a little differently, and I don’t know if I can make a simple plunker like it. Do you think it can be related to how my code is structured? Anyway, if needed, I can try to explain how things work in detail.

[UPDATE] as @IvanSanchez said, it is a 0.7.x problem. I changed the leaflet version in the plunker and now the described problem is happening. You can now mess with it, and check the console error.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
LookinGitcommented, Jun 22, 2016

@fplgusmao Faced the same problem, solution:

var Map = L.map('#map', {});
Map._initPathRoot();
Map._updatePathViewport();

call when reinitialization.

0reactions
fplgusmaocommented, Jun 22, 2016

@LookinGit thanks a lot! it worked for me!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property 'addLayer' of ...
I am getting my data from a geoJson file. I keep getting this error "Uncaught TypeError: Cannot read property 'addLayer' of undefined" leaflet- ......
Read more >
FeatureLayer | API Reference - ArcGIS Developers
Name Type Class apiKey String FeatureLayer blendMode String FeatureLayer capabilities Object FeatureLayer
Read more >
WMS layer option with Gemini VA WMS Server on Leaflet
I tried that but it throw me an error "Uncaught TypeError: Cannot read property 'wms' of undefined". In QGIS the first line is...
Read more >
Uncaught TypeError: Cannot read property of null - iDiallo
For example, document.getElementById('stuff') returns null. So adding .value will cause the error. You are trying to access a DOM element before ...
Read more >
Maps JavaScript API | Google Developers
Sets the viewport to contain the given bounds. Note: When the map is set to display: none , the fitBounds function reads the...
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