Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 20 additions & 26 deletions src/FlightMap/FlightMap.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Map {
property bool isSatelliteMap: activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1
property var gcsPosition: QGroundControl.qgcPositionManger.gcsPosition
property real gcsHeading: QGroundControl.qgcPositionManger.gcsHeading
property bool allowGCSLocationCenter: false ///< true: map will center/zoom to gcs location one time
property bool allowVehicleLocationCenter: false ///< true: map will center/zoom to vehicle location one time
property bool firstGCSPositionReceived: false ///< true: first gcs position update was responded to
property bool firstVehiclePositionReceived: false ///< true: first vehicle position update was responded to
property alias allowGCSLocationCenter: _positionTracker.allowGCSLocationCenter ///< true: map will center to gcs location one time
property alias allowVehicleLocationCenter: _positionTracker.allowVehicleLocationCenter ///< true: map will center/zoom to vehicle location one time
property alias firstVehiclePositionReceived: _positionTracker.firstVehiclePositionReceived ///< true: first vehicle position update was responded to
property alias positionTracker: _positionTracker ///< Auto-centering policy, for derived maps to layer follow behavior on
property bool planView: false ///< true: map being using for Plan view, items should be draggable
property bool pinchZoomDisabledByVirtualJoysticks: false ///< true: disable pinch-to-zoom while virtual joystick thumbs are down

Expand All @@ -40,18 +40,26 @@ Map {
}
}

function _possiblyCenterToVehiclePosition() {
if (!firstVehiclePositionReceived && allowVehicleLocationCenter && _activeVehicleCoordinate.isValid) {
firstVehiclePositionReceived = true
center = _activeVehicleCoordinate
zoomLevel = QGroundControl.flightMapInitialZoom
}
}

function centerToSpecifiedLocation() {
specifyMapPositionDialogFactory.open()
}

MapPositionTracker {
id: _positionTracker

active: _map.mapReady
gcsPosition: _map.gcsPosition
vehicleCoordinate: _map._activeVehicleCoordinate
centerGCSWhenVehicleValid: QGroundControl.settingsManager.flyViewSettings.keepMapCenteredOnVehicle.rawValue

onCenterMap: (coordinate, firstPosition) => {
_map.center = coordinate
if (firstPosition) {
_map.zoomLevel = QGroundControl.flightMapInitialZoom
}
}
}

QGCPopupDialogFactory {
id: specifyMapPositionDialogFactory

Expand All @@ -67,17 +75,6 @@ Map {
}
}

// Center map to gcs location
onGcsPositionChanged: {
if (gcsPosition.isValid && allowGCSLocationCenter && !firstGCSPositionReceived && !firstVehiclePositionReceived) {
firstGCSPositionReceived = true
//-- Only center on gsc if we have no vehicle (and we are supposed to do so)
var _activeVehicleCoordinate = _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
if(QGroundControl.settingsManager.flyViewSettings.keepMapCenteredOnVehicle.rawValue || !_activeVehicleCoordinate.isValid)
center = gcsPosition
}
}

function updateActiveMapType() {
var settings = QGroundControl.settingsManager.flightMapSettings
var fullMapName = settings.mapProvider.value + " " + settings.mapType.value
Expand All @@ -90,12 +87,9 @@ Map {
}
}

on_ActiveVehicleCoordinateChanged: _possiblyCenterToVehiclePosition()

onMapReadyChanged: {
if (_map.mapReady) {
updateActiveMapType()
_possiblyCenterToVehiclePosition()
}
}

Expand Down
35 changes: 35 additions & 0 deletions src/FlyView/FlyViewGeoMap.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,44 @@
*
****************************************************************************/

import QtPositioning

import QGroundControl
import QGroundControl.GeoMap

