QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VehicleMapItem.qml
Go to the documentation of this file.
1import QtQuick
2import QtLocation
3import QtPositioning
4
5import QGroundControl
6import QGroundControl.Controls
7
8/// Marker for displaying a vehicle location on the map
9MapQuickItem {
10 id: _root
11
12 property var vehicle /// Vehicle object
13 property var map
14 property double heading: vehicle ? vehicle.heading.value : Number.NaN ///< Vehicle heading, NAN for none
15 property real size: ScreenTools.defaultFontPixelHeight * 3 /// Default size for icon, most usage overrides this
16
17 anchorPoint.x: vehicleItem.width / 2
18 anchorPoint.y: vehicleItem.height / 2
19 visible: coordinate.isValid
20
21 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
22 property var _map: map
23 property bool _multiVehicle: QGroundControl.multiVehicleManager.vehicles.count > 1
24
25 sourceItem: Item {
26 id: vehicleItem
27 width: vehicleIcon.width
28 height: vehicleIcon.height
29 opacity: vehicle === _activeVehicle ? 1.0 : 0.5
30
31 Repeater {
32 model: vehicle ? vehicle.gimbalController.gimbals : []
33
34 Item {
35 id: canvasItem
36 anchors.centerIn: vehicleItem
37 width: vehicleItem.width * 2
38 height: vehicleItem.height * 2
39 property var gimbalYaw: object.absoluteYaw.rawValue
40 rotation: gimbalYaw + 180
41 onGimbalYawChanged: canvas.requestPaint()
42 visible: vehicle && !isNaN(gimbalYaw) && QGroundControl.settingsManager.gimbalControllerSettings.showAzimuthIndicatorOnMap.rawValue
43 opacity: object === vehicle.gimbalController.activeGimbal ? 1.0 : 0.4
44
45 Canvas {
46 id: canvas
47 anchors.centerIn: canvasItem
48 anchors.verticalCenterOffset: vehicleItem.width
49 width: vehicleItem.width
50 height: vehicleItem.height
51
52 onPaint: paintHeading()
53
54 function paintHeading() {
55 var context = getContext("2d")
56 // console.log("painting heading " + object.param1Raw + " " + opacity + " " + visible + " " + _index)
57 context.clearRect(0, 0, vehicleIcon.width, vehicleIcon.height);
58
59 var centerX = canvas.width / 2;
60 var centerY = canvas.height / 2;
61 var length = canvas.height * 1.3
62 var width = canvas.width * 0.6
63
64 var point1 = [centerX - width , centerY + canvas.height * 0.6]
65 var point2 = [centerX, centerY - canvas.height * 0.5]
66 var point3 = [centerX + width , centerY + canvas.height * 0.6]
67 var point4 = [centerX, centerY + canvas.height * 0.2]
68
69 // Draw the arrow
70 context.save();
71 context.globalAlpha = 0.9;
72 context.beginPath();
73 context.moveTo(centerX, centerY + canvas.height * 0.2);
74 context.lineTo(point1[0], point1[1]);
75 context.lineTo(point2[0], point2[1]);
76 context.lineTo(point3[0], point3[1]);
77 context.lineTo(point4[0], point4[1]);
78 context.closePath();
79
80 const gradient = context.createLinearGradient(canvas.width / 2, canvas.height , canvas.width / 2, 0);
81 gradient.addColorStop(0.3, Qt.rgba(255,255,255,0));
82 gradient.addColorStop(0.5, Qt.rgba(255,255,255,0.5));
83 gradient.addColorStop(1, qgcPal.mapIndicator);
84
85 context.fillStyle = gradient;
86 context.fill();
87 context.restore();
88 }
89 }
90 }
91 }
92
93 Image {
94 id: vehicleIcon
95 source: vehicle ? vehicle.vehicleImageOpaque : ""
96 mipmap: true
97 width: _root.size
98 sourceSize.width: _root.size
99 fillMode: Image.PreserveAspectFit
100 transform: Rotation {
101 origin.x: vehicleIcon.width / 2
102 origin.y: vehicleIcon.height / 2
103 angle: isNaN(heading) ? 0 : heading
104 }
105 }
106
107 QGCMapLabel {
108 id: vehicleLabel
109 anchors.top: parent.bottom
110 anchors.horizontalCenter: parent.horizontalCenter
111 map: _map
112 text: visible && vehicle ? qsTr("Vehicle %1").arg(vehicle.id) : ""
113 font.pointSize: ScreenTools.smallFontPointSize
114 visible: _multiVehicle
115 }
116 }
117}