7import QGroundControl.Controls
8import QGroundControl.FlightMap
13 property FlightMap mapControl
15 property color arrowColor: "white"
16 property var fromCoord: QtPositioning.coordinate()
17 property var toCoord: QtPositioning.coordinate()
18 property int arrowPosition: 1 ///< 1: first quarter, 2: halfway, 3: last quarter
20 property real _arrowSize: 15
21 property real _arrowHeading: 0
22 property real _screenLegLength: 0
24 function _updateArrowDetails() {
25 if (fromCoord && fromCoord.isValid && toCoord && toCoord.isValid) {
26 var lineDistanceQuarter = fromCoord.distanceTo(toCoord) / 4
27 coordinate = fromCoord.atDistanceAndAzimuth(lineDistanceQuarter * arrowPosition, fromCoord.azimuthTo(toCoord))
28 _arrowHeading = coordinate.azimuthTo(toCoord) // Account for changing bearing along great circle path
30 coordinate = QtPositioning.coordinate()
33 _updateScreenLegLength()
36 function _updateScreenLegLength() {
37 if (mapControl && fromCoord && fromCoord.isValid && toCoord && toCoord.isValid) {
38 const fromPoint = mapControl.fromCoordinate(fromCoord, false)
39 const toPoint = mapControl.fromCoordinate(toCoord, false)
40 _screenLegLength = Math.hypot(toPoint.x - fromPoint.x, toPoint.y - fromPoint.y)
46 onFromCoordChanged: _updateArrowDetails()
47 onToCoordChanged: _updateArrowDetails()
48 onMapControlChanged: _updateScreenLegLength()
50 Component.onCompleted: _updateArrowDetails()
53 target: root.mapControl
55 function onZoomLevelChanged() { root._updateScreenLegLength() }
63 visible: root._screenLegLength >= width
66 var ctx = getContext("2d");
68 ctx.strokeStyle = arrowColor
70 ctx.moveTo(_arrowSize, 0);
71 ctx.lineTo(_arrowSize * 2, _arrowSize)
74 ctx.moveTo(_arrowSize, 0);
75 ctx.lineTo(0, _arrowSize)