Leaflet throwing "Cannot read property 'max' of undefined" when adding a populated group layer to a map
See original GitHub issueBasically, 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:
- Created 8 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
@fplgusmao Faced the same problem, solution:
call when reinitialization.
@LookinGit thanks a lot! it worked for me!