protomaps / PMTiles

Cloud-optimized + compressed single-file tile archives for vector and raster maps
https://protomaps.com/docs/pmtiles/
BSD 3-Clause "New" or "Revised" License
2.11k stars 125 forks source link

Saving/Caching for offline use? #395

Closed bpevs closed 7 months ago

bpevs commented 7 months ago

I am currently happily using protomaps with maplibregl for maps on the web!

I haven't seen any mention of offline use, so I'm wondering if this use-case has been considered at some point? One of the benefits of the workflow of previous tile-based systems has been that I could actually download and cache the whole tile of an area, and have that usable offline.

However, for Protomaps, I'm currently just using one giant full-planet file. Clearly an end-user wouldn't want to download that huge file! Is the recommended solution just to make a bunch of pmtiles for different areas, and add multiple sources to the maplibregl? Or is there a way to actually cache/extract/save smaller areas from a full-planet file?

edit: oh I just realized Github Discussions exists; can move this there if you'd like, since this is more a question than an issue...

vinnyglennon commented 7 months ago

@bpevs Hi, https://gist.github.com/vinnyglennon/bb925d280741429bce4e9af2535140b2 I have been looking to save a pmtiles to indexeddb, using leaflet for display. I get an error when I retrieve it from indexeddb "Unimplemented type: 4 error".

bpevs commented 7 months ago

this gist is storing a full pmtiles file though, no? I guess my question is more about what to do if I want to cache only the used sections of a pmtiles file; or if that's impossible and I should just have extractions for every location that I want to be offline-accessible (I'd assume in this way: https://github.com/protomaps/PMTiles/issues/6)

bdon commented 7 months ago

Yes, pmtiles extract exists for this reason for getting small areas: https://docs.protomaps.com/guide/getting-started#_3-extract-any-area

Though what you're describing will require some storage mechanism that is platform-specific. It might be IndexedDB or service workers on browsers or it might be SQLite on mobile devices. These are outside of the scope of the encoding/decoding libraries in this repository, but it would be very useful to have a third-party library that accomplishes this for popular platforms.

bpevs commented 7 months ago

pmtiles extract is not meant to be run by the consumer app, though, right? So I'll probably need to do extraction separately from the app, make those downloadable, and then load those multiple downloaded pmtiles in the maplibre instance?

Re actual tile storage, thanks for the info! Although in my case, I'm not really working on anything for that, since I'm building a tauri app that has full access to fs.

bdon commented 7 months ago

There isn't a technical constraint here, the consumer could extract a region of tiles like pmtiles extract, but I don't believe an implementation of the extract algorithm exists outside of the Go one.

bpevs commented 7 months ago

Cool got it! Thanks for the info! I'll make a discussion instead of an issue next time, now that I realize it's there :+1: