QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GeoMapMissionLabel.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
10pragma ComponentBehavior: Bound
11
12import QtQuick
13import QtQuick3D
14
15import QGroundControl
16import QGroundControl.Controls
17import QGroundControl.GeoMap
18
19import "GeoMapAltitude.js" as GeoMapAltitude
20
21/// Point marker for complex mission item visuals: same colored dot that
22/// crossfades into a 3D sphere as GeoMapWaypointItem, plus an always-visible
23/// side text label (e.g. "Loiter", "Land").
24GeoMapItem {
25 id: root
26
27 property int index: -1 ///< Sequence number shown in the dot; < 0 shows none
28 property string label: ""
29 property bool checked: false
30 property real size: ScreenTools.defaultFontPixelHeight * 1.5
31 property bool pickable: false ///< The marker takes clicks and drags; false lets them through to the map
32 property bool draggable: false ///< The marker can be dragged; the map is not panned meanwhile
33 property bool groundMarker: false ///< A position on the ground: lies flat on the terrain in 3D instead of a sphere
34 property var dragHeightAt: null ///< function(coordinate): height in meters at a position, for markers whose height follows it
35
36 // Same conventions as GeoMapWaypointItem / MissionItemIndexLabel:
37 // checked is "green" and grown, everything else the plain indicator color
38 readonly property color _markerColor: root.checked ? "green" : qgcPal.mapIndicator
39 readonly property real _indicatorSize: root.checked ? root.size : root.size * 0.75
40
41 readonly property var _camera: scene ? scene.camera : null
42
43 // Constant apparent size, same technique as GeoMapWaypointItem: scene
44 // units per screen pixel at the camera's look-at distance. Built-in
45 // QtQuick3D meshes are 100 units across.
46 readonly property real _modelScale: _camera
47 ? root._indicatorSize * _camera.distance * _camera.unitsPerPixelAtUnitDistance / 100
48 : 1
49
50 readonly property real _groundOpacity: root.groundMarker && root.scene ? root.scene.terrainScale : 0
51
52 // Ground meters for the dot's radius at the marker's own camera distance; the scene is in mercator units,
53 // which are 1/cos(latitude) ground meters
54 readonly property real _groundRadiusMeters: {
55 if (!root.groundMarker || !root._camera || !root.coordinate.isValid) {
56 return 0
57 }
58 const markerDistance = root._camera.scenePosition.minus(root.scenePosition).length()
59 return (root._indicatorSize / 2) * markerDistance * root._camera.unitsPerPixelAtUnitDistance
60 * Math.cos(root.coordinate.latitude * Math.PI / 180)
61 }
62
63 signal clicked()
64 signal dragged(var coordinate) ///< Position the marker was dragged to
65 signal dragFinished()
66
67 objectName: "geoMapMissionLabel"
68 width: size
69 height: size
70 anchorPoint: Qt.point(width / 2, height / 2)
71 crossfade3D: !groundMarker
72 delegate3D: groundMarker ? null : sphereComponent
73 // altitudeMode defaults to ClampToGround (GeoMapItem); callers may override
74
75 QGCPalette { id: qgcPal; colorGroupEnabled: root.enabled }
76
77 // A ground marker lies flat on the terrain in 3D, the same size as the dot it replaces
78 GeoMapCircle {
79 objectName: "geoMapGroundMarkerCircle"
80 x: -root.x
81 y: -root.y
82 visible: root.groundMarker && opacity > 0
83 opacity: root._groundOpacity
84 scene: root.scene
85 surfaceModel: root.surfaceModel
86 center: root.coordinate
87 radiusMeters: root._groundRadiusMeters
88 strokeColor: "transparent"
89 strokeWidth: 0
90 fillColor: root._markerColor
91 }
92
93 Rectangle {
94 anchors.centerIn: parent
95 width: root._indicatorSize
96 height: root._indicatorSize
97 radius: width / 2
98 color: root._markerColor
99 opacity: root.groundMarker ? 1 - root._groundOpacity : root.contentOpacity2D
100 }
101
102 QGCLabel {
103 anchors.centerIn: parent
104 // MissionItemIndexLabel convention: single-char label lives inside the dot
105 text: root.index >= 0 ? root.index : (root.label.length === 1 ? root.label : "")
106 color: "white"
107 font.bold: true
108 }
109
110 GeoMapMarkerMouseArea {
111 anchors.fill: parent
112 marker: root
113 enabled: root.pickable
114 draggable: root.draggable
115
116 onMarkerClicked: root.clicked()
117 onDragFinished: root.dragFinished()
118 onDragged: (target) => {
119 // Absolute markers sit on the horizontal plane at their altitude, ground-clamped ones on the rendered terrain
120 const camera = root.scene.camera
121 const coordinate = root.altitudeMode === GeoMapItem.Absolute
122 ? GeoMapAltitude.coordinateUnderCursor(camera, target, root.scenePosition.z,
123 root.scene.verticalScale * root.scene.terrainScale, root.dragHeightAt)
124 : root.surfaceModel.surfaceCoordinateAtScreenPoint(camera, target, root.scene.verticalScale * root.scene.terrainScale)
125 if (coordinate.isValid) {
126 root.dragged(coordinate)
127 }
128 }
129 }
130
131 GeoMapDropShadow {
132 id: dropShadow
133 objectName: "geoMapDropShadow"
134 geoItem: root
135 indicatorSize: root._indicatorSize
136 }
137
138 Rectangle {
139 anchors.left: parent.right
140 anchors.leftMargin: ScreenTools.defaultFontPixelWidth / 2
141 anchors.verticalCenter: parent.verticalCenter
142 width: sideLabel.width + ScreenTools.defaultFontPixelWidth
143 height: sideLabel.height
144 radius: height / 2
145 color: root._markerColor
146 visible: root.label.length > 1
147
148 QGCLabel {
149 id: sideLabel
150 anchors.centerIn: parent
151 text: root.label
152 color: "white"
153 }
154 }
155
156 Component {
157 id: sphereComponent
158
159 Node {
160 Node {
161 scale: Qt.vector3d(root._modelScale, root._modelScale, root._modelScale)
162
163 Model {
164 source: "#Sphere"
165
166 materials: PrincipledMaterial {
167 baseColor: root._markerColor
168 }
169 }
170 }
171
172 GeoMapDropLine {
173 dropLength: dropShadow.dropLength
174 lineScale: dropShadow.dropLineScale
175 lineColor: root._markerColor
176 }
177 }
178 }
179}