Preload Leaflet nearby tiles

Asked by At

I am using Leaflet as my map component. When the map initially loads, I want to preload nearby tiles at the same zoom level. What is the best solution to do this?

2 Answers

1
ghybs On Best Solutions

Use Leaflet Grid/Tile Layer option keepBuffer:

When panning the map, keep this many rows and columns of tiles before unloading them.

1
IvanSanchez On

Please note that the keepBuffer option of L.GridLayer (and L.TileLayer) affects how tiles are unloaded: A bigger value of keepBuffer means that the user has to pan around further away before tiles are unloaded. It does not affect how soon tiles are loaded.

If you want to preload nearby tiles, I encourage you to look at some of the plugins, and in particular Leaflet.EdgeBuffer.