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

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 {
    id:             flightMap
    anchors.fill:   parent
    mapName:        _mapName

30 31 32 33
    gesture.acceptedGestures: _followVehicle ?
                                          MapGestureArea.PinchGesture :
                                          MapGestureArea.PinchGesture | MapGestureArea.PanGesture | MapGestureArea.FlickGesture

34
    property alias  missionController: missionController
Don Gagne's avatar
Don Gagne committed
35
    property var    flightWidgets
36
    property var    rightPanelWidth
Don Gagne's avatar
Don Gagne committed
37

38
    property bool   _followVehicle:                 true
Don Gagne's avatar
Don Gagne committed
39 40 41 42
    property var    _activeVehicle:                 QGroundControl.multiVehicleManager.activeVehicle
    property bool   _activeVehicleCoordinateValid:  _activeVehicle ? _activeVehicle.coordinateValid : false
    property var    activeVehicleCoordinate:        _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
    property var    _gotoHereCoordinate:            QtPositioning.coordinate()
43
    property int    _retaskSequence:                0
44
    property real   _toolButtonTopMargin:           parent.height - ScreenTools.availableHeight + (ScreenTools.defaultFontPixelHeight / 2)
45

46 47
    property bool   followVehicleConnection:        _followVehicle  ///< Only use to create connection on

48 49 50 51
    Component.onCompleted: {
        QGroundControl.flightMapPosition = center
        QGroundControl.flightMapZoom = zoomLevel
    }
52
    onCenterChanged: QGroundControl.flightMapPosition = center
53
    onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel
54

55
    onActiveVehicleCoordinateChanged: {
56
        if (_followVehicle && _activeVehicleCoordinateValid && activeVehicleCoordinate.isValid) {
57 58
            _initialMapPositionSet = true
            flightMap.center  = activeVehicleCoordinate
59 60 61
        }
    }

Don Gagne's avatar
Don Gagne committed
62
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
63
    QGCMapPalette { id: mapPal; lightColors: isSatelliteMap }
Don Gagne's avatar
Don Gagne committed
64

65
    MissionController {
66
        id: missionController
67 68 69
        Component.onCompleted: start(false /* editMode */)
    }

70
    GeoFenceController {
71
        id: geoFenceController
72 73 74
        Component.onCompleted: start(false /* editMode */)
    }

75 76 77 78 79
    RallyPointController {
        id: rallyPointController
        Component.onCompleted: start(false /* editMode */)
    }

80
    ExclusiveGroup {
Don Gagne's avatar
Don Gagne committed
81
        id: _mapTypeButtonsExclusiveGroup
82 83
    }

Don Gagne's avatar
Don Gagne committed
84 85 86 87 88 89 90 91 92 93
    ToolStrip {
        id:                 toolStrip
        anchors.leftMargin: ScreenTools.defaultFontPixelWidth
        anchors.left:       parent.left
        anchors.topMargin:  _toolButtonTopMargin
        anchors.top:        parent.top
        color:              qgcPal.window
        title:              qsTr("Fly")
        z:                  QGroundControl.zOrderWidgets
        buttonVisible:      [ true, true, _showZoom, _showZoom ]
94
        maxHeight:          (_flightVideo.visible ? _flightVideo.y : parent.height) - toolStrip.y   // Massive reach across hack
Don Gagne's avatar
Don Gagne committed
95

Don Gagne's avatar
Don Gagne committed
96
        property bool _showZoom: !ScreenTools.isMobile
Don Gagne's avatar
Don Gagne committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117

        model: [
            {
                name:               "Center",
                iconSource:         "/qmlimages/MapCenter.svg",
                dropPanelComponent: centerMapDropPanel
            },
            {
                name:               "Map",
                iconSource:         "/qmlimages/MapType.svg",
                dropPanelComponent: mapTypeDropPanel
            },
            {
                name:               "In",
                iconSource:         "/qmlimages/ZoomPlus.svg"
            },
            {
                name:               "Out",
                iconSource:         "/qmlimages/ZoomMinus.svg"
            }
        ]
118 119

        onClicked: {
Don Gagne's avatar
Don Gagne committed
120 121 122 123 124 125 126
            switch (index) {
            case 2:
                _flightMap.zoomLevel += 0.5
                break
            case 3:
                _flightMap.zoomLevel -= 0.5
                break
127 128 129 130
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
131
    // Toolstrip drop panel compomnents
Don Gagne's avatar
Don Gagne committed
132

Don Gagne's avatar
Don Gagne committed
133 134 135 136 137 138 139 140
    MapFitFunctions {
        id:                         mapFitFunctions
        map:                        _flightMap
        mapFitViewport:             Qt.rect(leftToolWidth, _toolButtonTopMargin, flightMap.width - leftToolWidth - rightPanelWidth, flightMap.height - _toolButtonTopMargin)
        usePlannedHomePosition:     false
        mapMissionController:      missionController
        mapGeoFenceController:     geoFenceController
        mapRallyPointController:   rallyPointController
141

Don Gagne's avatar
Don Gagne committed
142 143
        property real leftToolWidth:    toolStrip.x + toolStrip.width
    }
144

Don Gagne's avatar
Don Gagne committed
145 146
    Component {
        id: centerMapDropPanel
147

Don Gagne's avatar
Don Gagne committed
148
        CenterMapDropPanel {
149 150 151 152 153 154
            map:                _flightMap
            fitFunctions:       mapFitFunctions
            showFollowVehicle:  true
            followVehicle:      _followVehicle

            onFollowVehicleChanged: _followVehicle = followVehicle
Don Gagne's avatar
Don Gagne committed
155 156
        }
    }
157

Don Gagne's avatar
Don Gagne committed
158 159
    Component {
        id: mapTypeDropPanel
160

Don Gagne's avatar
Don Gagne committed
161 162
        Column {
            spacing: ScreenTools.defaultFontPixelHeight / 2
163

Don Gagne's avatar
Don Gagne committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
            QGCLabel { text: qsTr("Map type:") }
            Row {
                spacing: ScreenTools.defaultFontPixelWidth
                Repeater {
                    model: QGroundControl.flightMapSettings.mapTypes

                    QGCButton {
                        checkable:      true
                        checked:        QGroundControl.flightMapSettings.mapType === text
                        text:           modelData
                        exclusiveGroup: _mapTypeButtonsExclusiveGroup
                        onClicked: {
                            QGroundControl.flightMapSettings.mapType = text
                            dropPanel.hide()
                        }
179 180 181 182
                    }
                }
            }
        }
Don Gagne's avatar
Don Gagne committed
183
    }
184

185 186
    // Add trajectory points to the map
    MapItemView {
187
        model: _mainIsMap ? _activeVehicle ? _activeVehicle.trajectoryPoints : 0 : 0
188 189
        delegate:
            MapPolyline {
Don Gagne's avatar
Don Gagne committed
190 191 192 193
            line.width: 3
            line.color: "red"
            z:          QGroundControl.zOrderMapItems - 1
            path: [
194 195
                object.coordinate1,
                object.coordinate2,
Don Gagne's avatar
Don Gagne committed
196 197
            ]
        }
198 199 200 201
    }

    // Add the vehicles to the map
    MapItemView {
202
        model: QGroundControl.multiVehicleManager.vehicles
203 204
        delegate:
            VehicleMapItem {
Don Gagne's avatar
Don Gagne committed
205 206 207
            vehicle:        object
            coordinate:     object.coordinate
            isSatellite:    flightMap.isSatelliteMap
Gus Grubba's avatar
Gus Grubba committed
208
            size:           _mainIsMap ? ScreenTools.defaultFontPixelHeight * 3 : ScreenTools.defaultFontPixelHeight
209
            z:              QGroundControl.zOrderMapItems - 1
Don Gagne's avatar
Don Gagne committed
210
        }
211 212
    }

213 214
    // Add the mission item visuals to the map
    Repeater {
215
        model: _mainIsMap ? missionController.visualItems : 0
216 217 218 219

        delegate: MissionItemMapVisual {
            map: flightMap
        }
220 221 222 223
    }

    // Add lines between waypoints
    MissionLineView {
224
        model: _mainIsMap ? missionController.waypointLines : 0
225 226
    }

227 228 229 230
    // GeoFence polygon
    MapPolygon {
        border.color:   "#80FF0000"
        border.width:   3
231
        path:           geoFenceController.polygon.path
232
        visible:        geoFenceController.polygonEnabled
233 234 235 236 237 238 239
    }

    // GeoFence circle
    MapCircle {
        border.color:   "#80FF0000"
        border.width:   3
        center:         missionController.plannedHomePosition
240
        radius:         geoFenceController.circleRadius
241
        z:              QGroundControl.zOrderMapItems
242
        visible:        geoFenceController.circleEnabled
243 244 245 246
    }

    // GeoFence breach return point
    MapQuickItem {
247 248
        anchorPoint.x:  sourceItem.anchorPointX
        anchorPoint.y:  sourceItem.anchorPointY
249
        coordinate:     geoFenceController.breachReturnPoint
250
        visible:        geoFenceController.breachReturnEnabled
251
        sourceItem:     MissionItemIndexLabel { label: "F" }
252
        z:              QGroundControl.zOrderMapItems
253 254
    }

255 256 257 258 259 260
    // Rally points on map
    MapItemView {
        model: rallyPointController.points

        delegate: MapQuickItem {
            id:             itemIndicator
261 262
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
263 264 265 266 267 268 269 270 271 272
            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
273 274 275
    // GoTo here waypoint
    MapQuickItem {
        coordinate:     _gotoHereCoordinate
Don Gagne's avatar
Don Gagne committed
276
        visible:        _activeVehicle && _activeVehicle.guidedMode && _gotoHereCoordinate.isValid
Don Gagne's avatar
Don Gagne committed
277
        z:              QGroundControl.zOrderMapItems
278 279
        anchorPoint.x:  sourceItem.anchorPointX
        anchorPoint.y:  sourceItem.anchorPointY
Don Gagne's avatar
Don Gagne committed
280 281

        sourceItem: MissionItemIndexLabel {
282 283
            checked: true
            label:   qsTr("G", "Goto here waypoint") // second string is translator's hint.
Don Gagne's avatar
Don Gagne committed
284
        }
285 286 287 288 289 290 291 292 293
    }    

    MapScale {
        anchors.bottomMargin:   ScreenTools.defaultFontPixelHeight * (0.66)
        anchors.rightMargin:    ScreenTools.defaultFontPixelHeight * (0.33)
        anchors.bottom:         parent.bottom
        anchors.right:          parent.right
        mapControl:             flightMap
        visible:                !ScreenTools.isTinyScreen
Don Gagne's avatar
Don Gagne committed
294 295 296
    }

    // Handle guided mode clicks
297 298
    MouseArea {
        anchors.fill: parent
Don Gagne's avatar
Don Gagne committed
299 300

        onClicked: {
Don Gagne's avatar
Don Gagne committed
301
            if (_activeVehicle) {
302
                if (flightWidgets.guidedModeBar.state != "Shown") {
Don Gagne's avatar
Don Gagne committed
303
                    flightWidgets.guidedModeBar.state = "Shown"
304 305 306 307 308
                } else {
                    if (flightWidgets.gotoEnabled) {
                        _gotoHereCoordinate = flightMap.toCoordinate(Qt.point(mouse.x, mouse.y))
                        flightWidgets.guidedModeBar.confirmAction(flightWidgets.guidedModeBar.confirmGoTo)
                    }
Don Gagne's avatar
Don Gagne committed
309
                }
Don Gagne's avatar
Don Gagne committed
310 311
            }
        }
312 313
    }
}