FlightDisplayViewMap.qml 11.2 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
    planView:                   false
33

34 35
    property alias  scaleState: mapScale.state

36
    // The following properties must be set by the consumer
37
    property var    planMasterController
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    _planMasterController:      planMasterController
    property var    _missionController:         _planMasterController.missionController
    property var    _geoFenceController:        _planMasterController.geoFenceController
    property var    _rallyPointController:      _planMasterController.rallyPointController
49 50 51 52
    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)
53

54 55
    property bool   _disableVehicleTracking:    false
    property bool   _keepVehicleCentered:       _mainIsMap ? false : true
56

57
    // Track last known map position and zoom from Fly view in settings
58
    onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel
59
    onCenterChanged:    QGroundControl.flightMapPosition = center
60

61
    // When the user pans the map we stop responding to vehicle coordinate updates until the panRecenterTimer fires
62
    onUserPannedChanged: {
DonLakeFlyer's avatar
DonLakeFlyer committed
63 64 65 66 67 68
        if (userPanned) {
            console.log("user panned")
            userPanned = false
            _disableVehicleTracking = true
            panRecenterTimer.restart()
        }
69 70
    }

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    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() {
101
        var vehiclePoint = flightMap.fromCoordinate(_activeVehicleCoordinate, false /* clipToViewport */)
102 103
        var centerViewport = Qt.rect(0, 0, width, height)
        return !pointInRect(vehiclePoint, centerViewport)
104 105 106
    }

    function updateMapToVehiclePosition() {
107 108
        // We let FlightMap handle first vehicle position
        if (firstVehiclePositionReceived && _activeVehicleCoordinate.isValid && !_disableVehicleTracking) {
109
            if (_keepVehicleCentered) {
110
                flightMap.center = _activeVehicleCoordinate
111
            } else {
DonLakeFlyer's avatar
DonLakeFlyer committed
112
                if (firstVehiclePositionReceived && recenterNeeded()) {
113
                    animatedMapRecenter(flightMap.center, _activeVehicleCoordinate)
114 115
                }
            }
116 117 118 119
        }
    }

    Timer {
120 121 122
        id:         panRecenterTimer
        interval:   10000
        running:    false
123 124

        onTriggered: {
125
            _disableVehicleTracking = false
126
            updateMapToVehiclePosition()
127 128 129
        }
    }

130 131 132 133 134 135 136
    Timer {
        interval:       500
        running:        true
        repeat:         true
        onTriggered:    updateMapToVehiclePosition()
    }

Don Gagne's avatar
Don Gagne committed
137
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
138
    QGCMapPalette { id: mapPal; lightColors: isSatelliteMap }
Don Gagne's avatar
Don Gagne committed
139

140
    Connections {
141
        target: _missionController
142 143

        onNewItemsFromVehicle: {
144
            var visualItems = _missionController.visualItems
145 146
            if (visualItems && visualItems.count != 1) {
                mapFitFunctions.fitMapViewportToMissionItems()
147
                firstVehiclePositionReceived = true
148 149
            }
        }
150 151
    }

152
    ExclusiveGroup {
Don Gagne's avatar
Don Gagne committed
153
        id: _mapTypeButtonsExclusiveGroup
154 155
    }

Don Gagne's avatar
Don Gagne committed
156 157 158 159
    MapFitFunctions {
        id:                         mapFitFunctions
        map:                        _flightMap
        usePlannedHomePosition:     false
160
        planMasterController:       _planMasterController
161

Don Gagne's avatar
Don Gagne committed
162 163
        property real leftToolWidth:    toolStrip.x + toolStrip.width
    }
164

165 166
    // Add trajectory points to the map
    MapItemView {
167
        model: _mainIsMap ? _activeVehicle ? _activeVehicle.trajectoryPoints : 0 : 0
DonLakeFlyer's avatar
DonLakeFlyer committed
168 169

        delegate: MapPolyline {
Don Gagne's avatar
Don Gagne committed
170 171
            line.width: 3
            line.color: "red"
DonLakeFlyer's avatar
DonLakeFlyer committed
172
            z:          QGroundControl.zOrderTrajectoryLines
Don Gagne's avatar
Don Gagne committed
173
            path: [
174 175
                object.coordinate1,
                object.coordinate2,
Don Gagne's avatar
Don Gagne committed
176 177
            ]
        }
178 179 180 181
    }

    // Add the vehicles to the map
    MapItemView {
182
        model: QGroundControl.multiVehicleManager.vehicles
DonLakeFlyer's avatar
DonLakeFlyer committed
183 184

        delegate: VehicleMapItem {
Don Gagne's avatar
Don Gagne committed
185 186
            vehicle:        object
            coordinate:     object.coordinate
187
            map:            flightMap
Gus Grubba's avatar
Gus Grubba committed
188
            size:           _mainIsMap ? ScreenTools.defaultFontPixelHeight * 3 : ScreenTools.defaultFontPixelHeight
DonLakeFlyer's avatar
DonLakeFlyer committed
189
            z:              QGroundControl.zOrderVehicles
Don Gagne's avatar
Don Gagne committed
190
        }
191 192
    }

