FlightMap.qml 6.31 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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9

10 11 12 13
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtLocation       5.3
import QtPositioning    5.3
14
import QtQuick.Dialogs  1.2
dogmaphobic's avatar
dogmaphobic committed
15

16
import QGroundControl                       1.0
dogmaphobic's avatar
dogmaphobic committed
17
import QGroundControl.FactSystem            1.0
18
import QGroundControl.Controls              1.0
19
import QGroundControl.FlightMap             1.0
20 21 22
import QGroundControl.ScreenTools           1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.Vehicle               1.0
23
import QGroundControl.QGCPositionManager    1.0
dogmaphobic's avatar
dogmaphobic committed
24

25 26
Map {
    id: _map
dogmaphobic's avatar
dogmaphobic committed
27

28 29
    zoomLevel:                  QGroundControl.flightMapZoom
    center:                     QGroundControl.flightMapPosition
30 31
    //-- Qt 5.9 has rotation gesture enabled by default. Here we limit the possible gestures.
    gesture.acceptedGestures:   MapGestureArea.PinchGesture | MapGestureArea.PanGesture | MapGestureArea.FlickGesture
32 33 34
    gesture.flickDeceleration:  3000
    plugin:                     Plugin { name: "QGroundControl" }

35 36
    property string mapName:                        'defaultMap'
    property bool   isSatelliteMap:                 activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1
37
    property var    gcsPosition:                    QGroundControl.qgcPositionManger.gcsPosition
38
    property var    gcsHeading:                     QGroundControl.qgcPositionManger.gcsHeading
39 40 41 42 43
    property bool   userPanned:                     false   ///< true: the user has manually panned the map
    property bool   allowGCSLocationCenter:         false   ///< true: map will center/zoom to gcs location one time
    property bool   allowVehicleLocationCenter:     false   ///< true: map will center/zoom to vehicle location one time
    property bool   firstGCSPositionReceived:       false   ///< true: first gcs position update was responded to
    property bool   firstVehiclePositionReceived:   false   ///< true: first vehicle position update was responded to
44
    property bool   planView:                       false   ///< true: map being using for Plan view, items should be draggable
45
    property var    qgcView
46

dogmaphobic's avatar
dogmaphobic committed
47 48
    readonly property real  maxZoomLevel: 20

49 50 51
    property var    _activeVehicle:                 QGroundControl.multiVehicleManager.activeVehicle
    property var    activeVehicleCoordinate:        _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()

52
    function setVisibleRegion(region) {
53
        // TODO: Is this still necessary with Qt 5.11?
54 55 56 57 58 59 60
        // This works around a bug on Qt where if you set a visibleRegion and then the user moves or zooms the map
        // and then you set the same visibleRegion the map will not move/scale appropriately since it thinks there
        // is nothing to do.
        _map.visibleRegion = QtPositioning.rectangle(QtPositioning.coordinate(0, 0), QtPositioning.coordinate(0, 0))
        _map.visibleRegion = region
    }

61 62 63 64 65 66 67 68
    function _possiblyCenterToVehiclePosition() {
        if (!firstVehiclePositionReceived && allowVehicleLocationCenter && activeVehicleCoordinate.isValid) {
            firstVehiclePositionReceived = true
            center = activeVehicleCoordinate
            zoomLevel = QGroundControl.flightMapInitialZoom
        }
    }

69
    function centerToSpecifiedLocation() {
70
        qgcView.showDialog(specifyMapPositionDialog, qsTr("Specify Position"), qgcView.showDialogDefaultWidth, StandardButton.Close)
71 72 73 74 75 76 77 78 79 80 81 82

    }

    Component {
        id: specifyMapPositionDialog

        EditPositionDialog {
            coordinate:             center
            onCoordinateChanged:    center = coordinate
        }
    }

83
    ExclusiveGroup { id: mapTypeGroup }
84

85 86 87 88 89 90
    // Center map to gcs location
    onGcsPositionChanged: {
        if (gcsPosition.isValid && allowGCSLocationCenter && !firstGCSPositionReceived && !firstVehiclePositionReceived) {
            firstGCSPositionReceived = true
            center = gcsPosition
            zoomLevel = QGroundControl.flightMapInitialZoom
91 92
        }
    }
93

94 95 96 97 98 99 100 101
    // We track whether the user has panned or not to correctly handle automatic map positioning
    Connections {
        target: gesture

        onPanFinished:      userPanned = true
        onFlickFinished:    userPanned = true
    }

102
    function updateActiveMapType() {
103 104
        var settings =  QGroundControl.settingsManager.flightMapSettings
        var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue
Don Gagne's avatar
Don Gagne committed
105
        for (var i = 0; i < _map.supportedMapTypes.length; i++) {
106
            if (fullMapName === _map.supportedMapTypes[i].name) {
Don Gagne's avatar
Don Gagne committed
107
                _map.activeMapType = _map.supportedMapTypes[i]
108
                return
Don Gagne's avatar
Don Gagne committed
109 110 111
            }
        }
    }
112

113 114 115 116 117 118
    onActiveVehicleCoordinateChanged: _possiblyCenterToVehiclePosition()

    Component.onCompleted: {
        updateActiveMapType()
        _possiblyCenterToVehiclePosition()
    }
119 120

    Connections {
121 122 123 124 125 126 127
        target:             QGroundControl.settingsManager.flightMapSettings.mapType
        onRawValueChanged:  updateActiveMapType()
    }

    Connections {
        target:             QGroundControl.settingsManager.flightMapSettings.mapProvider
        onRawValueChanged:  updateActiveMapType()
128 129
    }

130
    /// Ground Station location
131
    MapQuickItem {
132 133
        anchorPoint.x:  sourceItem.width / 2
        anchorPoint.y:  sourceItem.height / 2
134 135
        visible:        gcsPosition.isValid
        coordinate:     gcsPosition
136 137

        sourceItem: Image {
138 139
            id:             mapItemImage
            source:         isNaN(gcsHeading) ? "/res/QGCLogoFull" : "/res/QGCLogoArrow"
140 141 142
            mipmap:         true
            antialiasing:   true
            fillMode:       Image.PreserveAspectFit
143
            height:         ScreenTools.defaultFontPixelHeight * (isNaN(gcsHeading) ? 1.75 : 2.5 )
144
            sourceSize.height: height
145 146 147 148 149
            transform: Rotation {
                origin.x:       mapItemImage.width  / 2
                origin.y:       mapItemImage.height / 2
                angle:          isNaN(gcsHeading) ? 0 : gcsHeading
            }
150 151
        }
    }
152
} // Map