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 ****************************************************************************/
14import QGroundControl.Controls
16/// General flight-path direction indicators for the GeoMap: one arrow per
17/// entry in MissionController.directionArrows (added to the second flight
18/// path segment and every 5 segments thereafter, regardless of simple vs
19/// complex item — see MissionController::_recalcFlightPathSegments),
20/// mirroring the MapLineArrow Repeater in src/FlightMap/MapItems/PlanMapItems.qml.
24 property var missionController
26 property var surfaceModel
27 property real homeTerrainBias: 0 ///< See GeoMapWaypointItem.homeTerrainBias
30 model: root.missionController ? root.missionController.directionArrows : 0
34 objectName: "geoMapDirectionArrow"
36 surfaceModel: root.surfaceModel
37 // An endpoint altitude is NaN while a terrain-frame item waits on its terrain query: it would be
38 // projected at sea level, away from the route and the markers
39 visible: !isNaN(object.coord1AMSLAlt) && !isNaN(object.coord2AMSLAlt)
42 return _terrainLeg ? _drapedPoint(0.75 - _halfChordFraction)
43 : QtPositioning.coordinate(object.coordinate1.latitude, object.coordinate1.longitude,
44 object.coord1AMSLAlt + root.homeTerrainBias)
48 return _terrainLeg ? _drapedPoint(0.75 + _halfChordFraction)
49 : QtPositioning.coordinate(object.coordinate2.latitude, object.coordinate2.longitude,
50 object.coord2AMSLAlt + root.homeTerrainBias)
52 fraction: _terrainLeg ? 0.5 : 0.75
54 // Terrain-frame legs are draped over the DEM (see
55 // GeoMapMissionPath), so anchor the arrow to a short draped chord
56 // around the 0.75 mark rather than the straight AMSL chord: the
57 // chord midpoint puts the arrow on the ribbon and the chord ends
58 // give it the local tangent heading
59 readonly property bool _terrainLeg: !!root.surfaceModel && object.segmentType === FlightPathSegment.SegmentTypeTerrainFrame
61 // Cap the chord at 50 m so it stays local to the ribbon on long
62 // legs (a 10% chord averages away terrain curvature), while short
63 // legs keep enough screen separation for a stable heading
64 readonly property real _halfChordFraction: {
65 const len = object.coordinate1.distanceTo(object.coordinate2)
66 return len > 0 ? Math.min(0.05, 25 / len) : 0.05
69 // terrainHeightAt is not NOTIFY-reactive; read in the coordinate
70 // bindings above so they re-sample as DEM patches stream in
71 property int _terrainRev: 0
73 // Same AGL-ramp draping as GeoMapMissionPath._appendTerrainLeg
74 function _drapedPoint(f) {
75 const c1 = object.coordinate1
76 const c2 = object.coordinate2
77 const point = c1.atDistanceAndAzimuth(c1.distanceTo(c2) * f, c1.azimuthTo(c2))
78 const agl1 = object.coord1AMSLAlt - root.surfaceModel.terrainHeightAt(c1)
79 const agl2 = object.coord2AMSLAlt - root.surfaceModel.terrainHeightAt(c2)
80 return QtPositioning.coordinate(point.latitude, point.longitude,
81 root.surfaceModel.terrainHeightAt(point) + agl1 + ((agl2 - agl1) * f) + root.homeTerrainBias)
85 target: root.surfaceModel
86 enabled: arrow._terrainLeg
87 function onTerrainHeightsChanged() { arrow._terrainRev++ }