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 ****************************************************************************/
10pragma ComponentBehavior: Bound
16import QGroundControl.Controls
17import QGroundControl.GeoMap
19import "GeoMapAltitude.js" as GeoMapAltitude
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").
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
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
41 readonly property var _camera: scene ? scene.camera : null
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
50 readonly property real _groundOpacity: root.groundMarker && root.scene ? root.scene.terrainScale : 0
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) {
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)
64 signal dragged(var coordinate) ///< Position the marker was dragged to
67 objectName: "geoMapMissionLabel"
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
75 QGCPalette { id: qgcPal; colorGroupEnabled: root.enabled }
77 // A ground marker lies flat on the terrain in 3D, the same size as the dot it replaces
79 objectName: "geoMapGroundMarkerCircle"
82 visible: root.groundMarker && opacity > 0
83 opacity: root._groundOpacity
85 surfaceModel: root.surfaceModel
86 center: root.coordinate
87 radiusMeters: root._groundRadiusMeters
88 strokeColor: "transparent"
90 fillColor: root._markerColor
94 anchors.centerIn: parent
95 width: root._indicatorSize
96 height: root._indicatorSize
98 color: root._markerColor
99 opacity: root.groundMarker ? 1 - root._groundOpacity : root.contentOpacity2D
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 : "")
110 GeoMapMarkerMouseArea {
113 enabled: root.pickable
114 draggable: root.draggable
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)
133 objectName: "geoMapDropShadow"
135 indicatorSize: root._indicatorSize
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
145 color: root._markerColor
146 visible: root.label.length > 1
150 anchors.centerIn: parent
161 scale: Qt.vector3d(root._modelScale, root._modelScale, root._modelScale)
166 materials: PrincipledMaterial {
167 baseColor: root._markerColor
173 dropLength: dropShadow.dropLength
174 lineScale: dropShadow.dropLineScale
175 lineColor: root._markerColor