我有我自己的本地Z/X/Y地圖瓷磚服務器,並希望將它用作QML應用程序中的地圖背景。看看示例代碼,它看起來是這樣做的: -QT QML QtLocation地圖插件
Plugin {
id: osmPlugin
name: "osm"
}
所以我需要寫我自己的插件。但文檔看起來很稀疏,我找不到osm版本或安裝說明的源代碼。
這樣做相對容易嗎,還是可以在不編寫新插件的情況下完成?
我有我自己的本地Z/X/Y地圖瓷磚服務器,並希望將它用作QML應用程序中的地圖背景。看看示例代碼,它看起來是這樣做的: -QT QML QtLocation地圖插件
Plugin {
id: osmPlugin
name: "osm"
}
所以我需要寫我自己的插件。但文檔看起來很稀疏,我找不到osm版本或安裝說明的源代碼。
這樣做相對容易嗎,還是可以在不編寫新插件的情況下完成?
如果文檔沒有包含足夠詳細的內容,請務必記住Qt's source是公開可用的。
例如,OSM插件here
的Woboq code browser也很不錯的,如果你知道類名或文件,你是looking for
好,我已經想出了一個辦法做到這一點無需編寫插件。
OSM插件使用tileserver來檢索圖塊。 URL設置爲插件選項osm.mapping.custom.host將其設置爲本地URL允許我使用自己的瓷磚,只要它們符合osm結構。
可以這樣設置osm.mapping.host:
Plugin {
id: osmPlugin
name: "osm"
PluginParameter { name: "osm.mapping.host"; value: "https://tile.openstreetmap.org/" }
PluginParameter { name: "osm.geocoding.host"; value: "https://nominatim.openstreetmap.org" }
PluginParameter { name: "osm.routing.host"; value: "https://router.project-osrm.org/viaroute" }
PluginParameter { name: "osm.places.host"; value: "https://nominatim.openstreetmap.org/search" }
PluginParameter { name: "osm.mapping.copyright"; value: "" }
PluginParameter { name: "osm.mapping.highdpi_tiles"; value: true }
}
但不要忘記使用下面的代碼來設置自定義地圖類型:
Map {
id: map
height: parent.width
width: parent.width
plugin: osmPlugin
Component.onCompleted: {
for(var i_type in supportedMapTypes) {
if(supportedMapTypes[i_type].name.localeCompare("Custom URL Map") === 0) {
activeMapType = supportedMapTypes[i_type]
}
}
}
}
謝謝,但作爲我的問題的第二部分是有一個替代方案,因爲它似乎很多工作,特別是在OSM代碼中沒有評論。 –