VehicleMapItem.qml 4.27 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10 11 12 13
import QtQuick              2.3
import QtLocation           5.3
import QtPositioning        5.3
import QtGraphicalEffects   1.0
14

15
import QGroundControl               1.0
16 17
import QGroundControl.ScreenTools   1.0
import QGroundControl.Vehicle       1.0
18
import QGroundControl.Controls      1.0
19 20 21

/// Marker for displaying a vehicle location on the map
MapQuickItem {
22 23 24
    property var    vehicle                                                         /// Vehicle object, undefined for ADSB vehicle
    property var    map
    property double altitude:       Number.NaN                                      ///< NAN to not show
25
    property string callsign:       ""                                              ///< Vehicle callsign
26 27
    property double heading:        vehicle ? vehicle.heading.value : Number.NaN    ///< Vehicle heading, NAN for none
    property real   size:           _adsbVehicle ? _adsbSize : _uavSize             /// Size for icon
Gus Grubba's avatar
Gus Grubba committed
28
    property bool   alert:          false                                           /// Collision alert
29 30 31 32 33 34 35

    anchorPoint.x:  vehicleItem.width  / 2
    anchorPoint.y:  vehicleItem.height / 2
    visible:        coordinate.isValid

    property bool   _adsbVehicle:   vehicle ? false : true
    property real   _uavSize:       ScreenTools.defaultFontPixelHeight * 5
Gus Grubba's avatar
Gus Grubba committed
36
    property real   _adsbSize:      ScreenTools.defaultFontPixelHeight * 2.5
37
    property var    _map:           map
38
    property bool   _multiVehicle:  QGroundControl.multiVehicleManager.vehicles.count > 1
39 40

    sourceItem: Item {
41 42 43 44
        id:         vehicleItem
        width:      vehicleIcon.width
        height:     vehicleIcon.height
        opacity:    vehicle ? (vehicle.active ? 1.0 : 0.5) : 1.0
45

46 47 48 49 50 51 52 53
        Rectangle {
            id:                 vehicleShadow
            anchors.fill:       vehicleIcon
            color:              Qt.rgba(1,1,1,1)
            radius:             width * 0.5
            visible:            false
        }
        DropShadow {
Gus Grubba's avatar
Gus Grubba committed
54 55
            anchors.fill:       vehicleShadow
            visible:            vehicleIcon.visible && _adsbVehicle
56 57 58 59 60 61 62
            horizontalOffset:   4
            verticalOffset:     4
            radius:             32.0
            samples:            65
            color:              Qt.rgba(0.94,0.91,0,0.5)
            source:             vehicleShadow
        }
63 64
        Image {
            id:                 vehicleIcon
Gus Grubba's avatar
Gus Grubba committed
65
            source:             _adsbVehicle ? (alert ? "/qmlimages/AlertAircraft.svg" : "/qmlimages/AwarenessAircraft.svg") : vehicle.vehicleImageOpaque
66 67 68 69 70 71 72 73 74 75 76 77
            mipmap:             true
            width:              size
            sourceSize.width:   size
            fillMode:           Image.PreserveAspectFit
            transform: Rotation {
                origin.x:       vehicleIcon.width  / 2
                origin.y:       vehicleIcon.height / 2
                angle:          isNaN(heading) ? 0 : heading
            }
        }

        QGCMapLabel {
78
            id:                         vehicleLabel
79 80 81
            anchors.top:                parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
            map:                        _map
82
            text:                       vehicleLabelText
83
            font.pointSize:             _adsbVehicle ? ScreenTools.defaultFontPointSize : ScreenTools.smallFontPointSize
84 85 86
            visible:                    _adsbVehicle ? !isNaN(altitude) : _multiVehicle
            property string vehicleLabelText: visible ?
                                                  (_adsbVehicle ?
Remek Zajac's avatar
Remek Zajac committed
87
                                                       QGroundControl.unitsConversion.metersToAppSettingsHorizontalDistanceUnits(altitude).toFixed(0) + " " + QGroundControl.unitsConversion.appSettingsHorizontalDistanceUnitsString :
88 89
                                                       (_multiVehicle ? qsTr("Vehicle %1").arg(vehicle.id) : "")) :
                                                  ""
90

91 92 93
        }
    }
}