From 6b40fb48fe5f5f094232535199cfccc753f62b17 Mon Sep 17 00:00:00 2001 From: Harald Meyer Date: Thu, 9 Jul 2015 17:29:56 +0200 Subject: 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 Reviewed-by: Alex Blasche --- examples/location/mapviewer/map/MapComponent.qml | 38 +++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'examples/location/mapviewer') 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:{ -- cgit v1.2.3