I'm using Leaflet, and using OSM's tile.openstreetmap.org tile server. However, sometimes my application does not load the maps tiles. It seems OSM's servers are having some problems sporadically, which is out of my scope of fixing. So, my question:
Is it possible to wait an X amount of time for the tile server to load the requested tiles, before trying to contact another URL for its tiles?
Best Answer
I don't think Leaflet supports this out of the box. However, I think you can implement such a behavior using events such as
tileloadstart
andtileload
: http://leafletjs.com/reference.html#tilelayer-tileloadstartFor example, you could start counting time the first time a
tileloadstart
is fired usingsetTimeout
, and cancel it (usingclearTimeout
) once atileload
is fired. If nobody cancels thesetTimeout
, swap the base OSM layer for another one.