master, 1.0.3I expect that passing Infinity in to the L.LatLng constructor like this new L.LatLng(Infinity, Infinity); would throw an error. Instead this is allowed and is causing the browser to freeze when adding a tile layer, for example.
Beware, this will freeze your browser
Example - http://playground-leaflet.rhcloud.com/qem/edit?html,output
The problem, as far as I can see, lies within the L.GridLayer logic for the tile bounds. The for (var i = tileRange.min.x; i <= tileRange.max.x; i++) { loop in L.GridLayer._update is trying to loop from Infinity to Infinity (since those are the values of tileRange.min.x and tileRange.max.x).
So the problem is not instantiating a L.LatLng with infinite numbers, is creating a map, setting the map center's easting coordinate to Infinity, and adding one tile layer to that map.
I see, okay, then we should blame the L.GridLayer.
Yep, great. On the other hand though - should the L.LatLng be initiated using infinite numbers?
I think that L.LatLngs should be allowed to have Infinity coordinates. We, in fact, use stuff like that for the maxBounds option of the map.
Okay, I see, thanks for the explanation. ;)
Looks like this is fixed in #5479
My example does not freeze the browser any more
@IvanSanchez However, looks like I found another issue after the merge.
This is the same example, but with the Console part open - http://playground-leaflet.rhcloud.com/qem/edit?html,console,output
The map loads up and if you do a drag on the map the Console will continuously fill up with the newly added error Attempted to load an infinite number of tiles.
@theashyster Hey, you wanted Leaflet to throw an error instead of getting stuck in an infinite loop, and you got errors instead of infinite loops, don't complain now 馃槤馃槤馃槤
@IvanSanchez Damn, I have to choose my expectations more wisely next time.
@IvanSanchez Is this implementation going to stay the way it is with the error thrown continuously?
What would be the alternative? I can't see a good one right now :-|
I played with the example a bit and looks like the error is thrown in an infinite loop basically when you do a drag and release that causes the inertia to kick in. In other words when I changed the example a bit and added inertia: false to the map options I was not able to reproduce the infinite loop of errors. Maybe that helps in finding some ways to prevent this?
Hi!
I had the same problem like u guys
Uncaught Error: Attempted to load an infinite number of tiles
when using proj4leaflet js.
I just added masu.map.zoomIn to my code and console.log says "Error: Attempted to load an infinite number of tiles"
I have confirmed that I am providing a legit latlng.
I will investigate more and then hopefully I can make a more useful post.
Edit: Adding animate: false made no difference
More info: I am using leaflet 1.3.4, windows 10 and current versions of Firefox and Chrome.
I tried setting map options to animate: false
but that did not help.
Can you publish a fiddle/codepen/plunkr that displays this behaviour? I mean, something that reproduces the issue while providing a non-infinite latlng.
Greater Seattle area was hit today with the second windstorm in less than a week. Assuming the power is on in the morning I will see if I can produce a short demo.
Mark my comment down to 'user error'. I am a reformed Google map API dev still coming up to speed on Leaflet.
Also, I mis-spoke. Actually I was using the event setZoomAround and failed to use the correct syntax. I also failed to notice that the Leaflet API will automatically zoom in on a spot that is double-clicked. My attempt to code that feature myself is what led me down this path of confusion.
All is good now.
And the power is on.
Thanks to all the mighty minds that have made Leaflet so great!
I think the current approach (throw an error from #6416) is the right one - no better ones have been suggested :-|
Most helpful comment
@theashyster Hey, you wanted Leaflet to throw an error instead of getting stuck in an infinite loop, and you got errors instead of infinite loops, don't complain now 馃槤馃槤馃槤