I am using leaflet which displays offline tiles that have been created using maperitive. Everything works just fine but does anyone know how to trigger the error event in case the requested tile does not exist? In case the requested tile cannot be loaded, you can specify a default tile.
var myLayer = new L.TileLayer(..., {errorTileUrl: '/path/to/default/tile.png'});
which actually sets the default tile if there is an error loading the requested tile. But this is not exactly what I need. I need it to fire an event.
The leaflet code itself is pretty simple.
L.tileLayer('http://{s}.tiles.mapbox.com/v3/MapID/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 18
}).addTo(map);
myLayer.on('tileerror', function(error, tile) {
console.log(error);
console.log(tile);
});
Ref: https://github.com/Leaflet/Leaflet/blob/v0.7.3/src/layer/tile/TileLayer.js#L581
Does it help ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With