Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

leaflet - tile loading - error event

Tags:

leaflet

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 &copy; <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);
like image 499
R.W Avatar asked Jun 21 '14 14:06

R.W


1 Answers

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 ?

like image 159
YaFred Avatar answered Sep 28 '22 06:09

YaFred