1/****************************************************************************
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
8 ****************************************************************************/
15import QGroundControl.Controls
16import QGroundControl.FlightMap
17import QGroundControl.GeoMap
19/// Fly-view 2D/3D map: the GeoMap-engine counterpart of FlyViewMap.
20/// Fly-view specific map content (vehicle items, trajectory, ...) lands here.
24 allowGCSLocationCenter: true
25 allowVehicleLocationCenter: true
26 keepVehicleCentered: QGroundControl.settingsManager.flyViewSettings.keepMapCenteredOnVehicle.rawValue
28 // Guided-action indicators for the map click drop panel (FlyViewMapClickDropPanel)
29 readonly property var gotoIndicator: gotoLocationItem
30 readonly property var orbitIndicator: orbitMapCircle
32 readonly property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
33 readonly property var _missionController: globals.planMasterControllerFlyView ? globals.planMasterControllerFlyView.missionController : null
34 readonly property var _rallyPointController: globals.planMasterControllerFlyView ? globals.planMasterControllerFlyView.rallyPointController : null
35 readonly property var _geoFenceController: globals.planMasterControllerFlyView ? globals.planMasterControllerFlyView.geoFenceController : null
36 readonly property var _flyViewSettings: QGroundControl.settingsManager.flyViewSettings
38 // DEM height minus vehicle-reported AMSL, sampled at home for the active
39 // vehicle. Computed once here and shared by GeoMapMissionPath and every
40 // GeoMapMissionItems marker instead of each re-sampling the same DEM
41 // lookup independently (see GeoMapVehicleItem for the same correction
42 // applied per-vehicle in the marker Repeater below, where it can't be
43 // shared since each vehicle has its own home position).
44 property real _activeVehicleHomeTerrainBias: 0
46 function _updateActiveVehicleHomeTerrainBias() {
47 if (root.surfaceModel && root._activeVehicle && root._activeVehicle.homePosition.isValid && !isNaN(root._activeVehicle.homePosition.altitude)) {
48 root._activeVehicleHomeTerrainBias = root.surfaceModel.terrainDataHeightAt(root._activeVehicle.homePosition) - root._activeVehicle.homePosition.altitude
50 root._activeVehicleHomeTerrainBias = 0
54 on_ActiveVehicleChanged: {
55 _updateActiveVehicleHomeTerrainBias()
56 _fuzzyVehicleDisplayAltitude = NaN
57 _updateFuzzyVehicleDisplayAltitude()
59 onSurfaceModelChanged: _updateActiveVehicleHomeTerrainBias()
61 // Deadbanded copy of the vehicle's bias-corrected display altitude so
62 // live-bound orbit visuals don't rebuild their ring geometry on every
63 // sub-meter telemetry altitude tick
64 property real _fuzzyVehicleDisplayAltitude: NaN
66 readonly property real _fuzzyAltitudeDeadbandMeters: 1
68 function _updateFuzzyVehicleDisplayAltitude() {
69 if (!root._activeVehicle || isNaN(root._activeVehicle.coordinate.altitude)) {
70 root._fuzzyVehicleDisplayAltitude = NaN
73 const displayAltitude = root._activeVehicle.coordinate.altitude + root._activeVehicleHomeTerrainBias
74 if (isNaN(root._fuzzyVehicleDisplayAltitude) || Math.abs(displayAltitude - root._fuzzyVehicleDisplayAltitude) > root._fuzzyAltitudeDeadbandMeters) {
75 root._fuzzyVehicleDisplayAltitude = displayAltitude
79 on_ActiveVehicleHomeTerrainBiasChanged: _updateFuzzyVehicleDisplayAltitude()
81 function _withFuzzyVehicleAltitude(coord) {
82 if (!isNaN(root._fuzzyVehicleDisplayAltitude)) {
83 return QtPositioning.coordinate(coord.latitude, coord.longitude, root._fuzzyVehicleDisplayAltitude)
85 return QtPositioning.coordinate(coord.latitude, coord.longitude)
88 // Guided commands hold the vehicle's current altitude; same bias-corrected
89 // AMSL as GeoMapVehicleItem so indicators line up with the rendered vehicle
90 function _withVehicleAltitude(coord) {
91 if (root._activeVehicle && !isNaN(root._activeVehicle.coordinate.altitude)) {
92 return QtPositioning.coordinate(coord.latitude, coord.longitude,
93 root._activeVehicle.coordinate.altitude + root._activeVehicleHomeTerrainBias)
95 return QtPositioning.coordinate(coord.latitude, coord.longitude)
98 property var _missionItemSelectionPanel: null
100 function _confirmSetWaypoint(sequenceNumber) {
101 globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionSetWaypoint,
102 Math.max(sequenceNumber, 1))
105 function _closeMissionItemSelectionPanel() {
106 if (_missionItemSelectionPanel) {
107 _missionItemSelectionPanel.close()
112 target: root.surfaceModel
114 function onTerrainDataChanged() {
115 root._updateActiveVehicleHomeTerrainBias()
120 target: root._activeVehicle
122 function onHomePositionChanged() {
123 root._updateActiveVehicleHomeTerrainBias()
126 function onCoordinateChanged() {
127 root._updateFuzzyVehicleDisplayAltitude()
131 // Vehicle home (launch) location
134 surfaceModel: root.surfaceModel
135 coordinate: root._activeVehicle ? root._activeVehicle.homePosition : QtPositioning.coordinate()
136 visible: root._activeVehicle && root._activeVehicle.homePosition.isValid
141 model: QGroundControl.multiVehicleManager.vehicles
145 surfaceModel: root.surfaceModel
152 surfaceModel: root.surfaceModel
153 vehicle: root._activeVehicle
158 surfaceModel: root.surfaceModel
159 missionController: root._missionController
160 vehicle: root._activeVehicle
161 homeTerrainBias: root._activeVehicleHomeTerrainBias
166 surfaceModel: root.surfaceModel
167 missionController: root._missionController
168 homeTerrainBias: root._activeVehicleHomeTerrainBias
169 // Same action as PlanMapItems in the QtLocation fly view: clicking a
170 // marker adjusts the vehicle's current mission item (after confirm)
171 onItemClicked: (item) => root._confirmSetWaypoint(item.sequenceNumber)
172 onGroupClicked: (items, marker) => {
173 root._closeMissionItemSelectionPanel()
174 const topLeft = marker.mapToItem(globals.parent, 0, 0)
175 root._missionItemSelectionPanel = missionItemSelectionPanelComponent.createObject(mainWindow, {
176 clickRect: Qt.rect(topLeft.x, topLeft.y, marker.width, marker.height),
179 if (root._missionItemSelectionPanel) {
180 root._missionItemSelectionPanel.open()
183 onGroupsInvalidated: root._closeMissionItemSelectionPanel()
186 // The picker lists the old mission's items: close it when the mission is replaced
188 target: root._missionController
190 function onVisualItemsReset() { root._closeMissionItemSelectionPanel() }
194 id: missionItemSelectionPanelComponent
196 MissionItemSelectionPanel {
197 id: missionItemSelectionPanel
199 onItemSelected: (sequenceNumber) => root._confirmSetWaypoint(sequenceNumber)
201 if (root._missionItemSelectionPanel === missionItemSelectionPanel) {
202 root._missionItemSelectionPanel = null
209 GeoMapMissionDirectionArrows {
211 surfaceModel: root.surfaceModel
212 missionController: root._missionController
213 homeTerrainBias: root._activeVehicleHomeTerrainBias
216 // Allow custom builds to add map items (QGCCorePlugin::customGeoMapItems)
218 model: QGroundControl.corePlugin.customGeoMapItems
221 Component.onCompleted: setSource(object.url, {
222 customMapObject: object,
224 surfaceModel: root.surfaceModel
229 GeoMapGeoFenceVisuals {
231 surfaceModel: root.surfaceModel
232 geoFenceController: root._geoFenceController
233 homePosition: root._activeVehicle && root._activeVehicle.homePosition.isValid ? root._activeVehicle.homePosition : QtPositioning.coordinate()
238 model: root._rallyPointController ? root._rallyPointController.points : undefined
242 surfaceModel: root.surfaceModel
244 vehicle: root._activeVehicle
245 homeAltitude: root._activeVehicle ? root._activeVehicle.homePosition.altitude : NaN
246 homeTerrainBias: root._activeVehicleHomeTerrainBias
250 // Proximity sensor arcs per vehicle
252 model: QGroundControl.multiVehicleManager.vehicles
254 FlyViewGeoProximityRadar {
256 surfaceModel: root.surfaceModel
263 model: QGroundControl.adsbVehicleManager.adsbVehicles
265 GeoMapADSBVehicleItem {
267 surfaceModel: root.surfaceModel
268 coordinate: object.coordinate
269 altitude: object.altitude
270 callsign: object.callsign
271 heading: object.heading
273 size: ScreenTools.defaultFontPixelHeight * 2.5
274 homeTerrainBias: root._activeVehicleHomeTerrainBias
278 // Camera trigger points: batched sprite layer (single draw call), since
279 // surveys can produce thousands of points
282 surfaceModel: root.surfaceModel
283 model: root._activeVehicle ? root._activeVehicle.cameraTriggerPoints : null
284 sprite: triggerIconSource
285 spriteSize: triggerIcon.width
287 CameraTriggerIcon { id: triggerIcon }
289 id: triggerIconSource
290 sourceItem: triggerIcon
292 // Render at physical resolution: the default (logical-size) texture
293 // is upscaled on hidpi displays and looks blurry
294 textureSize: Qt.size(triggerIcon.width * Screen.devicePixelRatio, triggerIcon.height * Screen.devicePixelRatio)
298 // GoTo Location forward flight circle visuals
299 GeoMapCircleVisuals {
300 id: fwdFlightGotoMapCircle
301 objectName: "flyViewGeoFwdFlightGotoCircle"
303 surfaceModel: root.surfaceModel
304 mapCircle: _fwdFlightGotoCircleModel
305 radiusLabelVisible: true
306 // Only the radius is editable, not the position
307 centerDragHandleVisible: false
308 // Loiter happens at the goto altitude (carried in the center coordinate)
309 altitudeMode: !isNaN(_fwdFlightGotoCircleModel.center.altitude) ? GeoMapItem.Absolute : GeoMapItem.ClampToGround
310 // PX4 ignores the commanded loiter radius (flies NAV_LOITER_RAD), so the circle size is unknown
311 visible: gotoLocationItem.visible && root._activeVehicle &&
312 !root._activeVehicle.px4Firmware &&
313 root._activeVehicle.inFwdFlight &&
314 !root._activeVehicle.orbitActive
316 property alias coordinate: _fwdFlightGotoCircleModel.center
317 property alias radius: _fwdFlightGotoCircleModel.radius
318 property alias clockwiseRotation: _fwdFlightGotoCircleModel.clockwiseRotation
320 Component.onCompleted: globals.guidedControllerFlyView.fwdFlightGotoMapCircle = this
323 target: _fwdFlightGotoCircleModel
325 value: gotoLocationItem.coordinate
328 function startLoiterRadiusEdit() {
329 _fwdFlightGotoCircleModel.interactive = true
332 // Called when loiter edit is confirmed
333 function actionConfirmed() {
334 _fwdFlightGotoCircleModel.interactive = false
335 _fwdFlightGotoCircleModel._commitRadius()
338 // Called when loiter edit is cancelled
339 function actionCancelled() {
340 _fwdFlightGotoCircleModel.interactive = false
341 _fwdFlightGotoCircleModel._restoreRadius()
345 id: _fwdFlightGotoCircleModel
348 clockwiseRotation: true
350 property real _defaultLoiterRadius: root._flyViewSettings.forwardFlightGoToLocationLoiterRad.rawValue
351 property real _committedRadius
354 // Don't commit the radius in case this operation is undone
355 radius.rawValue = _defaultLoiterRadius
358 Component.onCompleted: {
359 radius.rawValue = _defaultLoiterRadius
363 function _commitRadius() {
364 _committedRadius = radius.rawValue
367 function _restoreRadius() {
368 radius.rawValue = _committedRadius
373 // GoTo Location visuals
376 objectName: "flyViewGeoGotoLocation"
378 surfaceModel: root.surfaceModel
381 label: qsTr("Go here", "Go to location waypoint")
382 // Goto holds the vehicle's current altitude, so render there in 3D
383 altitudeMode: isNaN(coordinate.altitude) ? GeoMapItem.ClampToGround : GeoMapItem.Absolute
385 readonly property bool inGotoFlightMode: root._activeVehicle ? root._activeVehicle.flightMode === root._activeVehicle.gotoFlightMode : false
387 property var _committedCoordinate: null
389 onInGotoFlightModeChanged: {
390 if (!inGotoFlightMode && gotoLocationItem.visible) {
391 // Hide goto indicator when vehicle falls out of guided mode
396 function show(coord) {
397 gotoLocationItem.coordinate = root._withVehicleAltitude(coord)
398 gotoLocationItem.visible = true
402 gotoLocationItem.visible = false
405 function actionConfirmed() {
408 // Commit the new radius which possibly changed
409 fwdFlightGotoMapCircle.actionConfirmed()
411 // We leave the indicator visible. The handling for onInGuidedModeChanged will hide it.
414 function actionCancelled() {
417 // Also restore the loiter radius
418 fwdFlightGotoMapCircle.actionCancelled()
421 function _commitCoordinate() {
423 _committedCoordinate = QtPositioning.coordinate(coordinate.latitude, coordinate.longitude, coordinate.altitude)
426 function _restoreCoordinate() {
427 if (_committedCoordinate) {
428 coordinate = _committedCoordinate
435 // Orbit editing visuals
436 GeoMapCircleVisuals {
438 objectName: "flyViewGeoOrbitCircle"
440 surfaceModel: root.surfaceModel
441 mapCircle: _orbitCircleModel
442 altitudeMode: !isNaN(_orbitCircleModel.center.altitude) ? GeoMapItem.Absolute : GeoMapItem.ClampToGround
445 property alias center: _orbitCircleModel.center
446 property alias clockwiseRotation: _orbitCircleModel.clockwiseRotation
447 readonly property real defaultRadius: 30
450 target: QGroundControl.multiVehicleManager
451 function onActiveVehicleChanged(activeVehicle) {
452 if (!activeVehicle) {
453 orbitMapCircle.visible = false
458 function show(coord) {
459 _orbitCircleModel.radius.rawValue = defaultRadius
460 _orbitCircleModel.center = root._withVehicleAltitude(coord)
461 orbitMapCircle.visible = true
465 orbitMapCircle.visible = false
468 function actionConfirmed() {
469 // Live orbit status is handled by telemetry so we hide here and telemetry will show again.
473 function actionCancelled() {
478 return _orbitCircleModel.radius.rawValue
481 Component.onCompleted: globals.guidedControllerFlyView.orbitMapCircle = orbitMapCircle
484 id: _orbitCircleModel
488 clockwiseRotation: true
492 // ROI Location visuals
496 surfaceModel: root.surfaceModel
497 visible: root._activeVehicle && root._activeVehicle.isROIEnabled
499 label: qsTr("ROI here", "Make this a Region Of Interest")
501 // The vehicle reports the ROI center as lat/lon only; the commanded
502 // height lives in roiRelativeAltitudeMeters (relative to home).
503 // Render at that height, DEM bias-corrected like the mission markers.
504 property var _roiCenter: QtPositioning.coordinate()
506 // Picked coordinates carry altitude 0 (worldToGeo), so isNaN(altitude)
507 // cannot detect the missing-composition case; ground-clamp on this
508 readonly property bool _haveComposedAltitude: _roiCenter.isValid && root._activeVehicle
509 && root._activeVehicle.homePosition.isValid
510 && !isNaN(root._activeVehicle.homePosition.altitude)
512 // Re-check the vehicle here: _haveComposedAltitude can be stale-true
513 // during binding re-evaluation when the active vehicle goes null
514 coordinate: (_haveComposedAltitude && root._activeVehicle)
515 ? QtPositioning.coordinate(_roiCenter.latitude, _roiCenter.longitude,
516 root._activeVehicle.homePosition.altitude
517 + root._activeVehicle.roiRelativeAltitudeMeters
518 + root._activeVehicleHomeTerrainBias)
520 altitudeMode: _haveComposedAltitude ? GeoMapItem.Absolute : GeoMapItem.ClampToGround
523 target: root._activeVehicle
524 function onRoiCoordChanged(centerCoord) {
525 roiLocationItem._roiCenter = centerCoord
531 onClicked: (position) => {
532 const windowPosition = mapToItem(globals.parent, position.x, position.y)
533 const dropPanel = roiEditDropPanelComponent.createObject(mainWindow, { clickRect: Qt.rect(windowPosition.x, windowPosition.y, 0, 0) })
539 // Orbit telemetry visuals. ORBIT_EXECUTION_STATUS carries no altitude, so
540 // render at the vehicle's altitude (the vehicle flies on this ring)
542 id: orbitTelemetryCircle
544 surfaceModel: root.surfaceModel
545 center: root._activeVehicle ? root._withFuzzyVehicleAltitude(root._activeVehicle.orbitMapCircle.center) : QtPositioning.coordinate()
546 radiusMeters: root._activeVehicle ? root._activeVehicle.orbitMapCircle.radius.rawValue : 0
547 altitudeMode: (center && !isNaN(center.altitude)) ? GeoMapItem.Absolute : GeoMapItem.ClampToGround
548 visible: root._activeVehicle ? root._activeVehicle.orbitActive : false
552 id: orbitCenterIndicator
554 surfaceModel: root.surfaceModel
555 coordinate: root._activeVehicle ? root._withFuzzyVehicleAltitude(root._activeVehicle.orbitMapCircle.center) : QtPositioning.coordinate()
556 altitudeMode: isNaN(coordinate.altitude) ? GeoMapItem.ClampToGround : GeoMapItem.Absolute
557 visible: orbitTelemetryCircle.visible && !gotoLocationItem.visible
559 label: qsTr("Orbit", "Orbit waypoint")
562 QGCPopupDialogFactory {
563 id: roiEditPositionDialogFactory
565 dialogComponent: roiEditPositionDialogComponent
569 id: roiEditPositionDialogComponent
572 // Edit the raw reported center, not the composed display coordinate:
573 // that binding recomputes on home/terrain-bias updates, which would
574 // fire onCoordinateChanged and re-command the ROI while editing
575 title: qsTr("Edit ROI Position")
576 coordinate: roiLocationItem._roiCenter
578 readonly property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
579 property var _openedForVehicle: null
581 Component.onCompleted: _openedForVehicle = _activeVehicle
583 // The ROI belongs to the vehicle the dialog was opened for; close
584 // if that vehicle goes away or the active vehicle changes
585 on_ActiveVehicleChanged: close()
587 onCoordinateChanged: {
588 // Guards the init-time change and the vehicle-switch race, where
589 // the rebound coordinate could command the new vehicle with the
590 // old vehicle's ROI before the close() handler runs
591 if (!_openedForVehicle || (_activeVehicle !== _openedForVehicle)) {
594 roiLocationItem._roiCenter = coordinate
595 _openedForVehicle.guidedModeROI(coordinate, _openedForVehicle.roiRelativeAltitudeMeters)
601 id: roiEditDropPanelComponent
606 readonly property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
608 // The ROI belongs to the vehicle the panel was opened for; close
609 // if that vehicle goes away or the active vehicle changes
610 on_ActiveVehicleChanged: close()
614 sourceComponent: Component {
616 spacing: ScreenTools.defaultFontPixelWidth / 2
619 Layout.fillWidth: true
620 text: qsTr("Cancel ROI")
622 root._activeVehicle.stopGuidedModeROI()
623 roiEditDropPanel.close()
628 Layout.fillWidth: true
629 text: qsTr("Edit Position")
631 roiEditPositionDialogFactory.open()
632 roiEditDropPanel.close()