Commit a928b1a9 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #4849 from DonLakeFlyer/FollowVehicle

New Follow Vehicle user model
parents 1723a2d2 02709fef
...@@ -33,16 +33,18 @@ FlightMap { ...@@ -33,16 +33,18 @@ FlightMap {
property var rightPanelWidth property var rightPanelWidth
property var qgcView ///< QGCView control which contains this map property var qgcView ///< QGCView control which contains this map
property bool _followVehicleSetting: true ///< User facing setting for follow vehicle
property bool _followVehicle: _followVehicleSetting && _activeVehicleCoordinateValid ///< Control map follow vehicle functionality
property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
property bool _activeVehicleCoordinateValid: _activeVehicle ? _activeVehicle.coordinateValid : false property bool _activeVehicleCoordinateValid: _activeVehicle ? _activeVehicle.coordinateValid : false
property var activeVehicleCoordinate: _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate() property var activeVehicleCoordinate: _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
property var _gotoHereCoordinate: QtPositioning.coordinate() property var _gotoHereCoordinate: QtPositioning.coordinate()
property int _retaskSequence: 0 property int _retaskSequence: 0
property real _toolButtonTopMargin: parent.height - ScreenTools.availableHeight + (ScreenTools.defaultFontPixelHeight / 2) property real _toolButtonTopMargin: parent.height - ScreenTools.availableHeight + (ScreenTools.defaultFontPixelHeight / 2)
property bool _firstVehicleCoordinate: false
property bool _centerUpdateFromTimer: true property bool _disableVehicleTracking: false
property bool _keepVehicleCentered: _mainIsMap ? false : true
property bool _followVehicleSetting: true ///< User facing setting for follow vehicle
property bool _followVehicle: _followVehicleSetting && _activeVehicleCoordinateValid ///< Control map follow vehicle functionality
property bool _firstVehiclePosition: true
Component.onCompleted: { Component.onCompleted: {
QGroundControl.flightMapPosition = center QGroundControl.flightMapPosition = center
...@@ -51,45 +53,92 @@ FlightMap { ...@@ -51,45 +53,92 @@ FlightMap {
onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel
onCenterChanged: { // When the user pans the map we leave things alone until the panRecenterTimer fires
if (_centerUpdateFromTimer) { Connections {
_centerUpdateFromTimer = false target: gesture
} else {
vehicleCenterTimer.restart() onPanFinished: {
_disableVehicleTracking = true
panRecenterTimer.start()
} }
QGroundControl.flightMapPosition = center onFlickFinished: {
_disableVehicleTracking = true
panRecenterTimer.start()
}
} }
onActiveVehicleCoordinateChanged: { onCenterChanged: QGroundControl.flightMapPosition = center
if (!_firstVehicleCoordinate && _activeVehicleCoordinateValid) {
_firstVehicleCoordinate = true function pointInRect(point, rect) {
updateMapToVehiclePosition() return point.x > rect.x &&
} point.x < rect.x + rect.width &&
point.y > rect.y &&
point.y < rect.y + rect.height;
}
property real _animatedLatitudeStart
property real _animatedLatitudeStop
property real _animatedLongitudeStart
property real _animatedLongitudeStop
property real animatedLatitude
property real animatedLongitude
onAnimatedLatitudeChanged: flightMap.center = QtPositioning.coordinate(animatedLatitude, animatedLongitude)
onAnimatedLongitudeChanged: flightMap.center = QtPositioning.coordinate(animatedLatitude, animatedLongitude)
NumberAnimation on animatedLatitude { id: animateLat; from: _animatedLatitudeStart; to: _animatedLatitudeStop; duration: 1000 }
NumberAnimation on animatedLongitude { id: animateLong; from: _animatedLongitudeStart; to: _animatedLongitudeStop; duration: 1000 }
function animatedMapRecenter(fromCoord, toCoord) {
_animatedLatitudeStart = fromCoord.latitude
_animatedLongitudeStart = fromCoord.longitude
_animatedLatitudeStop = toCoord.latitude
_animatedLongitudeStop = toCoord.longitude
animateLat.start()
animateLong.start()
}
function recenterNeeded() {
var vehiclePoint = flightMap.fromCoordinate(activeVehicleCoordinate, false /* clipToViewport */)
var centerViewport = Qt.rect(0, 0, width, height)
return !pointInRect(vehiclePoint, centerViewport)
} }
function updateMapToVehiclePosition() { function updateMapToVehiclePosition() {
if (_followVehicle) { if (_followVehicle && !_disableVehicleTracking) {
_initialMapPositionSet = true if (_keepVehicleCentered) {
_firstVehicleCoordinate = true _firstVehiclePosition = true
_centerUpdateFromTimer = true flightMap.center = activeVehicleCoordinate
flightMap.center = activeVehicleCoordinate } else {
if (_firstVehiclePosition) {
_firstVehiclePosition = false
flightMap.center = activeVehicleCoordinate
} else if (recenterNeeded()) {
animatedMapRecenter(flightMap.center, activeVehicleCoordinate)
}
}
} }
} }
Timer { Timer {
id: vehicleCenterTimer id: panRecenterTimer
interval: 5000 interval: 10000
running: true running: false
triggeredOnStart: true
repeat: true
onTriggered: { onTriggered: {
triggeredOnStart = false _disableVehicleTracking = false
updateMapToVehiclePosition() updateMapToVehiclePosition()
} }
} }
Timer {
interval: 500
running: true
repeat: true
onTriggered: updateMapToVehiclePosition()
}
QGCPalette { id: qgcPal; colorGroupEnabled: true } QGCPalette { id: qgcPal; colorGroupEnabled: true }
QGCMapPalette { id: mapPal; lightColors: isSatelliteMap } QGCMapPalette { id: mapPal; lightColors: isSatelliteMap }
...@@ -231,7 +280,7 @@ FlightMap { ...@@ -231,7 +280,7 @@ FlightMap {
MapPolyline { MapPolyline {
line.width: 3 line.width: 3
line.color: "red" line.color: "red"
z: QGroundControl.zOrderMapItems - 1 z: QGroundControl.zOrderMapItems - 2
path: [ path: [
object.coordinate1, object.coordinate1,
object.coordinate2, object.coordinate2,
......
...@@ -72,18 +72,6 @@ Map { ...@@ -72,18 +72,6 @@ Map {
ExclusiveGroup { id: mapTypeGroup } ExclusiveGroup { id: mapTypeGroup }
property bool _initialMapPositionSet: false
Connections {
target: mainWindow
onGcsPositionChanged: {
if (!_initialMapPositionSet) {
_initialMapPositionSet = true
center = mainWindow.gcsPosition
}
}
}
function updateActiveMapType() { function updateActiveMapType() {
var settings = QGroundControl.settingsManager.flightMapSettings var settings = QGroundControl.settingsManager.flightMapSettings
var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment