Is there an offline Map layer available for Leaflet?

懵懂的女人 提交于 2019-12-22 06:55:53

问题


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


回答1:


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.




回答2:


You can build your own local osm server. It is quite easy using Ubuntu, because there is special packages for it. Installation process is described on this great resource: switch2osm.org




回答3:


Here is an example using NeDB and modifications to this project/examples https://github.com/tbicr/OfflineMap: https://github.com/KD0NKS/APRSViewJS/blob/master/js/techpire/LayerManager.js. This only caches what the user has already viewed and avoids bulk downloading from osm servers.

There is also a Leaflet Plugin: https://github.com/MazeMap/Leaflet.TileLayer.PouchDBCached



来源:https://stackoverflow.com/questions/34408079/is-there-an-offline-map-layer-available-for-leaflet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!