QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GeoMapWaypointItem.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 QtQuick3D
12import QtPositioning
13
14import QGroundControl
15import QGroundControl.Controls
16import QGroundControl.GeoMap
17
18import "GeoMapAltitude.js" as GeoMapAltitude
19
20/// Simple-mission waypoint marker for the GeoMap: a colored dot that
21/// crossfades into a 3D sphere, with an always-visible sequence-number label.
22/// Marker color matches the existing 2D FlyView convention (MissionItemIndexLabel):
23/// current item highlighted, everything else a plain indicator color.
24/// Renders nothing for complex mission items, the home item, or items with
25/// no real coordinate (e.g. RTL, which flies to home dynamically rather than
26/// a mission-encoded lat/lon) — see visible.
27GeoMapItem {
28 id: root
29
30 property var item ///< VisualMissionItem for this marker
31 // DEM-vs-home-AMSL bias (see GeoMapVehicleItem), computed once by the
32 // consumer for the active vehicle and shared across every marker instead
33 // of each one re-sampling the same DEM lookup independently
34 property real homeTerrainBias: 0
35 property real size: ScreenTools.defaultFontPixelHeight * 1.5
36 property bool collapsed: false ///< Drawn by another marker of its overlap group (see GeoMapMissionItems)
37 property bool grouped: false ///< Stands for an overlap group: shows a "…" badge
38 property bool draggable: false ///< The marker can be dragged to move its item; the map is not panned meanwhile
39 property bool pickable: true ///< The marker takes clicks and drags; false lets them through to the map
40
41 readonly property bool hasMarker: item ? item.isSimpleItem && item.specifiesCoordinate : false
42 readonly property real smallIndicatorSize: size * 0.75
43
44 // terrainHeightAt does not notify, so _terrainRev re-evaluates the fallback as terrain tiles arrive.
45 property int _terrainRev: 0
46 readonly property real _pendingTerrainHeight: {
47 root._terrainRev
48 return item && isNaN(item.amslEntryAlt) && surfaceModel ? surfaceModel.terrainHeightAt(item.coordinate) : NaN
49 }
50 // item.amslEntryAlt is AMSL per QGC's own terrain-query pipeline, which
51 // can disagree with GeoMap's own DEM tiles; bias-corrected the same way
52 // GeoMapVehicleItem aligns the vehicle marker to the rendered mesh.
53 // It is NaN while a terrain-frame item waits on its terrain query.
54 readonly property real _amsl: !item ? NaN : GeoMapAltitude.displayAmsl(
55 item.amslEntryAlt,
56 item.isSimpleItem ? item.altitude.rawValue : NaN,
57 _pendingTerrainHeight,
58 homeTerrainBias)
59
60 // Terrain-relative items stand at their height above the terrain, so moving one changes its height
61 readonly property bool _terrainRelative: !!item && item.isSimpleItem
62 && (item.altitudeFrame === QGroundControl.AltitudeFrameTerrain
63 || item.altitudeFrame === QGroundControl.AltitudeFrameCalcAboveTerrain)
64
65 // Matches MissionItemIndicator.qml's _isCurrentItem exactly: current item
66 // (or a complex item with a current child) is highlighted
67 readonly property bool _isCurrentItem: item ? (item.isCurrentItem || item.hasCurrentChildItem) : false
68
69 // Matches MissionItemIndexLabel.qml's existing convention: current item
70 // is "green", everything else is the plain map indicator color
71 readonly property color _markerColor: root._isCurrentItem ? "green" : qgcPal.mapIndicator
72
73 // MissionItemIndexLabel also grows the indicator for the current item
74 // (small: !checked) and for a group; mirrored here for both the 2D dot and 3D sphere
75 readonly property real _indicatorSize: (root._isCurrentItem || root.grouped) ? root.size : root.smallIndicatorSize
76
77 readonly property var _camera: scene ? scene.camera : null
78
79 // Constant apparent size, same technique as GeoMapVehicleItem: scene
80 // units per screen pixel at the camera's look-at distance. Built-in
81 // QtQuick3D meshes are 100 units across.
82 readonly property real _modelScale: _camera
83 ? root._indicatorSize * _camera.distance * _camera.unitsPerPixelAtUnitDistance / 100
84 : 1
85
86 signal clicked()
87 signal dragged(var coordinate) ///< Horizontal position the marker was dragged to
88
89 function _coordinateUnderCursor(target) {
90 const heightAt = root._terrainRelative && root.surfaceModel
91 ? (coordinate) => root.surfaceModel.terrainHeightAt(coordinate) + root.item.altitude.rawValue
92 : null
93 return GeoMapAltitude.coordinateUnderCursor(root.scene.camera, target, root.scenePosition.z,
94 root.scene.verticalScale * root.scene.terrainScale, heightAt)
95 }
96
97 objectName: "geoMapWaypointMarker"
98 width: size
99 height: size
100 anchorPoint: Qt.point(width / 2, height / 2)
101 altitudeMode: GeoMapItem.Absolute
102 coordinate: item ? QtPositioning.coordinate(item.coordinate.latitude,
103 item.coordinate.longitude,
104 _amsl + homeTerrainBias)
105 : QtPositioning.coordinate()
106 visible: hasMarker && !collapsed
107
108 delegate3D: Component {
109 Node {
110 Node {
111 scale: Qt.vector3d(root._modelScale, root._modelScale, root._modelScale)
112
113 Model {
114 source: "#Sphere"
115
116 materials: PrincipledMaterial {
117 baseColor: root._markerColor
118 }
119 }
120 }
121
122 GeoMapDropLine {
123 dropLength: dropShadow.dropLength
124 lineScale: dropShadow.dropLineScale
125 lineColor: root._markerColor
126 }
127 }
128 }
129
130 QGCPalette { id: qgcPal; colorGroupEnabled: root.enabled }
131
132 Rectangle {
133 anchors.centerIn: parent
134 width: root._indicatorSize
135 height: root._indicatorSize
136 radius: width / 2
137 color: root._markerColor
138 opacity: root.contentOpacity2D
139 }
140
141 // Matches MissionItemIndicator.qml's "extra circle to indicate selection"
142 Rectangle {
143 anchors.centerIn: parent
144 width: root._indicatorSize * 1.4
145 height: width
146 radius: width / 2
147 color: "transparent"
148 border.color: Qt.rgba(1, 1, 1, 0.5)
149 border.width: 1
150 opacity: root.contentOpacity2D
151 visible: root._isCurrentItem
152 }
153
154 QGCLabel {
155 anchors.centerIn: parent
156 text: root.item ? root.item.sequenceNumber : ""
157 color: "white"
158 font.bold: true
159 }
160
161 QGCLabel {
162 anchors.horizontalCenter: parent.horizontalCenter
163 anchors.bottom: parent.bottom
164 text: "…"
165 color: "white"
166 font.pointSize: ScreenTools.smallFontPointSize
167 visible: root.grouped
168 }
169
170 // The item itself tracks the projected marker position at any tilt, so
171 // this hit target follows the 3D sphere through the 2D<->3D crossfade
172 GeoMapMarkerMouseArea {
173 anchors.fill: parent
174 marker: root
175 enabled: root.pickable
176 draggable: root.draggable
177
178 onMarkerClicked: root.clicked()
179 onDragged: (target) => {
180 // The marker sits on the horizontal plane at its height, so it stays under the cursor at any tilt
181 const coordinate = root._coordinateUnderCursor(target)
182 if (coordinate.isValid) {
183 root.dragged(coordinate)
184 }
185 }
186 }
187
188 GeoMapDropShadow {
189 id: dropShadow
190 geoItem: root
191 indicatorSize: root._indicatorSize
192 }
193
194 Connections {
195 target: root.surfaceModel
196 enabled: !!root.item && isNaN(root.item.amslEntryAlt)
197
198 function onTerrainHeightsChanged() {
199 root._terrainRev++
200 }
201 }
202}