Leaflet: Setting map center to L.LatLng(Infinity, Infinity) causes infinite loop

How to reproduce

  • Leaflet version I’m using: master, 1.0.3
  • Browser (with version) I’m using: Chrome, Firefox (latest versions)
  • OS/Platform (with version) I’m using: Windows 8.1

What behavior I’m expecting and which behavior I’m seeing

I 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.

Minimal example reproducing the issue

Beware, this will freeze your browser Example - http://playground-leaflet.rhcloud.com/qem/edit?html,output

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (13 by maintainers)

Most upvoted comments

@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 😝😝😝

Hi! I had the same problem like u guys Uncaught Error: Attempted to load an infinite number of tiles when using proj4leaflet js.

@IvanSanchez Damn, I have to choose my expectations more wisely next time.

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.

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!