How to run OpenStreetMap offline in QML (Qt)

怎甘沉沦 提交于 2021-02-18 11:42:19

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/41790875/how-to-run-openstreetmap-offline-in-qml-qt

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