summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHarald Meyer <dev@meh.at>2015-07-09 17:29:56 +0200
committerHarald Meyer <dev@meh.at>2015-07-13 06:52:31 +0000
commit6b40fb48fe5f5f094232535199cfccc753f62b17 (patch)
treea761835d0f0c1ea07d26ccbe83f53a7a5422150c /examples
parent43bea1bbadec470202cb27d9db5cc202b9514f91 (diff)
downloadqtlocation-6b40fb48fe5f5f094232535199cfccc753f62b17.tar.gz
Improved zooming and map movement behavior.
Improved: Double tapping/mouse wheel based zooming keeps the map at the current geo location. Added: Left/Right/Up/Down keys can be used to move the map. Task-number: QTBUG-47020 Task-number: QTBUG-47019 Change-Id: I63859319b282e7738a173b0d3917433860fc8969 Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/location/mapviewer/map/MapComponent.qml38
1 files changed, 31 insertions, 7 deletions
diff --git a/examples/location/mapviewer/map/MapComponent.qml b/examples/location/mapviewer/map/MapComponent.qml
index 0cb84fdf..0857804b 100644
--- a/examples/location/mapviewer/map/MapComponent.qml
+++ b/examples/location/mapviewer/map/MapComponent.qml
@@ -302,9 +302,25 @@ Map {
Keys.onPressed: {
if (event.key === Qt.Key_Plus) {
- map.zoomLevel++
+ map.zoomLevel++;
} else if (event.key === Qt.Key_Minus) {
- map.zoomLevel--
+ map.zoomLevel--;
+ } else if (event.key === Qt.Key_Left || event.key === Qt.Key_Right ||
+ event.key === Qt.Key_Up || event.key === Qt.Key_Down) {
+ var dx = 0;
+ var dy = 0;
+
+ switch (event.key) {
+
+ case Qt.Key_Left: dx = map.width / 4; break;
+ case Qt.Key_Right: dx = -map.width / 4; break;
+ case Qt.Key_Up: dy = map.height / 4; break;
+ case Qt.Key_Down: dy = -map.height / 4; break;
+
+ }
+
+ var mapCenterPoint = Qt.point(map.width / 2.0 - dx, map.height / 2.0 - dy);
+ map.center = map.toCoordinate(mapCenterPoint);
}
}
@@ -594,14 +610,22 @@ Map {
}
onDoubleClicked: {
- map.center = map.toCoordinate(Qt.point(mouse.x, mouse.y))
+ var mouseGeoPos = map.toCoordinate(Qt.point(mouse.x, mouse.y));
+ var preZoomPoint = map.fromCoordinate(mouseGeoPos, false);
if (mouse.button === Qt.LeftButton) {
- map.zoomLevel++
+ map.zoomLevel++;
} else if (mouse.button === Qt.RightButton) {
- map.zoomLevel--
+ map.zoomLevel--;
}
- lastX = -1
- lastY = -1
+ var postZoomPoint = map.fromCoordinate(mouseGeoPos, false);
+ var dx = postZoomPoint.x - preZoomPoint.x;
+ var dy = postZoomPoint.y - preZoomPoint.y;
+
+ var mapCenterPoint = Qt.point(map.width / 2.0 + dx, map.height / 2.0 + dy);
+ map.center = map.toCoordinate(mapCenterPoint);
+
+ lastX = -1;
+ lastY = -1;
}
onPressAndHold:{