Files
qt-dev-env/WeatherRoutes/qml/MapView.qml

108 lines
3.3 KiB
QML

import QtQuick
import QtLocation
import QtPositioning
Rectangle {
property alias positionSource: positionSource
property variant waypoints: mapData.waypoints
function resetZoomLevel()
{
map.zoomLevel = mapData.defaultZoomLevel
map.bearing = 0;
positionSource.start()
}
Plugin {
id: mapPlugin
name: "osm"
PluginParameter {
name: "osm.mapping.providersrepository.disabled"
value: "true"
}
PluginParameter {
name: "osm.mapping.providersrepository.address"
value: "http://maps-redirect.qt.io/osm/5.6/"
}
}
PositionSource
{
id: positionSource
updateInterval: mapData.gpsUpdateInterval
active: true
onPositionChanged: {
var coord = positionSource.position.coordinate;
map.visible = true;
map.center = positionSource.position.coordinate;
}
}
MapQuickItem {
id: marker
zoomLevel: map.zoomLevel
anchorPoint.x: image.width/2
anchorPoint.y: image.height
coordinate: positionSource.position.coordinate
sourceItem: Image {
id: image
height: 40
width: height*2/3
source: "qrc:/images/currentLocationOfWaypoint.svg"
transform: Rotation { origin.x: marker.anchorPoint.x; origin.y: marker.anchorPoint.y; angle: map.bearing}
}
Component.onCompleted: map.addMapItem(marker)
}
Map {
id: map
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(59.91, 10.75) // Oslo
zoomLevel: mapData.zoomLevel
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
acceptedDevices: Qt.platform.pluginName === "cocoa" || Qt.platform.pluginName === "wayland"
? PointerDevice.Mouse | PointerDevice.TouchPad
: PointerDevice.Mouse
rotationScale: 1/120
property: "zoomLevel"
}
DragHandler {
id: drag
target: null
onTranslationChanged: (delta) => map.pan(-delta.x, -delta.y)
// onGrabChanged: positionSource.active = false
}
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)
}
}
}