QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MapLineArrow.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtLocation
4import QtPositioning
5
6import QGroundControl
7import QGroundControl.Controls
8import QGroundControl.FlightMap
9
10MapQuickItem {
11 property color arrowColor: "white"
12 property var fromCoord: QtPositioning.coordinate()
13 property var toCoord: QtPositioning.coordinate()
14 property int arrowPosition: 1 ///< 1: first quarter, 2: halfway, 3: last quarter
15
16 property var _map: parent
17 property real _arrowSize: 15
18 property real _arrowHeading: 0
19
20 function _updateArrowDetails() {
21 if (fromCoord && fromCoord.isValid && toCoord && toCoord.isValid) {
22 var lineDistanceQuarter = fromCoord.distanceTo(toCoord) / 4
23 coordinate = fromCoord.atDistanceAndAzimuth(lineDistanceQuarter * arrowPosition, fromCoord.azimuthTo(toCoord))
24 _arrowHeading = coordinate.azimuthTo(toCoord) // Account for changing bearing along great circle path
25 } else {
26 coordinate = QtPositioning.coordinate()
27 _arrowHeading = 0
28 }
29 }
30
31 onFromCoordChanged: _updateArrowDetails()
32 onToCoordChanged: _updateArrowDetails()
33
34 sourceItem: Canvas {
35 x: -_arrowSize
36 y: 0
37 width: _arrowSize * 2
38 height: _arrowSize
39
40 onPaint: {
41 var ctx = getContext("2d");
42 ctx.lineWidth = 2
43 ctx.strokeStyle = arrowColor
44 ctx.beginPath();
45 ctx.moveTo(_arrowSize, 0);
46 ctx.lineTo(_arrowSize * 2, _arrowSize)
47 ctx.stroke();
48 ctx.beginPath();
49 ctx.moveTo(_arrowSize, 0);
50 ctx.lineTo(0, _arrowSize)
51 ctx.stroke();
52 }
53
54 transform: Rotation {
55 origin.x: width / 2
56 origin.y: 0
57 angle: _arrowHeading
58 }
59 }
60}