QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PlanViewGeoMap.qml
Go to the documentation of this file.
1import QtQuick
2import QtPositioning
3
4import QGroundControl
5import QGroundControl.Controls
6import QGroundControl.FlightMap
7import QGroundControl.GeoMap
8
9/// GeoMap-engine drop-in for the QtLocation FlightMap of Plan View. GeoMapView provides the editorMap contract Plan
10/// View and its panels consume (center, zoomLevel, toCoordinate/fromCoordinate, setVisibleRegion, mapClicked, ...).
11/// The plan is displayed, and the current simple mission item and rally point can be dragged. Editing fence points
12/// and pattern items on this map is not supported yet.
13GeoMapView {
14 id: root
15
16 property var planMasterController
17 property rect centerViewport: Qt.rect(0, 0, width, height) ///< Part of the map not covered by Plan View tools
18 property real missionOpacity: 1 ///< Dims the mission while another layer is edited
19 property bool missionInteractive: false ///< The current mission item can be dragged on the map
20 property real rallyOpacity: 1 ///< Dims the rally points while another layer is edited
21 property bool rallyInteractive: false ///< Rally points can be selected and the current one dragged
22 property real _nonInteractiveOpacity: 0.5 ///< Consumed by the Plan View panels
23
24 readonly property var _missionController: planMasterController ? planMasterController.missionController : null
25 readonly property var _rallyPointController: planMasterController ? planMasterController.rallyPointController : null
26 readonly property var _geoFenceController: planMasterController ? planMasterController.geoFenceController : null
27 readonly property var _plannedHomePosition: _missionController ? _missionController.plannedHomePosition : QtPositioning.coordinate()
28
29 property var _missionItemSelectionPanel: null
30
31 /// A mission item marker was picked on the map
32 signal itemSelected(int sequenceNumber)
33
34 function _closeMissionItemSelectionPanel() {
35 if (_missionItemSelectionPanel) {
36 _missionItemSelectionPanel.close()
37 }
38 }
39
40 allowGCSLocationCenter: true
41 allowVehicleLocationCenter: true
42 // The plan is edited away from the vehicle: only the one-time centering applies
43 followOffscreenVehicle: false
44
45 GeoMapPin {
46 scene: root.scene
47 surfaceModel: root.surfaceModel
48 coordinate: root._plannedHomePosition
49 visible: root._plannedHomePosition.isValid
50 label: qsTr("H")
51 }
52
53 Repeater {
54 model: QGroundControl.multiVehicleManager.vehicles
55
56 GeoMapVehicleItem {
57 scene: root.scene
58 surfaceModel: root.surfaceModel
59 vehicle: object
60 }
61 }
62
63 GeoMapMissionPath {
64 objectName: "geoMapMissionPath"
65 scene: root.scene
66 surfaceModel: root.surfaceModel
67 missionController: root._missionController
68 vehicle: root.planMasterController ? root.planMasterController.controllerVehicle : null
69 plannedHomePosition: root._plannedHomePosition
70 opacity: root.missionOpacity
71 }
72
73 GeoMapMissionItems {
74 scene: root.scene
75 surfaceModel: root.surfaceModel
76 missionController: root._missionController
77 opacity: root.missionOpacity
78 interactive: root.missionInteractive
79 pickable: root.missionInteractive
80 onItemClicked: (item) => root.itemSelected(item.sequenceNumber)
81 // Dragging only moves the item horizontally: its altitude is kept apart from its coordinate
82 onItemDragged: (item, coordinate) => item.coordinate = QtPositioning.coordinate(coordinate.latitude, coordinate.longitude)
83 onGroupClicked: (items, marker) => {
84 root._closeMissionItemSelectionPanel()
85 const topLeft = marker.mapToItem(globals.parent, 0, 0)
86 root._missionItemSelectionPanel = missionItemSelectionPanelComponent.createObject(mainWindow, {
87 clickRect: Qt.rect(topLeft.x, topLeft.y, marker.width, marker.height),
88 groupItems: items
89 })
90 if (root._missionItemSelectionPanel) {
91 root._missionItemSelectionPanel.open()
92 }
93 }
94 onGroupsInvalidated: root._closeMissionItemSelectionPanel()
95 }
96
97 GeoMapMissionDirectionArrows {
98 scene: root.scene
99 surfaceModel: root.surfaceModel
100 missionController: root._missionController
101 opacity: root.missionOpacity
102 }
103
104 GeoMapGeoFenceVisuals {
105 scene: root.scene
106 surfaceModel: root.surfaceModel
107 geoFenceController: root._geoFenceController
108 homePosition: root._plannedHomePosition
109 }
110
111 Repeater {
112 model: root._rallyPointController ? root._rallyPointController.points : undefined
113
114 GeoMapRallyPoint {
115 scene: root.scene
116 surfaceModel: root.surfaceModel
117 rallyPoint: object
118 vehicle: root.planMasterController ? root.planMasterController.controllerVehicle : null
119 homeAltitude: root._plannedHomePosition.altitude
120 checked: root.rallyInteractive && object === root._rallyPointController.currentRallyPoint
121 opacity: root.rallyOpacity
122 node3DOpacity: root.rallyOpacity
123 pickable: root.rallyInteractive
124 draggable: checked
125
126 onClicked: {
127 if (mainWindow.allowViewSwitch()) {
128 root._rallyPointController.currentRallyPoint = object
129 }
130 }
131 // The drag only moves the point horizontally, keeping its altitude
132 onDragged: (coordinate) => object.coordinate = QtPositioning.coordinate(coordinate.latitude, coordinate.longitude, object.coordinate.altitude)
133 // A PX4 AMSL altitude is the ground height under the point, so it is read again where the point lands
134 onDragFinished: {
135 const vehicle = root.planMasterController.controllerVehicle
136 if (vehicle && vehicle.px4Firmware && object.altitudeFrame === QGroundControl.AltitudeFrameAbsolute) {
137 object.useTerrainAltitude()
138 }
139 }
140 }
141 }
142
143 Component {
144 id: missionItemSelectionPanelComponent
145
146 MissionItemSelectionPanel {
147 id: missionItemSelectionPanel
148
149 onItemSelected: (sequenceNumber) => root.itemSelected(sequenceNumber)
150 onClosed: {
151 if (root._missionItemSelectionPanel === missionItemSelectionPanel) {
152 root._missionItemSelectionPanel = null
153 }
154 destroy()
155 }
156 }
157 }
158
159 // The picker lists the old mission's items: close it when the mission is replaced
160 Connections {
161 target: root._missionController
162
163 function onVisualItemsReset() {
164 root._closeMissionItemSelectionPanel()
165 }
166 }
167}