Is there an event (or other method) to detect when all visible tiles have been downloaded and displayed with leaflet? (Similar to Google Maps event that is called when all visible map tiles are loaded, but for leaflet instead)
Asked
Active
Viewed 2.0k times
26

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

Forest Katsch
- 1,485
- 2
- 15
- 26
-
What about http://leafletjs.com/reference-1.2.0.html#map-whenready? – Christian Martinez Jan 05 '18 at 17:48
2 Answers
40
Solved. Bind the "load" event on the tile layer. Example:
var tile_layer=L.tileLayer(tile_url,{
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>.",
maxZoom: 18
});
tile_layer.addTo(map);
tile_layer.on("load",function() { console.log("all visible tiles have been loaded") });

Forest Katsch
- 1,485
- 2
- 15
- 26
-
Very useful, thanks. Some answers elsewhere mention adding the 'load' listener at the map level but it fires almost immediately. – AlexG Jan 27 '21 at 10:00
27
The list of TileLayer events according to the leaflet documentation:
loading Event - Fired when the tile layer starts loading tiles.
load Event - Fired when the tile layer loaded all visible tiles.
tileloadstart TileEvent - Fired when a tile is requested and starts loading.
tileload TileEvent - Fired when a tile loads.
tileunload TileEvent - Fired when a tile is removed (e.g. when you have unloadInvisibleTiles on).

Matt Hampel
- 5,088
- 12
- 52
- 78

NXT
- 1,981
- 1
- 24
- 30
-
2For a full list of map events, see http://leafletjs.com/reference.html#map-events. – Erik Vullings Dec 04 '15 at 15:20