1/****************************************************************************
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
8 ****************************************************************************/
15import QGroundControl.Controls
16import QGroundControl.GeoMap
18import "GeoMapAltitude.js" as GeoMapAltitude
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.
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
41 readonly property bool hasMarker: item ? item.isSimpleItem && item.specifiesCoordinate : false
42 readonly property real smallIndicatorSize: size * 0.75
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: {
48 return item && isNaN(item.amslEntryAlt) && surfaceModel ? surfaceModel.terrainHeightAt(item.coordinate) : NaN
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(
56 item.isSimpleItem ? item.altitude.rawValue : NaN,
57 _pendingTerrainHeight,
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)
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
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
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
77 readonly property var _camera: scene ? scene.camera : null
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
87 signal dragged(var coordinate) ///< Horizontal position the marker was dragged to
89 function _coordinateUnderCursor(target) {
90 const heightAt = root._terrainRelative && root.surfaceModel
91 ? (coordinate) => root.surfaceModel.terrainHeightAt(coordinate) + root.item.altitude.rawValue
93 return GeoMapAltitude.coordinateUnderCursor(root.scene.camera, target, root.scenePosition.z,
94 root.scene.verticalScale * root.scene.terrainScale, heightAt)
97 objectName: "geoMapWaypointMarker"
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
108 delegate3D: Component {
111 scale: Qt.vector3d(root._modelScale, root._modelScale, root._modelScale)
116 materials: PrincipledMaterial {
117 baseColor: root._markerColor
123 dropLength: dropShadow.dropLength
124 lineScale: dropShadow.dropLineScale
125 lineColor: root._markerColor
130 QGCPalette { id: qgcPal; colorGroupEnabled: root.enabled }
133 anchors.centerIn: parent
134 width: root._indicatorSize
135 height: root._indicatorSize
137 color: root._markerColor
138 opacity: root.contentOpacity2D
141 // Matches MissionItemIndicator.qml's "extra circle to indicate selection"
143 anchors.centerIn: parent
144 width: root._indicatorSize * 1.4
148 border.color: Qt.rgba(1, 1, 1, 0.5)
150 opacity: root.contentOpacity2D
151 visible: root._isCurrentItem
155 anchors.centerIn: parent
156 text: root.item ? root.item.sequenceNumber : ""
162 anchors.horizontalCenter: parent.horizontalCenter
163 anchors.bottom: parent.bottom
166 font.pointSize: ScreenTools.smallFontPointSize
167 visible: root.grouped
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 {
175 enabled: root.pickable
176 draggable: root.draggable
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)
191 indicatorSize: root._indicatorSize
195 target: root.surfaceModel
196 enabled: !!root.item && isNaN(root.item.amslEntryAlt)
198 function onTerrainHeightsChanged() {