QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RallyPointMapVisuals.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtLocation
4import QtPositioning
5
6import QGroundControl
7import QGroundControl.Controls
8import QGroundControl.FlightMap
9
10/// Rally Point map visuals
11Item {
12 id: _root
13 z: QGroundControl.zOrderMapItems
14
15 property var map
16 property var myRallyPointController
17 property bool interactive: false ///< true: user can interact with items
18 property bool planView: false ///< true: visuals showing in plan view
19
20 property bool _interactive: interactive
21 property var _rallyPointsComponent
22 property bool _rallyPointsSupported: myRallyPointController.supported
23 property var _rallyPoints: myRallyPointController.points
24
25 Component.onCompleted: {
26 _rallyPointsComponent = rallyPointsComponent.createObject(map)
27 }
28
29 Component.onDestruction: {
30 _rallyPointsComponent.destroy()
31 }
32
33 Component {
34 id: dragAreaComponent
35
36 MissionItemIndicatorDrag {
37 mapControl: _root.map
38 itemCoordinate: rallyPointObject.coordinate
39 visible: rallyPointObject === myRallyPointController.currentRallyPoint && _root.interactive
40
41 property var rallyPointObject
42
43 // The drag only moves the point. Its altitude is read live because the drag breaks the itemCoordinate binding
44 onItemCoordinateChanged: rallyPointObject.coordinate = QtPositioning.coordinate(itemCoordinate.latitude, itemCoordinate.longitude, rallyPointObject.coordinate.altitude)
45
46 // A PX4 AMSL altitude is the ground height under the point, so it is read again where the point lands
47 onDragStop: {
48 const vehicle = myRallyPointController.masterController.controllerVehicle
49 if (vehicle && vehicle.px4Firmware && rallyPointObject.altitudeFrame === QGroundControl.AltitudeFrameAbsolute) {
50 rallyPointObject.useTerrainAltitude()
51 }
52 }
53 }
54 }
55
56 Component {
57 id: rallyPointComponent
58
59 MapQuickItem {
60 id: itemIndicator
61 anchorPoint.x: sourceItem.anchorPointX
62 anchorPoint.y: sourceItem.anchorPointY
63 z: QGroundControl.zOrderMapItems
64 opacity: _root.opacity
65
66 property var rallyPointObject
67
68 sourceItem: MissionItemIndexLabel {
69 id: itemIndexLabel
70 label: qsTr("R", "rally point map item label")
71 checked: _editingLayer == _layerRally ? rallyPointObject === myRallyPointController.currentRallyPoint : false
72 highlightSelected: true
73 onClicked: {
74 if (mainWindow.allowViewSwitch()) {
75 myRallyPointController.currentRallyPoint = rallyPointObject
76 }
77 }
78 }
79 }
80 }
81
82 // Add all rally points to the map
83 Component {
84 id: rallyPointsComponent
85
86 Repeater {
87 model: _rallyPoints
88
89 delegate: Item {
90 opacity: _root.opacity
91 property var _visuals: [ ]
92
93 Component.onCompleted: {
94 var rallyPointIndicator = rallyPointComponent.createObject(map)
95 rallyPointIndicator.coordinate = Qt.binding(function() { return object.coordinate })
96 rallyPointIndicator.rallyPointObject = Qt.binding(function() { return object })
97 map.addMapItem(rallyPointIndicator)
98 _visuals.push(rallyPointIndicator)
99
100 var dragArea = dragAreaComponent.createObject(map, { "itemIndicator": rallyPointIndicator, "rallyPointObject": object })
101 _visuals.push(dragArea)
102 }
103
104 Component.onDestruction: {
105 for (var i=0; i<_visuals.length; i++) {
106 _visuals[i].destroy()
107 }
108 _visuals = [ ]
109 }
110 }
111 }
112 }
113
114}