ghybs / Leaflet.TileLayer.Fallback

Replaces missing Tiles by scaled lower zoom Tiles
Apache License 2.0
36 stars 18 forks source link

Do an explicit undefined check on fallback zoom #10

Closed alexthemark closed 6 years ago

alexthemark commented 6 years ago

Hey @ghybs ,

Thanks for the awesome tile fallback library!

I was playing around when my tile server started erroring out, and I think there's a bug when minNativeZoom is set to zero, and leaflet fails to fetch any tiles.

If minNativeZoom is set to zero and you can't receive any tiles from your tile source you'll enter this loop:

fallbackZoom reaches 1 tile._fallbackZoom becomes 0 0 is not less than 0, so fallbackZoom < layer.options.minNativeZoom is false, and we don't return the error tile.

... so we request a tile and loop around

tile._fallbackZoom is 0, which is falsy, so we set tile._fallbackZoom to originalCoords.z -1. We begin our loop again.

By checking for an explicit undefined value, we won't hit that loop -- tile._fallbackZoom will be set to -1, it will be less than zero, and we'll set the error tile.

ghybs commented 6 years ago

Hi,

Thank you for submitting your PR!

Nice catch!

alexthemark commented 6 years ago

Thanks for merging! would you mind releasing a patch release?

ghybs commented 6 years ago

Hi,

Shipped in v1.0.4