Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an offline Map layer available for Leaflet?

Tags:

maps

leaflet

Is there an offline Map layer available for Leaflet? I don't need in detail, but basic geometry would be sufficient.

like image 794
Kenny Powers Avatar asked Dec 22 '15 03:12

Kenny Powers


People also ask

Can leaflet be used offline?

This library can be used to create maps, which are still available when you are offline and are fast when your connection is not. It works in the browser or can be used in an mobile app based on html and in progressive webapps.

Does leaflet use OpenStreetMap?

The Leaflet JavaScript. Our initial JavaScript is pretty straightforward. All we are doing here is creating the map and adding a tile layer. The tile images are coming from the OpenStreetMap servers which are good for testing.

Can I use Google Maps on my leaflet?

Using the leaflet, we can render the map into an HTML element and we can set the marker on the map. Leaflet works efficiently across all major desktop and mobile platforms.


1 Answers

For sure you can set up your own offline map (raster tiles and/or vector shapes). The difficulty or out-of-the-box availability depends on what kind of information and level of details you want.

GeoJSON:

The easiest is if you need just world countries borders with little detail, just to get the outline. In that case, you can find GeoJSON files on Internet that contain that data for a few hundreds kB (the weight of a single normal big image), e.g. https://github.com/johan/world.geo.json

Then simply use L.geoJson(geoJsonData).addTo(map) to have it shown.

Demo: http://plnkr.co/edit/aB6p7IC2cF7xW41Ju8m7?p=preview

Downloaded tiles:

A more complex (technically and contractually) but still manageable situation is if you want raster tiles (like the OSM website for example). You can download tiles (which are just normal images) from an online server, then use them offline. This is called "tiles scraping" or "tiles bulk downloading".

As for the technical side (you may have to download thousands of individual images, depending on to which zoom level / details you want to use offline), several software are available (have a look at the above OSM Wiki link).

As for the contractual side, many tile servers (including OSM for instance) specifically require in their Terms of Use not to perform bulk downloading (as it generates high demand and uses high bandwidth on their servers). So you should look for a service that accepts this usage.

Render tiles locally:

A perfectly authorized solution (but the most technically complex) is to download the raw OSM data, and to use it through software to generate your map (whether raster tiles or vector shapes).

You can probably find services on Internet that offer to download simplified OSM data (the full database for the entire planet is ~30 GB compressed…) or for a small geographic area (see the above OSM Wiki link).

Regarding the software, the link provided by chrki in the question comment (http://wiki.openstreetmap.org/wiki/Rendering) should get you started.

In particular, you can very well generate raster tiles once, save them and get rid of the rendering software, so you can use those tiles as if you had scraped them.

like image 121
ghybs Avatar answered Jan 04 '23 05:01

ghybs