jupyter-widgets / ipyleaflet

A Jupyter - Leaflet.js bridge
https://ipyleaflet.readthedocs.io
MIT License
1.48k stars 363 forks source link

Tiles cache #262

Open fitoprincipe opened 5 years ago

fitoprincipe commented 5 years ago

Hi, I'd like to know if tiles are downloaded into a cache folder. If not, is there any possibility to implement this? Thank you.

martinRenou commented 5 years ago

Hi, tiles are not downloaded to a cache folder. There are some plugins for LeafletJS that allows caching of tiles, like this one: https://github.com/MazeMap/Leaflet.TileLayer.PouchDBCached. Adding this feature to ipyleaflet should be easy using this plugin, but I start to be a little bit annoyed by the number of dependencies, and most of them are not maintained.

I suppose there is some caching already with the browser, but it does not last long.

fitoprincipe commented 5 years ago

I understand @martinRenou, thank you for your time.

martinRenou commented 5 years ago

Do you think that having the tiles in a folder and using something like a LocalTilesLayer in ipyleaflet, as discussed here would be enough for your use case? I guess you want caching for being able to use ipyleaflet without an internet connection, is that it?

fitoprincipe commented 5 years ago

I made a tool upon ipyleaflet to visualize tiles pulled from GEE (Google Earth Engine) (my tool: https://github.com/gee-community/gee_tools/blob/master/notebooks/ui/map_visualization.ipynb). I use it a lot myself, and that is why I am able to maintain it. If you sing up to GEE you can try it out.

Basically, using Google Earth Engine Python API I do some raster manipulation on their servers and they serve me the result as tiles (url), so every time I request a tile, their servers compute it and serve it (which may take long). Downloading the raster images would take much longer and would miss the point of "playing around" with GEE.

martinRenou commented 5 years ago

Ok I see :) I guess we can try adding the plugin for caching. It should not be too difficult.

fitoprincipe commented 5 years ago

That would be great! Thank you =)

martinRenou commented 5 years ago

I looked closer to Leaflet.PouchDBCached, it's not maintained anymore, apparently does not support the last version of LeafletJS and PouchDB. https://github.com/MazeMap/Leaflet.TileLayer.PouchDBCached/issues/38 On the other hand, it's not a lot of code, I guess it would not be that difficult to implement something similar.

fitoprincipe commented 5 years ago

Thanks for keeping this alive @martinRenou. May be if you guide me, I could help you, but that could be an extra effort for you, and whatever is your decision is fine to me. =)

martinRenou commented 5 years ago

Sure I can guide you :) I think the way to go would be to take a look at this file from Leaflet.TileLayer.PouchDBCached, and try to implement your own version that supports the last version of LeafletJS. I don't know if a dependency like PouchDB is essential. But to avoid duplication of effort I think it would be a good idea to answer to this issue first, I guess his code coulld be what we need :)