Search code examples
javascriptleafletopenstreetmap

Leaflet Offline Map: How to store a map for offline usage?


I want to save an OSM map with specific boundaries for offline usage in my file system without any DB outside of the web browser. After that I want to render the map with Leaflet library while offline. Is that possible?


Solution

  • I suspect this may be an XY problem, where saving tiles in cache of the web browser from an external provider sounds like only one of many possible solutions for the initial objective of offline usage, and not having to use (or actually not to install?) a database on client side.

    If that is the case, @IvanSanchez's Leaflet.TileLayer.MBTiles plugin could fit the bill: while the mbtiles file is technically a database, it is contained in a single portable file without requiring installation (it is an SQLite file).

    The size could be over a browser cache, but if you have some control on the client, you can just copy it on file system. Then you can have your HTML page opened from file system as well, or a local server, which would also be more inline with offline usage.