【问题标题】:How to run OpenStreetMap offline in QML (Qt)如何在 QML (Qt) 中离线运行 OpenStreetMap
【发布时间】:2017-06-07 01:11:10
【问题描述】:

我在 Qt 上使用 QML 来显示 OpenStreetMap(使用 osm 插件),这需要互联网连接。 有没有办法我可以做同样的事情但离线运行它?例如,运行我自己的 tile 服务器(但这样做有多容易)?或者使用可以让我快速完成的库。

顺便说一下,我在 Ubuntu 上运行我的程序。

任何有关如何做到这一点的帮助,特别是如果有人可以提供要完成的步骤,我们将不胜感激。

谢谢。

【问题讨论】:

标签: c++ qt qml openstreetmap


【解决方案1】:

我已按照以下步骤在 Qt(使用 QML)中离线显示 OpenStreetMap:

  1. 在 localhost 上构建/运行磁贴服务器。我使用了以下指南:https://switch2osm.org/serving-tiles/building-a-tile-server-from-packages/
  2. 在 Qt 中的 map.qml 文件中,我必须在地图插件 (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. 最后,Map QML 类型的activeMapType 属性必须设置为MapType.CustomMap (http://doc.qt.io/qt-5/qml-qtlocation-maptype.html),地图才能与本地图块服务器一起使用。

【讨论】:

  • 您还可以通过设置 osm.mapping.providersrepository.address 将您自己的一组 json 提供程序定义与您的应用一起发布。与 qt 中的几乎所有内容一样,此地址可以是 http:// 以及 file:/// 甚至 qrc:/,因此您可以使用您的应用为每种地图类型发送自定义地址
猜你喜欢
  • 2012-05-03
  • 2012-07-01
  • 1970-01-01
  • 2015-05-21
  • 1970-01-01
  • 1970-01-01
  • 2014-07-08
  • 2019-08-26
  • 1970-01-01
相关资源
最近更新 更多