[GIS] local tiles server for offline access

cachejavascriptopenlayers-2tilecachetiles

Anyone knows if there is a "lightway" solution to mount a local tile server?

Feature I'd to provide is local storage of small sections of maps, not more than small city for example, in order to provide some degree of offline maps navigation by pointing javascript functions to the local server when network is not accessible.

Best Answer

If you are using QGIS, you could utilise the OpenLayers plugin. Progams such as Mapertive can download tiles from OpenStreetMap, using the generate-tiles method. Other programs may be available for other sources. Mapertive exports the images into the 'Tiles' subfolder.

Once you have the tiles downloaded, make a copy of one of the files in the qgis\python\plugins\openlayers_plugin\html folder, except modify the statement which creates a layer.

In this example I am using MS Windows, and OpenStreetMap. I would replace

   var osm = new OpenLayers.Layer.OSM(
          "OpenStreetMap",
          "http://tile.openstreetmap.org/${z}/${x}/${y}.png",

with:

var osm = new OpenLayers.Layer.OSM(
              "OpenStreetMap",
              "C:/Path-to/Maperitive-latest/Maperitive/Tiles/${z}/${x}/${y}.png",

I saved this file as qgis\python\plugins\openlayers_plugin\html\osm_local.html

Last thing to do is modify the openlayers_plugin.py file, by registering the new html file.

# Layers
self.olLayerTypeRegistry = OlLayerTypeRegistry()

# Add this
self.olLayerTypeRegistry.add( OlLayerType(self, 'OpenStreetMap (Cache)', 'osm_icon.png', 'osm_local.html', True) )

After restarting QGIS, you will have a new option in the OpenLayers menu

enter image description here