我正在使用 OSM 和这里的 QML 应用程序的地图插件。我map.activeMapType = map.supportedMapTypes[currentIndex]
在 ComboBox 中使用以在地图区域上显示来自地图提供者的支持的地图类型。这里地图插件使用"here.app_id"
和"here.token"
参数。但是对于 OSM 插件,Terrain、transit 和除街道地图图块外的其他图块显示“需要 API 密钥”。我从Thunderforest.com获得了 API 密钥。使用该参数时,仍然显示“API Key Required”:
ComboBox {
id: selectmap
width: parent.width
model:map.supportedMapTypes
textRole:"description"
onCurrentIndexChanged:{
map.activeMapType = map.supportedMapTypes[currentIndex]
}
}
Plugin {
id: pluginOSM
name: "osm"
PluginParameter {
name: "osm.mapping.providersrepository.address";
// name: "osm.geocoding.host"; (also didn't work)
value: "https://tile.thunderforest.com/transport/{z}/{x}/{y}.png?apikey=<my_api_key>" }
}
我还从http://maps-redirect.qt.io/osm/5.8/站点下载了地形文件参数,以便与 qrc 一起使用,如下所示:
import QtQuick 2.6
import QtQuick.Controls 2.0
import QtLocation 5.12
import QtPositioning 5.12
ApplicationWindow{
id: root
width: 500
height: 700
visible: true
Flickable {
height: parent.height
width: parent.width
clip: true
boundsBehavior: Flickable.StopAtBounds
contentHeight: Math.max(mapColumn.implicitHeight, height)+50
ScrollBar.vertical: ScrollBar {}
z: 2
Column{
anchors.horizontalCenter: parent.horizontalCenter
id:mapColumn
spacing: 5
anchors.fill : parent
Row{
anchors.horizontalCenter: parent.horizontalCenter
spacing:25
id:maprow
Rectangle{
width:mapColumn.width
height:mapColumn.height/2
Map {
id:map
anchors.fill: parent
plugin: Plugin {
name: "osm"
PluginParameter {
name: "osm.mapping.host";
value: "qrc:/terrain"
}
}
}
}
}
Column{
id: combos
spacing: 10
width: parent.width
anchors.verticalCenter: root.verticalCenter
Row{
anchors.horizontalCenter: parent.horizontalCenter
spacing:1
Label{ text:"Map Type: " }
// Map Types
ComboBox {
id: selectmap
width: 200
model:map.supportedMapTypes
textRole:"description"
onCurrentIndexChanged: map.activeMapType = map.supportedMapTypes[currentIndex]
}
}
}
}
}
}
在地形文件中,我将参数更新为"UrlTemplate" : "https://tile.thunderforest.com/landscape/{z}/{x}/{y}.png?apikey=<api-key>",
这不起作用,自定义地图视图为空。是否可以使用 API 密钥将其删除?谢谢