FlightMap.qml 3.87 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 14 15 16


/**
 * @file
 *   @brief QGC Map Background
 *   @author Gus Grubba <mavlink@grubba.com>
 */

17 18 19 20
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtLocation       5.3
import QtPositioning    5.3
dogmaphobic's avatar
dogmaphobic committed
21

22
import QGroundControl                       1.0
dogmaphobic's avatar
dogmaphobic committed
23
import QGroundControl.FactSystem            1.0
24
import QGroundControl.Controls              1.0
25
import QGroundControl.FlightMap             1.0
26 27 28
import QGroundControl.ScreenTools           1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.Vehicle               1.0
29
import QGroundControl.Mavlink               1.0
dogmaphobic's avatar
dogmaphobic committed
30

31 32
Map {
    id: _map
dogmaphobic's avatar
dogmaphobic committed
33

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

dogmaphobic's avatar
dogmaphobic committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    readonly property real  maxZoomLevel: 20
    property variant        scaleLengths: [5, 10, 25, 50, 100, 150, 250, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000]

    function formatDistance(meters)
    {
        var dist = Math.round(meters)
        if (dist > 1000 ){
            if (dist > 100000){
                dist = Math.round(dist / 1000)
            }
            else{
                dist = Math.round(dist / 100)
                dist = dist / 10
            }
            dist = dist + " km"
        }
        else{
            dist = dist + " m"
        }
        return dist
    }

59 60 61 62 63 64 65 66
    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
    }

67
    zoomLevel:                  18
68
    center:                     QGroundControl.lastKnownHomePosition
69
    gesture.flickDeceleration:  3000
70

71
    plugin: Plugin { name: "QGroundControl" }
72

Don Gagne's avatar
Don Gagne committed
73
    ExclusiveGroup { id: mapTypeGroup }
74

75
    property bool _initialMapPositionSet: false
dogmaphobic's avatar
dogmaphobic committed
76

77 78 79 80 81
    Connections {
        target: mainWindow
        onGcsPositionChanged: {
            if (!_initialMapPositionSet) {
                _initialMapPositionSet = true
Don Gagne's avatar
Don Gagne committed
82
                center = mainWindow.gcsPosition
83 84 85 86
            }
        }
    }

87
    function updateActiveMapType() {
88 89
        var settings =  QGroundControl.settingsManager.flightMapSettings
        var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue
Don Gagne's avatar
Don Gagne committed
90
        for (var i = 0; i < _map.supportedMapTypes.length; i++) {
91
            if (fullMapName === _map.supportedMapTypes[i].name) {
Don Gagne's avatar
Don Gagne committed
92
                _map.activeMapType = _map.supportedMapTypes[i]
93
                return
Don Gagne's avatar
Don Gagne committed
94 95 96
            }
        }
    }
97

98 99 100
    Component.onCompleted: updateActiveMapType()

    Connections {
101 102 103 104 105 106 107
        target:             QGroundControl.settingsManager.flightMapSettings.mapType
        onRawValueChanged:  updateActiveMapType()
    }

    Connections {
        target:             QGroundControl.settingsManager.flightMapSettings.mapProvider
        onRawValueChanged:  updateActiveMapType()
108 109
    }

110
    /// Ground Station location
111
    MapQuickItem {
112 113
        anchorPoint.x:  sourceItem.anchorPointX
        anchorPoint.y:  sourceItem.anchorPointY
114 115
        visible:        mainWindow.gcsPosition.isValid
        coordinate:     mainWindow.gcsPosition
dogmaphobic's avatar
dogmaphobic committed
116
        sourceItem:     MissionItemIndexLabel {
117 118 119
            label: "Q"
        }
    }
120
} // Map