6import QGroundControl.Controls
8/// Marker for displaying a vehicle location on the map
12 property var vehicle /// Vehicle object
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
17 anchorPoint.x: vehicleItem.width / 2
18 anchorPoint.y: vehicleItem.height / 2
19 visible: coordinate.isValid
21 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
22 property var _map: map
23 property bool _multiVehicle: QGroundControl.multiVehicleManager.vehicles.count > 1
27 width: vehicleIcon.width
28 height: vehicleIcon.height
29 opacity: vehicle === _activeVehicle ? 1.0 : 0.5
32 model: vehicle ? vehicle.gimbalController.gimbals : []
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
47 anchors.centerIn: canvasItem
48 anchors.verticalCenterOffset: vehicleItem.width
49 width: vehicleItem.width
50 height: vehicleItem.height
52 onPaint: paintHeading()
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);
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
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]
71 context.globalAlpha = 0.9;
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]);
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);
85 context.fillStyle = gradient;
95 source: vehicle ? vehicle.vehicleImageOpaque : ""
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
109 anchors.top: parent.bottom
110 anchors.horizontalCenter: parent.horizontalCenter
112 text: visible && vehicle ? qsTr("Vehicle %1").arg(vehicle.id) : ""
113 font.pointSize: ScreenTools.smallFontPointSize
114 visible: _multiVehicle