193 194 195 196 197 198 199 200 201
    // Add ADSB vehicles to the map
    MapItemView {
        model: _activeVehicle ? _activeVehicle.adsbVehicles : 0

        property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle

        delegate: VehicleMapItem {
            coordinate:     object.coordinate
            altitude:       object.altitude
202
            callsign:       object.callsign
203 204 205 206 207 208
            heading:        object.heading
            map:            flightMap
            z:              QGroundControl.zOrderVehicles
        }
    }

209 210
    // Add the mission item visuals to the map
    Repeater {
211
        model: _mainIsMap ? _missionController.visualItems : 0
212 213

        delegate: MissionItemMapVisual {
214
            map:        flightMap
215
            onClicked:  guidedActionsController.confirmAction(guidedActionsController.actionSetWaypoint, Math.max(object.sequenceNumber, 1))
216
        }
217 218 219 220
    }

    // Add lines between waypoints
    MissionLineView {
221
        model:  _mainIsMap ? _missionController.waypointLines : 0
222 223
    }

224 225
    GeoFenceMapVisuals {
        map:                    flightMap
226
        myGeoFenceController:   _geoFenceController
227
        interactive:            false
228
        planView:               false
229
        homePosition:           _activeVehicle && _activeVehicle.homePosition.isValid ? _activeVehicle.homePosition : undefined
230 231
    }

232 233
    // Rally points on map
    MapItemView {
234
        model: _rallyPointController.points
235 236 237

        delegate: MapQuickItem {
            id:             itemIndicator
238 239
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
240 241 242 243 244 245 246 247 248 249
            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
250 251 252
    // GoTo here waypoint
    MapQuickItem {
        coordinate:     _gotoHereCoordinate
Don Gagne's avatar
Don Gagne committed
253
        visible:        _activeVehicle && _activeVehicle.guidedMode && _gotoHereCoordinate.isValid
Don Gagne's avatar
Don Gagne committed
254
        z:              QGroundControl.zOrderMapItems
255 256
        anchorPoint.x:  sourceItem.anchorPointX
        anchorPoint.y:  sourceItem.anchorPointY
Don Gagne's avatar
Don Gagne committed
257 258

        sourceItem: MissionItemIndexLabel {
DonLakeFlyer's avatar
DonLakeFlyer committed
259 260 261
            checked:    true
            index:      -1
            label:      qsTr("Goto here", "Goto here waypoint")
Don Gagne's avatar
Don Gagne committed
262
        }
263 264
    }    

265
    // Camera trigger points
266
    MapItemView {
267
        model: _activeVehicle ? _activeVehicle.cameraTriggerPoints : 0
268 269 270 271 272 273 274

        delegate: CameraTriggerIndicator {
            coordinate:     object.coordinate
            z:              QGroundControl.zOrderTopMost
        }
    }

Don Gagne's avatar
Don Gagne committed
275
    // Handle guided mode clicks
276 277
    MouseArea {
        anchors.fill: parent
Don Gagne's avatar
Don Gagne committed
278 279

        onClicked: {
DonLakeFlyer's avatar
DonLakeFlyer committed
280
            if (guidedActionsController.showGotoLocation && !guidedActionsController.guidedUIVisible) {
281 282
                _gotoHereCoordinate = flightMap.toCoordinate(Qt.point(mouse.x, mouse.y), false /* clipToViewPort */)
                guidedActionsController.confirmAction(guidedActionsController.actionGoto, _gotoHereCoordinate)
Don Gagne's avatar
Don Gagne committed
283 284
            }
        }
285
    }
286 287

    MapScale {
288
        id:                     mapScale
289
        anchors.right:          parent.right
290 291 292
        anchors.margins:        ScreenTools.defaultFontPixelHeight * (0.33)
        anchors.topMargin:      ScreenTools.defaultFontPixelHeight * (0.33) + state === "bottomMode" ? 0 : ScreenTools.toolbarHeight
        anchors.bottomMargin:   ScreenTools.defaultFontPixelHeight * (0.33)
293 294
        mapControl:             flightMap
        visible:                !ScreenTools.isTinyScreen
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
        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
                }
            }
        ]
314
    }
315
}