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
18/// Simple-mission waypoint marker for the GeoMap: a colored dot that
19/// crossfades into a 3D sphere, with an always-visible sequence-number label.
20/// Marker color matches the existing 2D FlyView convention (MissionItemIndexLabel):
21/// current item highlighted, everything else a plain indicator color.
22/// Renders nothing for complex mission items, the home item, or items with
23/// no real coordinate (e.g. RTL, which flies to home dynamically rather than
24/// a mission-encoded lat/lon) — see visible.
25GeoMapItem {
26 id: root
27
28 property var item ///< VisualMissionItem for this marker
29 // DEM-vs-home-AMSL bias (see GeoMapVehicleItem), computed once by the
30 // consumer for the active vehicle and shared across every marker instead
31 // of each one re-sampling the same DEM lookup independently
32 property real homeTerrainBias: 0
33 property real size: ScreenTools.defaultFontPixelHeight * 1.5
34 property bool collapsed: false ///< Drawn by another marker of its overlap group (see GeoMapMissionItems)
35 property bool grouped: false ///< Stands for an overlap group: shows a "…" badge
36
37 readonly property bool hasMarker: item ? item.isSimpleItem && item.specifiesCoordinate : false
38 readonly property real smallIndicatorSize: size * 0.75
39
40 signal clicked()
41
42 objectName: "geoMapWaypointMarker"
43 width: size
44 height: size
45 anchorPoint: Qt.point(width / 2, height / 2)
46 altitudeMode: GeoMapItem.Absolute
47 // item.amslEntryAlt is AMSL per QGC's own terrain-query pipeline, which
48 // can disagree with GeoMap's own DEM tiles; bias-corrected the same way
49 // GeoMapVehicleItem aligns the vehicle marker to the rendered mesh
50 coordinate: item ? QtPositioning.coordinate(item.coordinate.latitude,
51 item.coordinate.longitude,
52 item.amslEntryAlt + homeTerrainBias)
53 : QtPositioning.coordinate()
54 visible: hasMarker && !collapsed
55
56 QGCPalette { id: qgcPal; colorGroupEnabled: root.enabled }
57
58 // Matches MissionItemIndicator.qml's _isCurrentItem exactly: current item
59 // (or a complex item with a current child) is highlighted
60 readonly property bool _isCurrentItem: item ? (item.isCurrentItem || item.hasCurrentChildItem) : false
61
62 // Matches MissionItemIndexLabel.qml's existing convention: current item
63 // is "green", everything else is the plain map indicator color
64 readonly property color _markerColor: root._isCurrentItem ? "green" : qgcPal.mapIndicator
65
66 // MissionItemIndexLabel also grows the indicator for the current item
67 // (small: !checked) and for a group; mirrored here for both the 2D dot and 3D sphere
68 readonly property real _indicatorSize: (root._isCurrentItem || root.grouped) ? root.size : root.smallIndicatorSize
69
70 readonly property var _camera: scene ? scene.camera : null
71
72 // Constant apparent size, same technique as GeoMapVehicleItem: scene
73 // units per screen pixel at the camera's look-at distance. Built-in
74 // QtQuick3D meshes are 100 units across.
75 readonly property real _modelScale: _camera
76 ? root._indicatorSize * _camera.distance * _camera.unitsPerPixelAtUnitDistance / 100
77 : 1
78
79 Rectangle {
80 anchors.centerIn: parent
81 width: root._indicatorSize
82 height: root._indicatorSize
83 radius: width / 2
84 color: root._markerColor
85 opacity: root.contentOpacity2D
86 }
87
88 // Matches MissionItemIndicator.qml's "extra circle to indicate selection"
89 Rectangle {
90 anchors.centerIn: parent
91 width: root._indicatorSize * 1.4
92 height: width
93 radius: width / 2
94 color: "transparent"
95 border.color: Qt.rgba(1, 1, 1, 0.5)
96 border.width: 1
97 opacity: root.contentOpacity2D
98 visible: root._isCurrentItem
99 }
100
101 QGCLabel {
102 anchors.centerIn: parent
103 text: root.item ? root.item.sequenceNumber : ""
104 color: "white"
105 font.bold: true
106 }
107
108 QGCLabel {
109 anchors.horizontalCenter: parent.horizontalCenter
110 anchors.bottom: parent.bottom
111 text: "…"
112 color: "white"
113 font.pointSize: ScreenTools.smallFontPointSize
114 visible: root.grouped
115 }
116
117 // The item itself tracks the projected marker position at any tilt, so
118 // this hit target follows the 3D sphere through the 2D<->3D crossfade
119 MouseArea {
120 anchors.fill: parent
121 onClicked: root.clicked()
122 }
123
124 GeoMapDropShadow {
125 id: dropShadow
126 geoItem: root
127 indicatorSize: root._indicatorSize
128 }
129
130 delegate3D: Component {
131 Node {
132 Node {
133 scale: Qt.vector3d(root._modelScale, root._modelScale, root._modelScale)
134
135 Model {
136 source: "#Sphere"
137
138 materials: PrincipledMaterial {
139 baseColor: root._markerColor
140 }
141 }
142 }
143
144 GeoMapDropLine {
145 dropLength: dropShadow.dropLength
146 lineScale: dropShadow.dropLineScale
147 lineColor: root._markerColor
148 }
149 }
150 }
151}