diff options
Diffstat (limited to 'examples/location')
-rw-r--r-- | examples/location/geojson_viewer/main.qml | 30 | ||||
-rw-r--r-- | examples/location/minimal_map/main.qml | 42 |
2 files changed, 59 insertions, 13 deletions
diff --git a/examples/location/geojson_viewer/main.qml b/examples/location/geojson_viewer/main.qml index 85d0e07d..2aab296e 100644 --- a/examples/location/geojson_viewer/main.qml +++ b/examples/location/geojson_viewer/main.qml @@ -63,7 +63,10 @@ ApplicationWindow { width: 1024 height: 1024 menuBar: mainMenu - title: qsTr("GeoJSON Viewer") + title: qsTr("GeoJSON Viewer: ") + view.map.center + + " zoom " + view.map.zoomLevel.toFixed(3) + + " min " + view.map.minimumZoomLevel + + " max " + view.map.maximumZoomLevel FileDialog { visible: false @@ -147,23 +150,26 @@ ApplicationWindow { } Shortcut { - sequence: "Ctrl+P" - onActivated: { - - console.log("Center : QtPositioning.coordinate(",map.center.latitude,",",map.center.longitude,")") - console.log("Zoom : ",map.zoomLevel) - } + enabled: view.map.zoomLevel < view.map.maximumZoomLevel + sequence: StandardKey.ZoomIn + onActivated: view.map.zoomLevel = Math.round(view.map.zoomLevel + 1) + } + Shortcut { + enabled: view.map.zoomLevel > view.map.minimumZoomLevel + sequence: StandardKey.ZoomOut + onActivated: view.map.zoomLevel = Math.round(view.map.zoomLevel - 1) } - Map { - id: map + MapView { + id: view anchors.fill: parent - center: QtPositioning.coordinate(43.59, 13.50) // Starting coordinates: Ancona, the city where I am studying :) - plugin: Plugin { name: "osm" } - zoomLevel: 4 + map.center: QtPositioning.coordinate(43.59, 13.50) // Ancona, Italy + map.plugin: Plugin { name: "osm" } + map.zoomLevel: 4 MapItemView { id: miv + parent: view.map model: geoJsoner.model delegate: GeoJsonDelegate { } diff --git a/examples/location/minimal_map/main.qml b/examples/location/minimal_map/main.qml index 92230f76..be78f00d 100644 --- a/examples/location/minimal_map/main.qml +++ b/examples/location/minimal_map/main.qml @@ -49,7 +49,6 @@ ****************************************************************************/ import QtQuick -import QtQuick.Window import QtLocation import QtPositioning @@ -57,6 +56,8 @@ Window { width: Qt.platform.os == "android" ? Screen.width : 512 height: Qt.platform.os == "android" ? Screen.height : 512 visible: true + title: map.center + " zoom " + map.zoomLevel.toFixed(3) + + " min " + map.minimumZoomLevel + " max " + map.maximumZoomLevel Plugin { id: mapPlugin @@ -69,9 +70,48 @@ Window { } Map { + id: map anchors.fill: parent plugin: mapPlugin center: QtPositioning.coordinate(59.91, 10.75) // Oslo zoomLevel: 14 + property geoCoordinate startCentroid + + PinchHandler { + id: pinch + target: null + onActiveChanged: if (active) { + map.startCentroid = map.toCoordinate(pinch.centroid.position, false) + } + onScaleChanged: (delta) => { + map.zoomLevel += Math.log2(delta) + map.alignCoordinateToPoint(map.startCentroid, pinch.centroid.position) + } + onRotationChanged: (delta) => { + map.bearing -= delta + map.alignCoordinateToPoint(map.startCentroid, pinch.centroid.position) + } + grabPermissions: PointerHandler.TakeOverForbidden + } + WheelHandler { + id: wheel + rotationScale: 1/120 + property: "zoomLevel" + } + DragHandler { + id: drag + target: null + onTranslationChanged: (delta) => map.pan(-delta.x, -delta.y) + } + Shortcut { + enabled: map.zoomLevel < map.maximumZoomLevel + sequence: StandardKey.ZoomIn + onActivated: map.zoomLevel = Math.round(map.zoomLevel + 1) + } + Shortcut { + enabled: map.zoomLevel > map.minimumZoomLevel + sequence: StandardKey.ZoomOut + onActivated: map.zoomLevel = Math.round(map.zoomLevel - 1) + } } } |