How can I detect whether a map is loading properly or not? What happened was that in my ionic app the map url stopped to work, and the map did not throw an error. It only displayed gray.
Is there a way to check for this event properly and fall back to an alternative map?
I may be late in answering to this but, here are the layer events which you can make use of. This event is triggered on the layer and not on the map. In this case, if the
bingLayer
fails to load,tileerror
will get triggered.Experienced same of recent. Found the reason here Tile Usage Policy.
Use other tile layers that uses osm to render map. Had to use this for map images to show on mobile
In a nutshell osm blocked the map tiles.
A usual but simplistic workaround is to specify a single fallback tile, using the errorTileUrl option of your tileLayer. Typically it shows a light red cross to let the user know the map server does not have any image to provide for that area and that zoom.
Now if you want to be smarter and fallback to a different map (i.e. redirect to a different URL), I am not aware of any out-of-the box solution, but it is very well do-able. The idea is to override the
_tileOnError
method of theL.TileLayer
class, which normally replaces the tile by the one fromerrorTileUrl
when it receives a 404 error (i.e. no tile available on the server). In the given link, it automatically replaces the URL by a new one for a different location (could be a different server), as it expects only a few tiles to be missing.Now if you assume the whole server would stop responding and you want to switch over to a different tileLayer (so that it stops pinging the faulty server), you could implement for example a simple counter that is incremented by the
_tileOnError
method, and once a given threshold is reached, switch the layers.