FlightDisplayViewMap.qml 12.6 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
42
    property var    multiVehicleView                    ///< true: multi-vehicle view, false: single vehicle view
Don Gagne's avatar
Don Gagne committed
43

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

46 47 48 49
    property var    _planMasterController:      planMasterController
    property var    _missionController:         _planMasterController.missionController
    property var    _geoFenceController:        _planMasterController.geoFenceController
    property var    _rallyPointController:      _planMasterController.rallyPointController
50 51 52 53
    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)
Gus Grubba's avatar
Gus Grubba committed
54
    property bool   _airspaceManagement:        QGroundControl.airmapSupported && _activeVehicle
55

56 57
    property bool   _disableVehicleTracking:    false
    property bool   _keepVehicleCentered:       _mainIsMap ? false : true
58

59
    // Track last known map position and zoom from Fly view in settings
60
    onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel
61
    onCenterChanged: {
62
        if(_activeVehicle && QGroundControl.airmapSupported) {
63
            _activeVehicle.airspaceController.setROI(center, 5000)
64
        }
65 66
        QGroundControl.flightMapPosition = center
    }
67

68
    // When the user pans the map we stop responding to vehicle coordinate updates until the panRecenterTimer fires
69
    onUserPannedChanged: {
DonLakeFlyer's avatar
DonLakeFlyer committed
70 71 72 73 74 75
        if (userPanned) {
            console.log("user panned")
            userPanned = false
            _disableVehicleTracking = true
            panRecenterTimer.restart()
        }
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 101 102 103 104 105 106 107
    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() {
108
        var vehiclePoint = flightMap.fromCoordinate(_activeVehicleCoordinate, false /* clipToViewport */)
109 110
        var centerViewport = Qt.rect(0, 0, width, height)
        return !pointInRect(vehiclePoint, centerViewport)
111 112 113
    }

    function updateMapToVehiclePosition() {
114 115
        // We let FlightMap handle first vehicle position
        if (firstVehiclePositionReceived && _activeVehicleCoordinate.isValid && !_disableVehicleTracking) {
116
            if (_keepVehicleCentered) {
117
                flightMap.center = _activeVehicleCoordinate
118
            } else {
DonLakeFlyer's avatar
DonLakeFlyer committed
119
                if (firstVehiclePositionReceived && recenterNeeded()) {
120
                    animatedMapRecenter(flightMap.center, _activeVehicleCoordinate)
121 122
                }
            }
123 124 125 126
        }
    }

    Timer {
127 128 129
        id:         panRecenterTimer
        interval:   10000
        running:    false
130 131

        onTriggered: {
132
            _disableVehicleTracking = false
133
            updateMapToVehiclePosition()
134 135 136
        }
    }

137 138 139 140 141 142 143
    Timer {
        interval:       500
        running:        true
        repeat:         true
        onTriggered:    updateMapToVehiclePosition()
    }

Don Gagne's avatar
Don Gagne committed
144
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
145
    QGCMapPalette { id: mapPal; lightColors: isSatelliteMap }
Don Gagne's avatar
Don Gagne committed
146

147
    Connections {
148
        target: _missionController
149 150

        onNewItemsFromVehicle: {
151
            var visualItems = _missionController.visualItems
152 153
            if (visualItems && visualItems.count != 1) {
                mapFitFunctions.fitMapViewportToMissionItems()
154
                firstVehiclePositionReceived = true
155 156
            }
        }
157 158
    }

159
    ExclusiveGroup {
Don Gagne's avatar
Don Gagne committed
160
        id: _mapTypeButtonsExclusiveGroup
161 162
    }

Don Gagne's avatar
Don Gagne committed
163 164 165 166
    MapFitFunctions {
        id:                         mapFitFunctions
        map:                        _flightMap
        usePlannedHomePosition:     false
167
        planMasterController:       _planMasterController
168

Don Gagne's avatar
Don Gagne committed
169 170
        property real leftToolWidth:    toolStrip.x + toolStrip.width
    }
171

172 173
    // Add trajectory points to the map
    MapItemView {
174
        model: _mainIsMap ? _activeVehicle ? _activeVehicle.trajectoryPoints : 0 : 0
DonLakeFlyer's avatar
DonLakeFlyer committed
175 176

        delegate: MapPolyline {
Don Gagne's avatar
Don Gagne committed
177 178
            line.width: 3
            line.color: "red"
DonLakeFlyer's avatar
DonLakeFlyer committed
179
            z:          QGroundControl.zOrderTrajectoryLines
Don Gagne's avatar
Don Gagne committed
180
            path: [
181 182
                object.coordinate1,
                object.coordinate2,
Don Gagne's avatar
Don Gagne committed
183 184
            ]
        }
185 186 187 188
    }

    // Add the vehicles to the map
    MapItemView {
189
        model: QGroundControl.multiVehicleManager.vehicles
DonLakeFlyer's avatar
DonLakeFlyer committed
190 191

        delegate: VehicleMapItem {
Don Gagne's avatar
Don Gagne committed
192 193
            vehicle:        object
            coordinate:     object.coordinate
194
            map:            flightMap
Gus Grubba's avatar
Gus Grubba committed
195
            size:           _mainIsMap ? ScreenTools.defaultFontPixelHeight * 3 : ScreenTools.defaultFontPixelHeight
DonLakeFlyer's avatar
DonLakeFlyer committed
196
            z:              QGroundControl.zOrderVehicles
Don Gagne's avatar
Don Gagne committed
197
        }
198 199
    }

200 201
    // Add ADSB vehicles to the map
    MapItemView {
Gus Grubba's avatar
Gus Grubba committed
202
        model: _activeVehicle ? _activeVehicle.adsbVehicles : []
203 204 205 206
        property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
        delegate: VehicleMapItem {
            coordinate:     object.coordinate
            altitude:       object.altitude
207
            callsign:       object.callsign
208
            heading:        object.heading
Gus Grubba's avatar
Gus Grubba committed
209
            alert:          object.alert
210 211 212 213 214
            map:            flightMap
            z:              QGroundControl.zOrderVehicles
        }
    }

215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
    // Add the items associated with each vehicles flight plan to the map
    Repeater {
        model: QGroundControl.multiVehicleManager.vehicles

        PlanMapItems {
            map:                flightMap
            largeMapView:       _mainIsMap
            masterController:   masterController
            isActiveVehicle:    _vehicle.active

            property var _vehicle: object

            PlanMasterController {
                id: masterController
                Component.onCompleted: startStaticActiveVehicle(object)
            }
        }
232 233
    }

234 235 236 237 238 239
    // Allow custom builds to add map items
    CustomMapItems {
        map:            flightMap
        largeMapView:   _mainIsMap
    }

240 241
    GeoFenceMapVisuals {
        map:                    flightMap
242
        myGeoFenceController:   _geoFenceController
243
        interactive:            false
244
        planView:               false
245
        homePosition:           _activeVehicle && _activeVehicle.homePosition.isValid ? _activeVehicle.homePosition : undefined
246 247
    }

248 249
    // Rally points on map
    MapItemView {
250
        model: _rallyPointController.points
251 252 253

        delegate: MapQuickItem {
            id:             itemIndicator
254 255
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
256 257 258 259 260 261 262 263 264 265
            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
266 267 268
    // GoTo here waypoint
    MapQuickItem {
        coordinate:     _gotoHereCoordinate
269
        visible:        _activeVehicle && _activeVehicle.guidedModeSupported && _gotoHereCoordinate.isValid
Don Gagne's avatar
Don Gagne committed
270
        z:              QGroundControl.zOrderMapItems
271 272
        anchorPoint.x:  sourceItem.anchorPointX
        anchorPoint.y:  sourceItem.anchorPointY
Don Gagne's avatar
Don Gagne committed
273 274

        sourceItem: MissionItemIndexLabel {
DonLakeFlyer's avatar
DonLakeFlyer committed
275 276 277
            checked:    true
            index:      -1
            label:      qsTr("Goto here", "Goto here waypoint")
Don Gagne's avatar
Don Gagne committed
278
        }
279 280
    }    

281
    // Camera trigger points
282
    MapItemView {
283
        model: _activeVehicle ? _activeVehicle.cameraTriggerPoints : 0
284 285 286 287 288 289 290

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

Don Gagne's avatar
Don Gagne committed
291
    // Handle guided mode clicks
292 293
    MouseArea {
        anchors.fill: parent
Don Gagne's avatar
Don Gagne committed
294 295

        onClicked: {
DonLakeFlyer's avatar
DonLakeFlyer committed
296
            if (guidedActionsController.showGotoLocation && !guidedActionsController.guidedUIVisible) {
297 298
                _gotoHereCoordinate = flightMap.toCoordinate(Qt.point(mouse.x, mouse.y), false /* clipToViewPort */)
                guidedActionsController.confirmAction(guidedActionsController.actionGoto, _gotoHereCoordinate)
Don Gagne's avatar
Don Gagne committed
299 300
            }
        }
301
    }
302 303

    MapScale {
304
        id:                     mapScale
305
        anchors.right:          parent.right
306 307 308
        anchors.margins:        ScreenTools.defaultFontPixelHeight * (0.33)
        anchors.topMargin:      ScreenTools.defaultFontPixelHeight * (0.33) + state === "bottomMode" ? 0 : ScreenTools.toolbarHeight
        anchors.bottomMargin:   ScreenTools.defaultFontPixelHeight * (0.33)
309 310
        mapControl:             flightMap
        visible:                !ScreenTools.isTinyScreen
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
        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
                }
            }
        ]
330
    }
331

332
    // Airspace overlap support
333
    MapItemView {
334
        model:              _airspaceManagement && _activeVehicle.airspaceController.airspaceVisible ? _activeVehicle.airspaceController.airspaces.circles : []
335 336 337
        delegate: MapCircle {
            center:         object.center
            radius:         object.radius
338
            color:          Qt.rgba(0.94, 0.87, 0, 0.15)
Gus Grubba's avatar
Gus Grubba committed
339
            border.color:   Qt.rgba(1,1,1,0.85)
340 341 342 343
        }
    }

    MapItemView {
344
        model:              _airspaceManagement && _activeVehicle.airspaceController.airspaceVisible ? _activeVehicle.airspaceController.airspaces.polygons : []
345 346
        delegate: MapPolygon {
            path:           object.polygon
347 348
            color:          Qt.rgba(0.94, 0.87, 0, 0.15)
            border.color:   Qt.rgba(1,1,1,0.85)
349 350
        }
    }
351
}