FlightMap.qml 3.47 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
dogmaphobic's avatar
dogmaphobic committed
14

15
import QGroundControl                       1.0
dogmaphobic's avatar
dogmaphobic committed
16
import QGroundControl.FactSystem            1.0
17
import QGroundControl.Controls              1.0
18
import QGroundControl.FlightMap             1.0
19 20 21
import QGroundControl.ScreenTools           1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.Vehicle               1.0
22
import QGroundControl.Mavlink               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 30 31 32
    zoomLevel:                  QGroundControl.flightMapZoom
    center:                     QGroundControl.flightMapPosition
    gesture.flickDeceleration:  3000
    plugin:                     Plugin { name: "QGroundControl" }

33
    property string mapName:            'defaultMap'
34
    property bool   isSatelliteMap:     activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1
35
    property var    gcsPosition:        QtPositioning.coordinate()
36

dogmaphobic's avatar
dogmaphobic committed
37 38
    readonly property real  maxZoomLevel: 20

39 40 41 42 43 44 45 46
    function setVisibleRegion(region) {
        // 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
    }

47
    ExclusiveGroup { id: mapTypeGroup }
48

49 50 51
    // Update ground station position
    Connections {
        target: QGroundControl.qgcPositionManger
52

53 54 55 56 57 58
        onLastPositionUpdated: {
            if (valid && lastPosition.latitude && Math.abs(lastPosition.latitude)  > 0.001 && lastPosition.longitude && Math.abs(lastPosition.longitude)  > 0.001) {
                gcsPosition = QtPositioning.coordinate(lastPosition.latitude,lastPosition.longitude)
            }
        }
    }
59

60
    function updateActiveMapType() {
61 62
        var settings =  QGroundControl.settingsManager.flightMapSettings
        var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue
Don Gagne's avatar
Don Gagne committed
63
        for (var i = 0; i < _map.supportedMapTypes.length; i++) {
64
            if (fullMapName === _map.supportedMapTypes[i].name) {
Don Gagne's avatar
Don Gagne committed
65
                _map.activeMapType = _map.supportedMapTypes[i]
66
                return
Don Gagne's avatar
Don Gagne committed
67 68 69
            }
        }
    }
70

71 72 73
    Component.onCompleted: updateActiveMapType()

    Connections {
74 75 76 77 78 79 80
        target:             QGroundControl.settingsManager.flightMapSettings.mapType
        onRawValueChanged:  updateActiveMapType()
    }

    Connections {
        target:             QGroundControl.settingsManager.flightMapSettings.mapProvider
        onRawValueChanged:  updateActiveMapType()
81 82
    }

83
    /// Ground Station location
84
    MapQuickItem {
85 86
        anchorPoint.x:  sourceItem.anchorPointX
        anchorPoint.y:  sourceItem.anchorPointY
87 88
        visible:        gcsPosition.isValid
        coordinate:     gcsPosition
dogmaphobic's avatar
dogmaphobic committed
89
        sourceItem:     MissionItemIndexLabel {
90
        label:          "Q"
91 92
        }
    }
93
} // Map