Replaces missing Tiles (404 error) by scaled lower zoom Tiles
npm install leaflet.tilelayer.fallbackPlugin for Leaflet. Replaces missing Tiles (404 error) by scaled lower zoom Tiles.
Leaflet is the leading open-source JavaScript library
for mobile-friendly interactive maps.


Size: 2 kB minified, < 1 kB gzipped.
- Leaflet 1.x
- For Leaflet 0.7, use the v0.1.1 release or the leaflet-0.7 branch
HTML:
``html`
JavaScript:
`javascript`
var myTileLayer = L.tileLayer.fallback(url, options);
Now missing tiles will be automatically replaced by scaled up tiles from lower zoom levels.
#### Local copy
1. Download the "leaflet.tilelayer.fallback.js" file from the v1.0.4 release.
2. Place the file alongside your page.
3. Add the script tag (see Quick Guide > HTML) to your page after Leaflet script.
#### CDN
You can alternatively use the free unpkg CDN service, but keep in mind that it "_is a free, best-effort service and cannot provide any uptime or support guarantees_".
`html`
Simply use the L.tileLayer.fallback factory instead of your regular L.tileLayer:
`javascript
var myTileLayer = L.tileLayer.fallback(url, options);
myTileLayer.addTo(map);
`
| Factory | Description |
| :------ | :---------- |
| L.tileLayer.fallback( urlTemplate, options? ) | Instantiates a tile layer object given a URL template and optionally an options object. When tile images return a 404 error, they are replaced by a scaled up tile from lower zoom. |
| Option | Type | Default | Description |
| :----- | :--- | :------ | :---------- |
| minNativeZoom | Number | 0 | Minimum zoom number the tiles source has available. If tiles are missing down to that zoom level (included), they will be replaced by the standard Error Tile (specified by errorTileUrl). For zoom lower than minNativeZoom, standard Tile Layer behaviour applies, i.e. tiles are loaded from minNativeZoom and scaled down. |
All other TileLayer options are applicable.
| Event | Data | Description |
| :---- | :--- | :---------- |
| tilefallback | TileFallbackEvent | Fired when a tile is being replaced by a scaled up tile of lower zoom. |
All other TileLayer events are applicable.
#### TileFallbackEvent
| Property | Type | Description |
| :------- | :--- | :---------- |
| tile | HTMLElement | The tile element (image). |url
| | String | The original source URL of the tile (before any fallback is applied). |urlMissing
| | String | The missing source URL of the tile (possibly after a few fallback attempts). |urlFallback
| | String | The fallback source URL of the tile (which may turn out to be also missing). |
All regular TileLayer methods are applicable.
That means it has to wait for the server to return a 404 error before attempting
to replace the tile by a lower zoom equivalent. If several zoom levels are
missing, it has to wait as many times as the number of missing zooms. Therefore,
the more missing zoom levels, the more time it takes to replace a tile.
Leaflet.TileLayer.Fallback is distributed under the Apache 2.0 License.