/// Fly-view 2D/3D map: the GeoMap-engine counterpart of FlyViewMap.
/// Fly-view specific map content (vehicle items, trajectory, ...) lands here.
GeoMap {
id: root

allowGCSLocationCenter: true
allowVehicleLocationCenter: true
keepVehicleCentered: QGroundControl.settingsManager.flyViewSettings.keepMapCenteredOnVehicle.rawValue

readonly property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle

// Vehicle home (launch) location
GeoMapPin {
scene: root.scene
surfaceModel: root.surfaceModel
coordinate: root._activeVehicle ? root._activeVehicle.homePosition : QtPositioning.coordinate()
visible: root._activeVehicle && root._activeVehicle.homePosition.isValid
label: qsTr("L")
}

Repeater {
model: QGroundControl.multiVehicleManager.vehicles

GeoMapVehicleItem {
scene: root.scene
surfaceModel: root.surfaceModel
vehicle: object
}
}

GeoMapFlightPath {
scene: root.scene
surfaceModel: root.surfaceModel
vehicle: root._activeVehicle
}
}
132 changes: 43 additions & 89 deletions src/FlyView/FlyViewMap.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ FlightMap {
property var _flyViewSettings: QGroundControl.settingsManager.flyViewSettings
property bool _keepMapCenteredOnVehicle: _flyViewSettings.keepMapCenteredOnVehicle.rawValue

property bool _disableVehicleTracking: false
property bool _keepVehicleCentered: pipMode ? true : false
property bool _saveZoomLevelSetting: true

Expand Down Expand Up @@ -71,14 +70,33 @@ FlightMap {
}

// We track whether the user has panned or not to correctly handle automatic map positioning
onMapPanStart: _disableVehicleTracking = true
onMapPanStop: panRecenterTimer.restart()
onMapPanStart: positionTracker.userInteracting = true
onMapPanStop: positionTracker.userInteracting = false

function pointInRect(point, rect) {
return point.x > rect.x &&
point.x < rect.x + rect.width &&
point.y > rect.y &&
point.y < rect.y + rect.height;
// Follow behavior on top of FlightMap's one-shot centering: hard follow while
// the keep-centered setting or pip mode is active, inset-rect follow otherwise
Binding {
target: positionTracker
property: "keepVehicleCentered"
value: _keepMapCenteredOnVehicle || _keepVehicleCentered
}

Binding {
target: positionTracker
property: "animating"
value: animateLat.running || animateLong.running
}

Connections {
target: positionTracker
function onRecenterVehicleTo(screenPoint) {
// Move the map such that the vehicle lands on screenPoint
let vehiclePoint = _root.fromCoordinate(_activeVehicleCoordinate, false /* clipToViewport */)
let centerOffset = Qt.point((_root.width / 2) - screenPoint.x, (_root.height / 2) - screenPoint.y)
let vehicleOffsetPoint = Qt.point(vehiclePoint.x + centerOffset.x, vehiclePoint.y + centerOffset.y)
let vehicleOffsetCoord = _root.toCoordinate(vehicleOffsetPoint, false /* clipToViewport */)
animatedMapRecenter(_root.center, vehicleOffsetCoord)
}
}

property real _animatedLatitudeStart
Expand Down Expand Up @@ -115,76 +133,19 @@ FlightMap {
// returns the four rectangles formed by the 8 corner insets
// used for detecting if the vehicle has flown under the instrument panel, virtual joystick etc
function _insetCornerRects() {
var rects = {
"topleft": Qt.rect(0,0,
toolInsets.leftEdgeTopInset,
toolInsets.topEdgeLeftInset),
"topright": Qt.rect(_root.width-toolInsets.rightEdgeTopInset,0,
toolInsets.rightEdgeTopInset,
toolInsets.topEdgeRightInset),
"bottomleft": Qt.rect(0,_root.height-toolInsets.bottomEdgeLeftInset,
toolInsets.leftEdgeBottomInset,
toolInsets.bottomEdgeLeftInset),
"bottomright": Qt.rect(_root.width-toolInsets.rightEdgeBottomInset,_root.height-toolInsets.bottomEdgeRightInset,
toolInsets.rightEdgeBottomInset,
toolInsets.bottomEdgeRightInset)}
return rects
}

function recenterNeeded() {
var vehiclePoint = _root.fromCoordinate(_activeVehicleCoordinate, false /* clipToViewport */)
var centerRect = _insetCenterRect()
//return !pointInRect(vehiclePoint,insetRect)

// If we are outside the center inset rectangle, recenter
if(!pointInRect(vehiclePoint, centerRect)){
return true
}

// if we are inside the center inset rectangle
// then additionally check if we are underneath one of the corner inset rectangles
var cornerRects = _insetCornerRects()
if(pointInRect(vehiclePoint, cornerRects["topleft"])){
return true
} else if(pointInRect(vehiclePoint, cornerRects["topright"])){
return true
} else if(pointInRect(vehiclePoint, cornerRects["bottomleft"])){
return true
} else if(pointInRect(vehiclePoint, cornerRects["bottomright"])){
return true
}

// if we are inside the center inset rectangle, and not under any corner elements
return false
}

function updateMapToVehiclePosition() {
if (animateLat.running || animateLong.running) {
return
}
// We let FlightMap handle first vehicle position
if (!_keepMapCenteredOnVehicle && firstVehiclePositionReceived && _activeVehicleCoordinate.isValid && !_disableVehicleTracking) {
if (_keepVehicleCentered) {
_root.center = _activeVehicleCoordinate
} else {
if (firstVehiclePositionReceived && recenterNeeded()) {
// Move the map such that the vehicle is centered within the inset area
var vehiclePoint = _root.fromCoordinate(_activeVehicleCoordinate, false /* clipToViewport */)
var centerInsetRect = _insetCenterRect()
var centerInsetPoint = Qt.point(centerInsetRect.x + centerInsetRect.width / 2, centerInsetRect.y + centerInsetRect.height / 2)
var centerOffset = Qt.point((_root.width / 2) - centerInsetPoint.x, (_root.height / 2) - centerInsetPoint.y)
var vehicleOffsetPoint = Qt.point(vehiclePoint.x + centerOffset.x, vehiclePoint.y + centerOffset.y)
var vehicleOffsetCoord = _root.toCoordinate(vehicleOffsetPoint, false /* clipToViewport */)
animatedMapRecenter(_root.center, vehicleOffsetCoord)
}
}
}
}

on_ActiveVehicleCoordinateChanged: {
if (_keepMapCenteredOnVehicle && _activeVehicleCoordinate.isValid && !_disableVehicleTracking) {
_root.center = _activeVehicleCoordinate
}
return [
Qt.rect(0,0,
toolInsets.leftEdgeTopInset,
toolInsets.topEdgeLeftInset),
Qt.rect(_root.width-toolInsets.rightEdgeTopInset,0,
toolInsets.rightEdgeTopInset,
toolInsets.topEdgeRightInset),
Qt.rect(0,_root.height-toolInsets.bottomEdgeLeftInset,
toolInsets.leftEdgeBottomInset,
toolInsets.bottomEdgeLeftInset),
Qt.rect(_root.width-toolInsets.rightEdgeBottomInset,_root.height-toolInsets.bottomEdgeRightInset,
toolInsets.rightEdgeBottomInset,
toolInsets.bottomEdgeRightInset)]
}

PipState {
Expand All @@ -193,21 +154,14 @@ FlightMap {
isDark: _isFullWindowItemDark
}

Timer {
id: panRecenterTimer
interval: 10000
running: false
onTriggered: {
_disableVehicleTracking = false
updateMapToVehiclePosition()
}
}

Timer {
interval: 500
running: true
repeat: true
onTriggered: updateMapToVehiclePosition()
onTriggered: {
let vehiclePoint = _root.fromCoordinate(_activeVehicleCoordinate, false /* clipToViewport */)
positionTracker.evaluateInsetFollow(vehiclePoint, _insetCenterRect(), _insetCornerRects())
}
}

QGCMapPalette { id: mapPal; lightColors: isSatelliteMap }
Expand Down
13 changes: 13 additions & 0 deletions src/GeoMap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ qt_add_qml_module(GeoMapModule
SOURCES
CheckerboardTextureData.cc
CheckerboardTextureData.h
FlightPathGeometry.cc
FlightPathGeometry.h
GeoScene.cc
GeoScene.h
GeoMapCamera.cc
GeoMapCamera.h
GeoMapItem.cc
GeoMapItem.h
PaperPlaneGeometry.cc
PaperPlaneGeometry.h
PatchGeometry.cc
PatchGeometry.h
PatchTextureData.cc
Expand All @@ -50,6 +56,12 @@ qt_add_qml_module(GeoMapModule
SurfacePatchModel.h
QML_FILES
GeoMap.qml
GeoMapFlightPath.qml
GeoMapPin.qml
GeoMapVehicleItem.qml
RESOURCES
shaders/flightpath.frag
shaders/flightpath.vert
)

target_link_libraries(GeoMapModule
Expand All @@ -58,6 +70,7 @@ target_link_libraries(GeoMapModule
Qt6::Gui
Qt6::Positioning
Qt6::Qml
Qt6::Quick
Qt6::Quick3D
PRIVATE
QGCLogging
Expand Down
Loading
Loading