Qt QML地图仅垂直缩放
Qt中的地图是否有属性,所以若我在地图上的任意位置移动鼠标光标并尝试用鼠标滚轮更改缩放级别,它不会移动中心?因为在默认情况下,地图会缩放,但会将现有中心移向鼠标光标位置(下图中的示例;如果光标位于显示位置,我们尝试更改缩放,则地理标记图片将沿箭头方向移动)。我只需要它从地图的指定中心直接向上缩放,而不管鼠标光标的位置如何 地图说明: QML代码Qt QML地图仅垂直缩放,qt,geolocation,qml,qtlocation,qt5.12,Qt,Geolocation,Qml,Qtlocation,Qt5.12,Qt中的地图是否有属性,所以若我在地图上的任意位置移动鼠标光标并尝试用鼠标滚轮更改缩放级别,它不会移动中心?因为在默认情况下,地图会缩放,但会将现有中心移向鼠标光标位置(下图中的示例;如果光标位于显示位置,我们尝试更改缩放,则地理标记图片将沿箭头方向移动)。我只需要它从地图的指定中心直接向上缩放,而不管鼠标光标的位置如何 地图说明: QML代码 import QtQuick 2.0 import QtQuick.Window 2.0 import QtLocation 5.6 import Q
import QtQuick 2.0
import QtQuick.Window 2.0
import QtLocation 5.6
import QtPositioning 5.6
Item{
id: itemControl
objectName: "itemControl"
width: 512
height: 512
visible: true
Plugin {
id: mapPlugin
PluginParameter { name: "osm.useragent"; value: "usermap" }
name: "esri"
}
Map {
id:map
gesture.enabled: true
gesture.acceptedGestures: MapGestureArea.PinchGesture | MapGestureArea.PanGesture
objectName: "map"
anchors.fill: parent
bearing: 0
width: 512
height: 512
plugin: mapPlugin
center {
latitude: 45.525180446
longitude: 13.5575992170
}
zoomLevel: 15
//If user doubleclicks on map update coordinates of pixel to coordinates on UI
signal qmlSignalUpdateLat(string msg)
signal qmlSignalUpdateLon(string msg)
MouseArea
{
id: mousearea
hoverEnabled: true
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onDoubleClicked: {
map.center.latitude = map.toCoordinate(Qt.point(mouseX,mouseY)).latitude
map.center.longitude = map.toCoordinate(Qt.point(mouseX,mouseY)).longitude
map.qmlSignalUpdateLat(map.center.latitude)
map.qmlSignalUpdateLon(map.center.longitude)
}
}
function updateMap(lat,lon,bear){
map.center.latitude = lat;
map.center.longtitude = lon;
map.bearing = bear;
}
}
}
也许应该有更优雅的解决方案,但下面是您的简化代码:
import QtQuick 2.0
import QtQuick.Window 2.0
import QtLocation 5.6
import QtPositioning 5.6
Window {
width: 512
height: 512
visible: true
Plugin {
id: mapPlugin
PluginParameter { name: "osm.useragent"; value: "usermap" }
name: "esri"
}
Location {
// Define location that will be "center" of map
id: mapCenter
coordinate {
latitude: 45.525180446
longitude: 13.5575992170
}
}
Map {
id: map
anchors.fill: parent
plugin: mapPlugin
center: mapCenter.coordinate
onCenterChanged: {
// As soon as map center changed -- we'll check if coordinates differs from our
// mapCenter coordinates and if so, set map center coordinates equal to mapCenter
if (map.center != mapCenter.coordinate) {
map.center = mapCenter.coordinate
}
}
MapCircle {
// Circle just for ability to check if it zooms correctly
center: mapCenter.coordinate
radius: 500.0
color: "green"
border.width: 3
}
}
}
这背后的主要思想是控制地图中心的每次更改。如果它发生变化,检查它是否与我们的中心相等。如果它不等于我们想要的中心mapCenter
——我们会更改它
因此: