Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run OpenStreetMap offline in QML (Qt)

I am using QML on Qt to display OpenStreetMap (using the osm plugin), which requires internet connection. Is there a way that I can do the same but running it offline? For example, running my own tile server (but how easy is that to do)? Or using a library that will let me do it quite quickly.

By the way I am running my program on Ubuntu.

Any help on how to do that and especially if someone can provide the steps to be done would be appreciated.

Thank you.

like image 972
Soc Avatar asked Jan 22 '17 12:01

Soc


1 Answers

I have managed to display OpenStreetMap offline in Qt (using QML) following the steps below:

  1. Build/run a tile server on the localhost. I have used the following guide: https://switch2osm.org/serving-tiles/building-a-tile-server-from-packages/
  2. On my map.qml file in Qt, I had to include the following parameters on the map plugin (http://doc.qt.io/qt-5/location-plugin-osm.html):

    Plugin {
       id: osmMapPlugin
       name: "osm"
    
       //provide the address of the tile server to the plugin
       PluginParameter {
          name: "osm.mapping.custom.host"
          value: "http://localhost/osm/"
       }
    
       /*disable retrieval of the providers information from the remote repository. 
       If this parameter is not set to true (as shown here), then while offline, 
       network errors will be generated at run time*/
       PluginParameter {
          name: "osm.mapping.providersrepository.disabled"
          value: true
       }
    }
    
  3. Finally, the activeMapType property of the Map QML type has to be set to MapType.CustomMap (http://doc.qt.io/qt-5/qml-qtlocation-maptype.html) for the map to work with the local tile server.

like image 83
Soc Avatar answered Nov 15 '22 06:11

Soc