ghybs / Leaflet.TileLayer.Fallback

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

Add fallbackURL #6

Closed MrSohey closed 5 years ago

MrSohey commented 6 years ago

Added a fallbackURL parameter : if no tiles are loaded on any zoomLevel >= minNativeZoom, then try again with another URL if provided. If both failed, then use original tileOnError option

ghybs commented 6 years ago

Hi,

Thank you for your PR!

Just for reference, this is a follow-up on https://github.com/Leaflet/Leaflet/issues/5810

When I test your code, it suddenly switches all tiles to the fallbackUrl, I do not know if that is the behaviour you are expecting? http://playground-leaflet.rhcloud.com/karot/1/edit?html,output

ghybs commented 6 years ago

Thinking about this functionality further, I see 3 points for improvement:

  1. Why having a single fallbackUrl option? we could have an array of URL templates, so that we can fallback to the next one should the current one be unavailable, and so on. Similar to how the fork seems to work.

  2. What about the attribution? it should be changed when another URL is used, possibly joining several attributions together. Pushing it further, there is no special reason the fallback Tile Layer uses the same options (tileSize, opacity, etc.). I do not know yet how we could combine a full different Tile Layer with its own options as fallback, unfortunately.

  3. That may not be relevant, but I can imagine a case where the developer wants to fallback to a different URL for a given tile as soon as the latter is missing, instead of trying first to get its lower zoom parent. Then if all fallback URL fail, try to get the lower zoom. That would make it closer to the fork. Maybe we could set up an option to switch the behaviour?

It seems to me that the attribution for point 2 is important.

What do you think?

MrSohey commented 6 years ago

I'm conflicted about your third impovement. I do believe you'd rather first switch to your fallback provider if you provided one, and if that new provider fail, then try to unzoom. As I have never used the unzooming your plugin provides, I am not entirely sure. It could be an option but if one option is better than the other in all use cases, it might not be useful.

Considering the two other points, we could change the fallbackUrl option from a string to an array of objects containing the URL and the options. I'll look into it, but sounds like a good idea !

MrSohey commented 6 years ago

Concerning your example, I'll need to dive into it but at first glance I would say the plugin is working as intended: You start at zoom 8 and the tile you can't load are replaced by lower zoom level tiles. By unzooming, you trigger the same pattern until you reach minNativeZoom. At this point you can't replace the tile with a lower zoom level tile, therefore you switch provider. I'd rather change the provider for all tiles for consistency and aesthetics. Maybe we can switch back to the default URL when the user move/zoom if tiles from the default provider are available again. But my initial goal was not to switch between providers. The default provider should provide tiles in almost every case. But if for any reason, the tile provider is not responding, even for 5 min, I want to have an instantaneous fallback to not alternate the user experience.

ghybs commented 6 years ago

Hi,

Thank you for the further details on what you would like to achieve.

If my understanding is correct, at first "tileerror" event you want to switch all the tiles to another provider, so that the map is consistent.

In that case, instead of using a plugin, why not just listening to that event, and change the Tile Layer when it fires? You could even delay the removal of the current Tile Layer (the one with some missing tiles) in order to avoid too much flickering, by listening to the "load" event of the replacement Tile Layer.

ghybs commented 5 years ago

Closing due to lack of activity.