QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ProximityRadarMapView.qml
Go to the documentation of this file.
1import QtQuick
2import QtLocation
3import QtPositioning
4
5import QGroundControl
6import QGroundControl.Controls
7import QGroundControl.FlyView
8
9MapQuickItem {
10 id: _root
11 visible: proximityValues.telemetryAvailable && coordinate.isValid
12
13 property var vehicle /// Vehicle object, undefined for ADSB vehicle
14 property var map
15 property double heading: vehicle ? vehicle.heading.value : Number.NaN ///< Vehicle heading, NAN for none
16
17 anchorPoint.x: vehicleItem.width / 2
18 anchorPoint.y: vehicleItem.height / 2
19
20 property real _ratio: 1
21 property real _maxDistance: isNaN(proximityValues.maxDistance)
22
23 function calcSize() {
24 var scaleLinePixelLength = 100
25 var leftCoord = map.toCoordinate(Qt.point(0, 0), false /* clipToViewPort */)
26 var rightCoord = map.toCoordinate(Qt.point(scaleLinePixelLength, 0), false /* clipToViewPort */)
27 var scaleLineMeters = Math.round(leftCoord.distanceTo(rightCoord))
28 _ratio = scaleLinePixelLength / scaleLineMeters;
29 }
30
31 ProximityRadarValues {
32 id: proximityValues
33 vehicle: _root.vehicle
34 onRotationValueChanged: vehicleSensors.requestPaint()
35 }
36
37 Connections {
38 target: map
39 function onWidthChanged() { scaleTimer.restart() }
40 function onHeightChanged() { scaleTimer.restart() }
41 function onZoomLevelChanged() { scaleTimer.restart() }
42 }
43
44 Timer {
45 id: scaleTimer
46 interval: 100
47 running: false
48 repeat: false
49 onTriggered: calcSize()
50 }
51
52 sourceItem: Item {
53 id: vehicleItem
54 width: detectionLimitCircle.width
55 height: detectionLimitCircle.height
56 opacity: 0.5
57
58 Component.onCompleted: calcSize()
59
60 Canvas{
61 id: vehicleSensors
62 anchors.fill: detectionLimitCircle
63
64 transform: Rotation {
65 origin.x: detectionLimitCircle.width / 2
66 origin.y: detectionLimitCircle.height / 2
67 angle: isNaN(heading) ? 0 : heading
68 }
69
70 function deg2rad(degrees) {
71 var pi = Math.PI;
72 return degrees * (pi/180);
73 }
74
75 onPaint: {
76 var ctx = getContext("2d");
77 ctx.reset();
78 ctx.translate(width/2, height/2)
79 ctx.rotate(-Math.PI/2);
80 ctx.lineWidth = 5;
81 ctx.strokeStyle = Qt.rgba(1, 0, 0, 1);
82 for(var i=0; i<proximityValues.rgRotationValues.length; i++){
83 var rotationValue = proximityValues.rgRotationValues[i]
84 if (!isNaN(rotationValue)) {
85 var a=deg2rad(360-22.5)+Math.PI/4*i;
86 ctx.beginPath();
87 ctx.arc(0, 0, rotationValue * _ratio, a, a + Math.PI/4,false);
88 ctx.stroke();
89 }
90 }
91 }
92 }
93
94 Rectangle {
95 id: detectionLimitCircle
96 width: proximityValues.maxDistance * 2 *_ratio
97 height: proximityValues.maxDistance * 2 *_ratio
98 anchors.fill: detectionLimitCircle
99 color: Qt.rgba(1,1,1,0)
100 border.color: Qt.rgba(1,1,1,1)
101 border.width: 5
102 radius: width * 0.5
103
104 transform: Rotation {
105 origin.x: detectionLimitCircle.width / 2
106 origin.y: detectionLimitCircle.height / 2
107 angle: isNaN(heading) ? 0 : heading
108 }
109 }
110
111 }
112}