【问题标题】:Setting up Qt Location to query from a local osm server设置 Qt Location 以从本地 osm 服务器查询
【发布时间】:2017-12-21 12:30:04
【问题描述】:

我已成功设置本地 OSM 服务器,并希望将其用作我的应用程序的 tile 提供程序。但是,我面临一些难以使 Qt Location 应用程序连接到本地服务器的问题。以下代码是一个简单的 QML 应用程序,它使用本地服务器地址配置“osm.mapping.host”插件的属性。我注意到插件忽略了配置并从 MapQuest 检索图块。

我想知道是否有人将 OSM 插件连接到与默认服务器不同的服务器上?

    Window {
    visible: true

    Plugin {
        id: mapPlugin
        name: "osm"

        PluginParameter { name: "osm.useragent"; value: "map" }
        PluginParameter { name: "osm.mapping.host"; value: "http://127.0.0.1/osm_tiles/" }
        PluginParameter { name: "osm.mapping.copyright"; value: "All mine" }
    }

    Map {
        id: map

        plugin: mapPlugin
        anchors.fill: parent

        center {
            latitude: -23.5475
            longitude: -46.636110
        }

        zoomLevel: 10
        gesture.enabled: true
    }
  }

【问题讨论】:

    标签: qt geolocation qml


    【解决方案1】:

    我刚刚发现,为了强制 OSM 地图插件从本地服务器检索图块,必须确保地图的属性 activeMapType 设置为等于 MapType.CustomType。 Qt Location OSM Plugin 的文档对此并不清楚。以下代码对我有用。

    Window {
        visible: true
    
        width: 800
        height: 600
    
        Plugin {
            id: mapPlugin
            name: "osm"
    
            PluginParameter { name: "osm.mapping.host"; value: "http://127.0.0.1/osm_tiles/" }
    
        }
    
        Map {
            id: map
    
            anchors.fill: parent
    
            center {
                latitude: -23.5475
                longitude: -46.636110
            }
    
            zoomLevel: 10
    
            gesture.enabled: true
    
            plugin: mapPlugin
    
            //Make sure to set activeMapType equal to MapType.CustomType
            activeMapType: supportedMapTypes[7]
        }
    }
    

    【讨论】:

      【解决方案2】:

      不要假设“7”是索引自定义地图类型的幻数,而是在自定义地图类型始终是列表中的最后一个的基础上使用以下内容

      activeMapType: supportedMapTypes[supportedMapTypes.length - 1]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-07
        • 2017-09-18
        • 2019-09-18
        相关资源
        最近更新 更多