FlightDisplayViewMap.qml 10 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 13 14 15
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtLocation       5.3
import QtPositioning    5.3
import QtQuick.Dialogs  1.2
16 17 18 19 20 21 22 23 24 25 26

import QGroundControl               1.0
import QGroundControl.FlightDisplay 1.0
import QGroundControl.FlightMap     1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
import QGroundControl.Vehicle       1.0
import QGroundControl.Controllers   1.0

FlightMap {
27 28 29 30 31
    id:                         flightMap
    anchors.fill:               parent
    mapName:                    _mapName
    allowGCSLocationCenter:     !userPanned
    allowVehicleLocationCenter: !_keepVehicleCentered
32

33 34
    property alias  scaleState: mapScale.state

35
    property var    missionController
36 37
    property var    geoFenceController
    property var    rallyPointController
38
    property var    guidedActionsController
Don Gagne's avatar
Don Gagne committed
39
    property var    flightWidgets
40
    property var    rightPanelWidth
41
    property var    qgcView                             ///< QGCView control which contains this map
Don Gagne's avatar
Don Gagne committed
42

43 44
    property rect   centerViewport:             Qt.rect(0, 0, width, height)

45 46 47 48
    property var    _activeVehicle:             QGroundControl.multiVehicleManager.activeVehicle
    property var    _activeVehicleCoordinate:   _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
    property var    _gotoHereCoordinate:        QtPositioning.coordinate()
    property real   _toolButtonTopMargin:       parent.height - ScreenTools.availableHeight + (ScreenTools.defaultFontPixelHeight / 2)
49

50 51
    property bool   _disableVehicleTracking:    false
    property bool   _keepVehicleCentered:       _mainIsMap ? false : true
52

53
    // Track last known map position and zoom from Fly view in settings
54
    onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel
55
    onCenterChanged:    QGroundControl.flightMapPosition = center
56

57
    // When the user pans the map we stop responding to vehicle coordinate updates until the panRecenterTimer fires
58 59 60
    onUserPannedChanged: {
        _disableVehicleTracking = true
        panRecenterTimer.start()
61 62
    }

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    function pointInRect(point, rect) {
        return point.x > rect.x &&
                point.x < rect.x + rect.width &&
                point.y > rect.y &&
                point.y < rect.y + rect.height;
    }

    property real _animatedLatitudeStart
    property real _animatedLatitudeStop
    property real _animatedLongitudeStart
    property real _animatedLongitudeStop
    property real animatedLatitude
    property real animatedLongitude

    onAnimatedLatitudeChanged: flightMap.center = QtPositioning.coordinate(animatedLatitude, animatedLongitude)
    onAnimatedLongitudeChanged: flightMap.center = QtPositioning.coordinate(animatedLatitude, animatedLongitude)

    NumberAnimation on animatedLatitude { id: animateLat; from: _animatedLatitudeStart; to: _animatedLatitudeStop; duration: 1000 }
    NumberAnimation on animatedLongitude { id: animateLong; from: _animatedLongitudeStart; to: _animatedLongitudeStop; duration: 1000 }

    function animatedMapRecenter(fromCoord, toCoord) {
        _animatedLatitudeStart = fromCoord.latitude
        _animatedLongitudeStart = fromCoord.longitude
        _animatedLatitudeStop = toCoord.latitude
        _animatedLongitudeStop = toCoord.longitude
        animateLat.start()
        animateLong.start()
    }

    function recenterNeeded() {
93
        var vehiclePoint = flightMap.fromCoordinate(_activeVehicleCoordinate, false /* clipToViewport */)
94 95
        var centerViewport = Qt.rect(0, 0, width, height)
        return !pointInRect(vehiclePoint, centerViewport)
96 97 98
    }

    function updateMapToVehiclePosition() {
99 100
        // We let FlightMap handle first vehicle position
        if (firstVehiclePositionReceived && _activeVehicleCoordinate.isValid && !_disableVehicleTracking) {
101
            if (_keepVehicleCentered) {
102
                flightMap.center = _activeVehicleCoordinate
103
            } else {
DonLakeFlyer's avatar
DonLakeFlyer committed
104
                if (firstVehiclePositionReceived && recenterNeeded()) {
105
                    animatedMapRecenter(flightMap.center, _activeVehicleCoordinate)
106 107
                }
            }
108 109 110 111
        }
    }

    Timer {
112 113 114
        id:         panRecenterTimer
        interval:   10000
        running:    false
115 116

        onTriggered: {
117
            _disableVehicleTracking = false
118
            updateMapToVehiclePosition()
119 120 121
        }
    }

122 123 124 125 126 127 128
    Timer {
        interval:       500
        running:        true
        repeat:         true
        onTriggered:    updateMapToVehiclePosition()
    }

Don Gagne's avatar
Don Gagne committed
129
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
130
    QGCMapPalette { id: mapPal; lightColors: isSatelliteMap }
Don Gagne's avatar
Don Gagne committed
131

132 133
    Connections {
        target: missionController
134 135

        onNewItemsFromVehicle: {
136
            var visualItems = missionController.visualItems
137 138
            if (visualItems && visualItems.count != 1) {
                mapFitFunctions.fitMapViewportToMissionItems()
139
                firstVehiclePositionReceived = true
140 141
            }
        }
142 143
    }

144
    ExclusiveGroup {
Don Gagne's avatar
Don Gagne committed
145
        id: _mapTypeButtonsExclusiveGroup
146 147
    }

Don Gagne's avatar
Don Gagne committed
148 149 150 151 152 153 154
    MapFitFunctions {
        id:                         mapFitFunctions
        map:                        _flightMap
        usePlannedHomePosition:     false
        mapMissionController:      missionController
        mapGeoFenceController:     geoFenceController
        mapRallyPointController:   rallyPointController
155

Don Gagne's avatar
Don Gagne committed
156 157
        property real leftToolWidth:    toolStrip.x + toolStrip.width
    }
158

159 160
    // Add trajectory points to the map
    MapItemView {
161
        model: _mainIsMap ? _activeVehicle ? _activeVehicle.trajectoryPoints : 0 : 0
DonLakeFlyer's avatar
DonLakeFlyer committed
162 163

        delegate: MapPolyline {
Don Gagne's avatar
Don Gagne committed
164 165
            line.width: 3
            line.color: "red"
DonLakeFlyer's avatar
DonLakeFlyer committed
166
            z:          QGroundControl.zOrderTrajectoryLines
Don Gagne's avatar
Don Gagne committed
167
            path: [
168 169
                object.coordinate1,
                object.coordinate2,
Don Gagne's avatar
Don Gagne committed
170 171
            ]
        }
172 173 174 175
    }

    // Add the vehicles to the map
    MapItemView {
176
        model: QGroundControl.multiVehicleManager.vehicles
DonLakeFlyer's avatar
DonLakeFlyer committed
177 178

        delegate: VehicleMapItem {
Don Gagne's avatar
Don Gagne committed
179 180 181
            vehicle:        object
            coordinate:     object.coordinate
            isSatellite:    flightMap.isSatelliteMap
Gus Grubba's avatar
Gus Grubba committed
182
            size:           _mainIsMap ? ScreenTools.defaultFontPixelHeight * 3 : ScreenTools.defaultFontPixelHeight
DonLakeFlyer's avatar
DonLakeFlyer committed
183
            z:              QGroundControl.zOrderVehicles
Don Gagne's avatar
Don Gagne committed
184
        }
185 186
    }

187 188
    // Add the mission item visuals to the map
    Repeater {
189
        model: _mainIsMap ? missionController.visualItems : 0
190 191

        delegate: MissionItemMapVisual {
192
            map:        flightMap
193
            onClicked:  guidedActionsController.confirmAction(guidedActionsController.actionSetWaypoint, Math.max(object.sequenceNumber, 1))
194
        }
195 196 197 198
    }

    // Add lines between waypoints
    MissionLineView {
DonLakeFlyer's avatar
DonLakeFlyer committed
199
        model:  _mainIsMap ? missionController.waypointLines : 0
200 201
    }

202 203 204 205
    GeoFenceMapVisuals {
        map:                    flightMap
        myGeoFenceController:   geoFenceController
        interactive:            false
206
        planView:               false
207
        homePosition:           _activeVehicle && _activeVehicle.homePosition.isValid ? _activeVehicle.homePosition : undefined
208 209
    }

210 211 212 213 214 215
    // Rally points on map
    MapItemView {
        model: rallyPointController.points

        delegate: MapQuickItem {
            id:             itemIndicator
216 217
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
218 219 220 221 222 223 224 225 226 227
            coordinate:     object.coordinate
            z:              QGroundControl.zOrderMapItems

            sourceItem: MissionItemIndexLabel {
                id:         itemIndexLabel
                label:      qsTr("R", "rally point map item label")
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
228 229 230
    // GoTo here waypoint
    MapQuickItem {
        coordinate:     _gotoHereCoordinate
Don Gagne's avatar
Don Gagne committed
231
        visible:        _activeVehicle && _activeVehicle.guidedMode && _gotoHereCoordinate.isValid
Don Gagne's avatar
Don Gagne committed
232
        z:              QGroundControl.zOrderMapItems
233 234
        anchorPoint.x:  sourceItem.anchorPointX
        anchorPoint.y:  sourceItem.anchorPointY
Don Gagne's avatar
Don Gagne committed
235 236

        sourceItem: MissionItemIndexLabel {
237 238
            checked: true
            label:   qsTr("G", "Goto here waypoint") // second string is translator's hint.
Don Gagne's avatar
Don Gagne committed
239
        }
240 241
    }    

Don Gagne's avatar
Don Gagne committed
242
    // Handle guided mode clicks
243 244
    MouseArea {
        anchors.fill: parent
Don Gagne's avatar
Don Gagne committed
245 246

        onClicked: {
247 248 249
            if (guidedActionsController.showGotoLocation) {
                _gotoHereCoordinate = flightMap.toCoordinate(Qt.point(mouse.x, mouse.y), false /* clipToViewPort */)
                guidedActionsController.confirmAction(guidedActionsController.actionGoto, _gotoHereCoordinate)
Don Gagne's avatar
Don Gagne committed
250 251
            }
        }
252
    }
253 254

    MapScale {
255
        id:                     mapScale
256
        anchors.right:          parent.right
257 258 259
        anchors.margins:        ScreenTools.defaultFontPixelHeight * (0.33)
        anchors.topMargin:      ScreenTools.defaultFontPixelHeight * (0.33) + state === "bottomMode" ? 0 : ScreenTools.toolbarHeight
        anchors.bottomMargin:   ScreenTools.defaultFontPixelHeight * (0.33)
260 261
        mapControl:             flightMap
        visible:                !ScreenTools.isTinyScreen
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
        state:                  "bottomMode"
        states: [
            State {
                name:   "topMode"
                AnchorChanges {
                    target:                 mapScale
                    anchors.top:            parent.top
                    anchors.bottom:         undefined
                }
            },
            State {
                name:   "bottomMode"
                AnchorChanges {
                    target:                 mapScale
                    anchors.top:            undefined
                    anchors.bottom:         parent.bottom
                }
            }
        ]
281
    }
282
}