MazeMap / Leaflet.TileLayer.PouchDBCached

A Leaflet tile layer which caches into PouchDB for offline use
MIT License
208 stars 68 forks source link

Comparing this with downloading tiles in advance #40

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hi,

I had task to use leaflet offline. For this my approach was to download tiles in png format in following fashion: {atlas_name}/{z}/{x}/{y}.png and use leaflet like:

L.tileLayer('localfolder/atlasName/{z}/{x}/{y}.png', { maxZoom: 16 }).addTo(mymap);

But I have one problem with above approach, the size of tiles is too big. For example for geographic area I needed for zoom 14 the total size of tiles was 200MB.

My question is if I use TileLayer.PouchDBCached what advantages does it bring over above approach? does it use less space?


Also I assume when user uses this throughout time, the cache will store more and more tiles right? Is there a way to delete some entries in the cache? How long are they stored?

nikolauskrismer commented 5 years ago

How long tiles are cached depends on the cacheMaxAge parameter (defaults to 24h).

However, if you need smaller filesizes this plugin is not what you are looking for, since it just caches the tiles that you can also download by hand in png format. It does not reduce filesize.

Do you already know about vector tiles? Thats one good way I can think about when working offline and caring about filesizes....

ghost commented 5 years ago

@nikolauskrismer

How long tiles are cached depends on the cacheMaxAge parameter (defaults to 24h).

So after 24 hours they are deleted?

I managed to download a file of vector tiles, I also found this for displaying vector tiles, however it says: "L.VectorGrid.Protobuf for displaying vector tiles from an online tile server". I need to use it in offline mode however. Do you know of workaround for this limitation?

nikolauskrismer commented 5 years ago

Hmm... if they are deleted immediately after 24hours... you can not tell that for sure... I guess that it depends on the size of your browsers cache (and maybe on some additional factors). What you can tell for sure is that are re-requested from the server if you view them again after 24 hours

For additional information the OSM wiki on vector tiles might be a good starting point: https://wiki.openstreetmap.org/wiki/Vector_tiles

This question on gis.stackexchange also looks promising. It uses vector tiles downloaded from openmaptiles.org: https://gis.stackexchange.com/questions/254683/showing-offline-map-downloaded-from-openmaptiles-com-with-openlayers