QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FlyViewGeoMap.qml
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 *
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
7 *
8 ****************************************************************************/
9
10import QtQuick
11import QtQuick.Layouts
12import QtPositioning
13
14import QGroundControl
15import QGroundControl.Controls
16import QGroundControl.FlightMap
17import QGroundControl.GeoMap
18
19/// Fly-view 2D/3D map: the GeoMap-engine counterpart of FlyViewMap.
20/// Fly-view specific map content (vehicle items, trajectory, ...) lands here.
21GeoMapView {
22 id: root
23
24 allowGCSLocationCenter: true
25 allowVehicleLocationCenter: true
26 keepVehicleCentered: QGroundControl.settingsManager.flyViewSettings.keepMapCenteredOnVehicle.rawValue
27
28 // Guided-action indicators for the map click drop panel (FlyViewMapClickDropPanel)
29 readonly property var gotoIndicator: gotoLocationItem
30 readonly property var orbitIndicator: orbitMapCircle
31
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
37
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
45
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
49 } else {
50 root._activeVehicleHomeTerrainBias = 0
51 }
52 }
53
54 on_ActiveVehicleChanged: {
55 _updateActiveVehicleHomeTerrainBias()
56 _fuzzyVehicleDisplayAltitude = NaN
57 _updateFuzzyVehicleDisplayAltitude()
58 }
59 onSurfaceModelChanged: _updateActiveVehicleHomeTerrainBias()
60
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
65
66 readonly property real _fuzzyAltitudeDeadbandMeters: 1
67
68 function _updateFuzzyVehicleDisplayAltitude() {
69 if (!root._activeVehicle || isNaN(root._activeVehicle.coordinate.altitude)) {
70 root._fuzzyVehicleDisplayAltitude = NaN
71 return
72 }
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
76 }
77 }
78
79 on_ActiveVehicleHomeTerrainBiasChanged: _updateFuzzyVehicleDisplayAltitude()
80
81 function _withFuzzyVehicleAltitude(coord) {
82 if (!isNaN(root._fuzzyVehicleDisplayAltitude)) {
83 return QtPositioning.coordinate(coord.latitude, coord.longitude, root._fuzzyVehicleDisplayAltitude)
84 }
85 return QtPositioning.coordinate(coord.latitude, coord.longitude)
86 }
87
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)
94 }
95 return QtPositioning.coordinate(coord.latitude, coord.longitude)
96 }
97
98 property var _missionItemSelectionPanel: null
99
100 function _confirmSetWaypoint(sequenceNumber) {
101 globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionSetWaypoint,
102 Math.max(sequenceNumber, 1))
103 }
104
105 function _closeMissionItemSelectionPanel() {
106 if (_missionItemSelectionPanel) {
107 _missionItemSelectionPanel.close()
108 }
109 }
110
111 Connections {
112 target: root.surfaceModel
113
114 function onTerrainDataChanged() {
115 root._updateActiveVehicleHomeTerrainBias()
116 }
117 }
118
119 Connections {
120 target: root._activeVehicle
121
122 function onHomePositionChanged() {
123 root._updateActiveVehicleHomeTerrainBias()
124 }
125
126 function onCoordinateChanged() {
127 root._updateFuzzyVehicleDisplayAltitude()
128 }
129 }
130
131 // Vehicle home (launch) location
132 GeoMapPin {
133 scene: root.scene
134 surfaceModel: root.surfaceModel
135 coordinate: root._activeVehicle ? root._activeVehicle.homePosition : QtPositioning.coordinate()
136 visible: root._activeVehicle && root._activeVehicle.homePosition.isValid
137 label: qsTr("L")
138 }
139
140 Repeater {
141 model: QGroundControl.multiVehicleManager.vehicles
142
143 GeoMapVehicleItem {
144 scene: root.scene
145 surfaceModel: root.surfaceModel
146 vehicle: object
147 }
148 }
149
150 GeoMapFlightPath {
151 scene: root.scene
152 surfaceModel: root.surfaceModel
153 vehicle: root._activeVehicle
154 }
155
156 GeoMapMissionPath {
157 scene: root.scene
158 surfaceModel: root.surfaceModel
159 missionController: root._missionController
160 vehicle: root._activeVehicle
161 homeTerrainBias: root._activeVehicleHomeTerrainBias
162 }
163
164 GeoMapMissionItems {
165 scene: root.scene
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),
177 groupItems: items
178 })
179 if (root._missionItemSelectionPanel) {
180 root._missionItemSelectionPanel.open()
181 }
182 }
183 onGroupsInvalidated: root._closeMissionItemSelectionPanel()
184 }
185
186 // The picker lists the old mission's items: close it when the mission is replaced
187 Connections {
188 target: root._missionController
189
190 function onVisualItemsReset() { root._closeMissionItemSelectionPanel() }
191 }
192
193 Component {
194 id: missionItemSelectionPanelComponent
195
196 MissionItemSelectionPanel {
197 id: missionItemSelectionPanel
198
199 onItemSelected: (sequenceNumber) => root._confirmSetWaypoint(sequenceNumber)
200 onClosed: {
201 if (root._missionItemSelectionPanel === missionItemSelectionPanel) {
202 root._missionItemSelectionPanel = null
203 }
204 destroy()
205 }
206 }
207 }
208
209 GeoMapMissionDirectionArrows {
210 scene: root.scene
211 surfaceModel: root.surfaceModel
212 missionController: root._missionController
213 homeTerrainBias: root._activeVehicleHomeTerrainBias
214 }
215
216 // Allow custom builds to add map items (QGCCorePlugin::customGeoMapItems)
217 Repeater {
218 model: QGroundControl.corePlugin.customGeoMapItems
219
220 Loader {
221 Component.onCompleted: setSource(object.url, {
222 customMapObject: object,
223 scene: root.scene,
224 surfaceModel: root.surfaceModel
225 })
226 }
227 }
228
229 GeoMapGeoFenceVisuals {
230 scene: root.scene
231 surfaceModel: root.surfaceModel
232 geoFenceController: root._geoFenceController
233 homePosition: root._activeVehicle && root._activeVehicle.homePosition.isValid ? root._activeVehicle.homePosition : QtPositioning.coordinate()
234 }
235
236 // Rally points
237 Repeater {
238 model: root._rallyPointController ? root._rallyPointController.points : undefined
239
240 GeoMapRallyPoint {
241 scene: root.scene
242 surfaceModel: root.surfaceModel
243 rallyPoint: object
244 vehicle: root._activeVehicle
245 homeAltitude: root._activeVehicle ? root._activeVehicle.homePosition.altitude : NaN
246 homeTerrainBias: root._activeVehicleHomeTerrainBias
247 }
248 }
249
250 // Proximity sensor arcs per vehicle
251 Repeater {
252 model: QGroundControl.multiVehicleManager.vehicles
253
254 FlyViewGeoProximityRadar {
255 scene: root.scene
256 surfaceModel: root.surfaceModel
257 vehicle: object
258 }
259 }
260
261 // ADS-B traffic
262 Repeater {
263 model: QGroundControl.adsbVehicleManager.adsbVehicles
264
265 GeoMapADSBVehicleItem {
266 scene: root.scene
267 surfaceModel: root.surfaceModel
268 coordinate: object.coordinate
269 altitude: object.altitude
270 callsign: object.callsign
271 heading: object.heading
272 alert: object.alert
273 size: ScreenTools.defaultFontPixelHeight * 2.5
274 homeTerrainBias: root._activeVehicleHomeTerrainBias
275 }
276 }
277
278 // Camera trigger points: batched sprite layer (single draw call), since
279 // surveys can produce thousands of points
280 GeoMapSpriteLayer {
281 scene: root.scene
282 surfaceModel: root.surfaceModel
283 model: root._activeVehicle ? root._activeVehicle.cameraTriggerPoints : null
284 sprite: triggerIconSource
285 spriteSize: triggerIcon.width
286
287 CameraTriggerIcon { id: triggerIcon }
288 ShaderEffectSource {
289 id: triggerIconSource
290 sourceItem: triggerIcon
291 hideSource: true
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)
295 }
296 }
297
298 // GoTo Location forward flight circle visuals
299 GeoMapCircleVisuals {
300 id: fwdFlightGotoMapCircle
301 objectName: "flyViewGeoFwdFlightGotoCircle"
302 scene: root.scene
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
315
316 property alias coordinate: _fwdFlightGotoCircleModel.center
317 property alias radius: _fwdFlightGotoCircleModel.radius
318 property alias clockwiseRotation: _fwdFlightGotoCircleModel.clockwiseRotation
319
320 Component.onCompleted: globals.guidedControllerFlyView.fwdFlightGotoMapCircle = this
321
322 Binding {
323 target: _fwdFlightGotoCircleModel
324 property: "center"
325 value: gotoLocationItem.coordinate
326 }
327
328 function startLoiterRadiusEdit() {
329 _fwdFlightGotoCircleModel.interactive = true
330 }
331
332 // Called when loiter edit is confirmed
333 function actionConfirmed() {
334 _fwdFlightGotoCircleModel.interactive = false
335 _fwdFlightGotoCircleModel._commitRadius()
336 }
337
338 // Called when loiter edit is cancelled
339 function actionCancelled() {
340 _fwdFlightGotoCircleModel.interactive = false
341 _fwdFlightGotoCircleModel._restoreRadius()
342 }
343
344 QGCMapCircle {
345 id: _fwdFlightGotoCircleModel
346 interactive: false
347 showRotation: true
348 clockwiseRotation: true
349
350 property real _defaultLoiterRadius: root._flyViewSettings.forwardFlightGoToLocationLoiterRad.rawValue
351 property real _committedRadius
352
353 onCenterChanged: {
354 // Don't commit the radius in case this operation is undone
355 radius.rawValue = _defaultLoiterRadius
356 }
357
358 Component.onCompleted: {
359 radius.rawValue = _defaultLoiterRadius
360 _commitRadius()
361 }
362
363 function _commitRadius() {
364 _committedRadius = radius.rawValue
365 }
366
367 function _restoreRadius() {
368 radius.rawValue = _committedRadius
369 }
370 }
371 }
372
373 // GoTo Location visuals
374 GeoMapMissionLabel {
375 id: gotoLocationItem
376 objectName: "flyViewGeoGotoLocation"
377 scene: root.scene
378 surfaceModel: root.surfaceModel
379 visible: false
380 checked: true
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
384
385 readonly property bool inGotoFlightMode: root._activeVehicle ? root._activeVehicle.flightMode === root._activeVehicle.gotoFlightMode : false
386
387 property var _committedCoordinate: null
388
389 onInGotoFlightModeChanged: {
390 if (!inGotoFlightMode && gotoLocationItem.visible) {
391 // Hide goto indicator when vehicle falls out of guided mode
392 hide()
393 }
394 }
395
396 function show(coord) {
397 gotoLocationItem.coordinate = root._withVehicleAltitude(coord)
398 gotoLocationItem.visible = true
399 }
400
401 function hide() {
402 gotoLocationItem.visible = false
403 }
404
405 function actionConfirmed() {
406 _commitCoordinate()
407
408 // Commit the new radius which possibly changed
409 fwdFlightGotoMapCircle.actionConfirmed()
410
411 // We leave the indicator visible. The handling for onInGuidedModeChanged will hide it.
412 }
413
414 function actionCancelled() {
415 _restoreCoordinate()
416
417 // Also restore the loiter radius
418 fwdFlightGotoMapCircle.actionCancelled()
419 }
420
421 function _commitCoordinate() {
422 // Must deep copy
423 _committedCoordinate = QtPositioning.coordinate(coordinate.latitude, coordinate.longitude, coordinate.altitude)
424 }
425
426 function _restoreCoordinate() {
427 if (_committedCoordinate) {
428 coordinate = _committedCoordinate
429 } else {
430 hide()
431 }
432 }
433 }
434
435 // Orbit editing visuals
436 GeoMapCircleVisuals {
437 id: orbitMapCircle
438 objectName: "flyViewGeoOrbitCircle"
439 scene: root.scene
440 surfaceModel: root.surfaceModel
441 mapCircle: _orbitCircleModel
442 altitudeMode: !isNaN(_orbitCircleModel.center.altitude) ? GeoMapItem.Absolute : GeoMapItem.ClampToGround
443 visible: false
444
445 property alias center: _orbitCircleModel.center
446 property alias clockwiseRotation: _orbitCircleModel.clockwiseRotation
447 readonly property real defaultRadius: 30
448
449 Connections {
450 target: QGroundControl.multiVehicleManager
451 function onActiveVehicleChanged(activeVehicle) {
452 if (!activeVehicle) {
453 orbitMapCircle.visible = false
454 }
455 }
456 }
457
458 function show(coord) {
459 _orbitCircleModel.radius.rawValue = defaultRadius
460 _orbitCircleModel.center = root._withVehicleAltitude(coord)
461 orbitMapCircle.visible = true
462 }
463
464 function hide() {
465 orbitMapCircle.visible = false
466 }
467
468 function actionConfirmed() {
469 // Live orbit status is handled by telemetry so we hide here and telemetry will show again.
470 hide()
471 }
472
473 function actionCancelled() {
474 hide()
475 }
476
477 function radius() {
478 return _orbitCircleModel.radius.rawValue
479 }
480
481 Component.onCompleted: globals.guidedControllerFlyView.orbitMapCircle = orbitMapCircle
482
483 QGCMapCircle {
484 id: _orbitCircleModel
485 interactive: true
486 radius.rawValue: 30
487 showRotation: true
488 clockwiseRotation: true
489 }
490 }
491
492 // ROI Location visuals
493 GeoMapMissionLabel {
494 id: roiLocationItem
495 scene: root.scene
496 surfaceModel: root.surfaceModel
497 visible: root._activeVehicle && root._activeVehicle.isROIEnabled
498 checked: true
499 label: qsTr("ROI here", "Make this a Region Of Interest")
500
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()
505
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)
511
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)
519 : _roiCenter
520 altitudeMode: _haveComposedAltitude ? GeoMapItem.Absolute : GeoMapItem.ClampToGround
521
522 Connections {
523 target: root._activeVehicle
524 function onRoiCoordChanged(centerCoord) {
525 roiLocationItem._roiCenter = centerCoord
526 }
527 }
528
529 MouseArea {
530 anchors.fill: parent
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) })
534 dropPanel.open()
535 }
536 }
537 }
538
539 // Orbit telemetry visuals. ORBIT_EXECUTION_STATUS carries no altitude, so
540 // render at the vehicle's altitude (the vehicle flies on this ring)
541 GeoMapCircle {
542 id: orbitTelemetryCircle
543 scene: root.scene
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
549 }
550
551 GeoMapMissionLabel {
552 id: orbitCenterIndicator
553 scene: root.scene
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
558 checked: true
559 label: qsTr("Orbit", "Orbit waypoint")
560 }
561
562 QGCPopupDialogFactory {
563 id: roiEditPositionDialogFactory
564
565 dialogComponent: roiEditPositionDialogComponent
566 }
567
568 Component {
569 id: roiEditPositionDialogComponent
570
571 EditPositionDialog {
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
577
578 readonly property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
579 property var _openedForVehicle: null
580
581 Component.onCompleted: _openedForVehicle = _activeVehicle
582
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()
586
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)) {
592 return
593 }
594 roiLocationItem._roiCenter = coordinate
595 _openedForVehicle.guidedModeROI(coordinate, _openedForVehicle.roiRelativeAltitudeMeters)
596 }
597 }
598 }
599
600 Component {
601 id: roiEditDropPanelComponent
602
603 DropPanel {
604 id: roiEditDropPanel
605
606 readonly property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
607
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()
611
612 onClosed: destroy()
613
614 sourceComponent: Component {
615 ColumnLayout {
616 spacing: ScreenTools.defaultFontPixelWidth / 2
617
618 QGCButton {
619 Layout.fillWidth: true
620 text: qsTr("Cancel ROI")
621 onClicked: {
622 root._activeVehicle.stopGuidedModeROI()
623 roiEditDropPanel.close()
624 }
625 }
626
627 QGCButton {
628 Layout.fillWidth: true
629 text: qsTr("Edit Position")
630 onClicked: {
631 roiEditPositionDialogFactory.open()
632 roiEditDropPanel.close()
633 }
634 }
635 }
636 }
637 }
638 }
639}