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

10 11 12
import QtQuick          2.3
import QtLocation       5.3
import QtPositioning    5.3
13

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

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

    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
    property real   _adsbSize:      ScreenTools.defaultFontPixelHeight * 1.5
    property var    _map:           map
36
    property bool   _multiVehicle:  QGroundControl.multiVehicleManager.vehicles.count > 1
37 38

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

        Image {
            id:                 vehicleIcon
46
            source:             _adsbVehicle ? "/qmlimages/adsbVehicle.svg" : vehicle.vehicleImageOpaque
47 48 49 50 51 52 53 54 55 56 57 58 59
            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 {
60
            id:                         vehicleLabel
61 62 63
            anchors.top:                parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
            map:                        _map
64
            text:                       vehicleLabelText
65
            font.pointSize:             ScreenTools.smallFontPointSize
66
            visible:                    _adsbVehicle ? !isNaN(altitude) : _multiVehicle
67

68 69
            property string vehicleLabelText: visible ?
                                                  (_adsbVehicle ?
70
                                                       QGroundControl.metersToAppSettingsDistanceUnits(altitude).toFixed(0) + " " + QGroundControl.appSettingsDistanceUnitsString :
71 72
                                                       (_multiVehicle ? qsTr("Vehicle %1").arg(vehicle.id) : "")) :
                                                  ""
73

74
        }
75 76 77 78 79 80 81 82 83 84 85

        QGCMapLabel {
            anchors.top:                vehicleLabel.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
            map:                        _map
            text:                       vehicleLabelText
            font.pointSize:             ScreenTools.smallFontPointSize
            visible:                    _adsbVehicle ? !isNaN(altitude) : _multiVehicle

            property string vehicleLabelText: visible && _adsbVehicle ? callsign : ""
        }
86 87
    }
}