Eric
Eric

Reputation: 18922

Leaflet clears tile cache on zoom

I'm experiencing a issue with the tiles cache in leaflet. If I start at point A, pan to point B, and then look at the tiles inbetween; they are cached and such. No problem.

But if i pan from A to B, zoom in, and zoom out, and pan back to A, the tiles are cleared! By other words, the cached tiles seems to be cleared when altering the zoom-levels.

Is this a common behaviour, and can it be prevented? i.e. can I force leaflet to keep ALL loaded tiles in memory? I have tried playing around with the various options for the map and layers, without success. The option unloadInvisibleTiles is false by default, which implies that tiles are kept in memory..

I'm trying to create some sort of navigation on a map, where you can pan, zoom, back and forth. Therefore I need all the loaded tiles to be kept in memory, for a smooth experience.

Thank you in advance.

Upvotes: 2

Views: 1698

Answers (1)

Eric
Eric

Reputation: 18922

I found a solution to this "problem" actually.

I ended up modifying the source-code to Leaflet (thank you for Open Source), in such a way that the engine creates a leaflet-layer container for each layer. Instead of clearing the bgBuffer and foreground all the time.

And then when it zooms out, it positions the target layer behind the current active one. What this does, is that it covers all the gray area around the current one. And thus, creating the illusion that the tiles "outside" the viewport are actually loaded.

This might be a dodgy description of how I made it. But the idea is simple; just keep all the layers, and position the target layer behind the current one when zooming out.

Upvotes: 3

Related Questions