FlightDisplayViewMap.qml 12.3 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 16 17 18 19 20 21 22 23 24 25 26 27 28 29


import QtQuick                      2.4
import QtQuick.Controls             1.3
import QtLocation                   5.3
import QtPositioning                5.2

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
    property alias  missionController: missionController
Don Gagne's avatar
Don Gagne committed
31
    property var    flightWidgets
32
    property var    rightPanelWidth
Don Gagne's avatar
Don Gagne committed
33

34
    property bool   _followVehicle:                 true
Don Gagne's avatar
Don Gagne committed
35 36 37 38
    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()
39
    property int    _retaskSequence:                0
40
    property real   _toolButtonTopMargin:           parent.height - ScreenTools.availableHeight + (ScreenTools.defaultFontPixelHeight / 2)
41

42 43 44 45
    Component.onCompleted: {
        QGroundControl.flightMapPosition = center
        QGroundControl.flightMapZoom = zoomLevel
    }
46
    onCenterChanged: QGroundControl.flightMapPosition = center
47
    onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel
48

49
    onActiveVehicleCoordinateChanged: {
50
        if (_followVehicle && _activeVehicleCoordinateValid && activeVehicleCoordinate.isValid) {
51 52
            _initialMapPositionSet = true
            flightMap.center  = activeVehicleCoordinate
53 54 55
        }
    }

Don Gagne's avatar
Don Gagne committed
56
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
57
    QGCMapPalette { id: mapPal; lightColors: isSatelliteMap }
Don Gagne's avatar
Don Gagne committed
58

59
    MissionController {
60
        id: missionController
61 62 63
        Component.onCompleted: start(false /* editMode */)
    }

64
    GeoFenceController {
65
        id: geoFenceController
66 67 68
        Component.onCompleted: start(false /* editMode */)
    }

69 70 71 72 73
    RallyPointController {
        id: rallyPointController
        Component.onCompleted: start(false /* editMode */)
    }

74
    QGCMapLabel {
75
        id:                         flyLabel
76
        map:                        flightMap
77 78 79
        text:                       qsTr("Fly")
        visible:                    !ScreenTools.isShortScreen
        anchors.topMargin:          _toolButtonTopMargin
Don Gagne's avatar
Don Gagne committed
80
        anchors.horizontalCenter:   centerMapDropButton.horizontalCenter
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
        anchors.top:                parent.top
    }

    //-- Vertical Tool Buttons

    ExclusiveGroup {
        id: dropButtonsExclusiveGroup
    }

    ExclusiveGroup {
        id: mapTypeButtonsExclusiveGroup
    }

    //-- Dismiss Drop Down (if any)
    MouseArea {
        anchors.fill:   parent
        enabled:        dropButtonsExclusiveGroup.current != null
        onClicked: {
            if (dropButtonsExclusiveGroup.current) {
                dropButtonsExclusiveGroup.current.checked = false
            }
            dropButtonsExclusiveGroup.current = null
        }
    }

Don Gagne's avatar
Don Gagne committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
    // IMPORTANT NOTE: Drop Buttons must be parented directly to the map. If they are placed in a Column for example the drop control positioning
    // will not work correctly.

    //-- Map Center Control
    CenterMapDropButton {
        id:                     centerMapDropButton
        anchors.topMargin:      flyLabel.visible ? ScreenTools.defaultFontPixelHeight / 2 : _toolButtonTopMargin
        anchors.leftMargin:     ScreenTools.defaultFontPixelHeight
        anchors.left:           parent.left
        anchors.top:            flyLabel.visible ? flyLabel.bottom : parent.top
        z:                      QGroundControl.zOrderWidgets
        exclusiveGroup:         dropButtonsExclusiveGroup
        map:                    _flightMap
        mapFitViewport:         Qt.rect(leftToolWidth, _toolButtonTopMargin, flightMap.width - leftToolWidth - rightPanelWidth, flightMap.height - _toolButtonTopMargin)
        usePlannedHomePosition: false
        geoFenceController:     geoFenceController
        missionController:      missionController
        rallyPointController:   rallyPointController
        showFollowVehicle:      true
        followVehicle:          _followVehicle
        onFollowVehicleChanged: _followVehicle = followVehicle

        property real leftToolWidth:    centerMapDropButton.x + centerMapDropButton.width
    }

    //-- Map Type Control
    DropButton {
        id:                 mapTypeButton
        anchors.topMargin:  ScreenTools.defaultFontPixelHeight
        anchors.top:        centerMapDropButton.bottom
        anchors.left:       centerMapDropButton.left
        dropDirection:      dropRight
        buttonImage:        "/qmlimages/MapType.svg"
        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
        exclusiveGroup:     dropButtonsExclusiveGroup
141
        z:                  QGroundControl.zOrderWidgets
Don Gagne's avatar
Don Gagne committed
142
        lightBorders:       isSatelliteMap
143

Don Gagne's avatar
Don Gagne committed
144 145 146
        dropDownComponent: Component {
            Column {
                spacing: ScreenTools.defaultFontPixelWidth
147

Don Gagne's avatar
Don Gagne committed
148
                Row {
149 150
                    spacing: ScreenTools.defaultFontPixelWidth

Don Gagne's avatar
Don Gagne committed
151 152
                    Repeater {
                        model: QGroundControl.flightMapSettings.mapTypes
153

Don Gagne's avatar
Don Gagne committed
154 155 156 157 158 159
                        QGCButton {
                            checkable:      true
                            checked:        QGroundControl.flightMapSettings.mapType === text
                            text:           modelData
                            width:          clearButton.width
                            exclusiveGroup: mapTypeButtonsExclusiveGroup
160

Don Gagne's avatar
Don Gagne committed
161 162 163 164
                            onClicked: {
                                QGroundControl.flightMapSettings.mapType = text
                                checked = true
                                dropButtonsExclusiveGroup.current = null
165 166 167
                            }
                        }
                    }
Don Gagne's avatar
Don Gagne committed
168
                }
169

Don Gagne's avatar
Don Gagne committed
170 171 172 173 174 175 176
                QGCButton {
                    id:         clearButton
                    text:       qsTr("Clear Flight Trails")
                    enabled:    QGroundControl.multiVehicleManager.activeVehicle
                    onClicked: {
                        QGroundControl.multiVehicleManager.activeVehicle.clearTrajectoryPoints()
                        dropButtonsExclusiveGroup.current = null
177 178 179 180
                    }
                }
            }
        }
Don Gagne's avatar
Don Gagne committed
181
    }
182

Don Gagne's avatar
Don Gagne committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    //-- Zoom Map In
    RoundButton {
        id:                 mapZoomPlus
        anchors.topMargin:  ScreenTools.defaultFontPixelHeight
        anchors.top:        mapTypeButton.bottom
        anchors.left:       mapTypeButton.left
        visible:            !ScreenTools.isTinyScreen && _mainIsMap
        buttonImage:        "/qmlimages/ZoomPlus.svg"
        exclusiveGroup:     dropButtonsExclusiveGroup
        z:                  QGroundControl.zOrderWidgets
        lightBorders:       isSatelliteMap
        onClicked: {
            if(_flightMap)
                _flightMap.zoomLevel += 0.5
            checked = false
198
        }
Don Gagne's avatar
Don Gagne committed
199
    }
200

Don Gagne's avatar
Don Gagne committed
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
    //-- Zoom Map Out
    RoundButton {
        id:                 mapZoomMinus
        anchors.topMargin:  ScreenTools.defaultFontPixelHeight
        anchors.top:        mapZoomPlus.bottom
        anchors.left:       mapZoomPlus.left
        visible:            !ScreenTools.isTinyScreen && _mainIsMap
        buttonImage:        "/qmlimages/ZoomMinus.svg"
        exclusiveGroup:     dropButtonsExclusiveGroup
        z:                  QGroundControl.zOrderWidgets
        lightBorders:       isSatelliteMap
        onClicked: {
            if(_flightMap)
                _flightMap.zoomLevel -= 0.5
            checked = false
216 217 218
        }
    }

219 220
    // Add trajectory points to the map
    MapItemView {
221
        model: _mainIsMap ? _activeVehicle ? _activeVehicle.trajectoryPoints : 0 : 0
222 223
        delegate:
            MapPolyline {
Don Gagne's avatar
Don Gagne committed
224 225 226 227
            line.width: 3
            line.color: "red"
            z:          QGroundControl.zOrderMapItems - 1
            path: [
228 229
                object.coordinate1,
                object.coordinate2,
Don Gagne's avatar
Don Gagne committed
230 231
            ]
        }
232 233 234 235
    }

    // Add the vehicles to the map
    MapItemView {
236
        model: QGroundControl.multiVehicleManager.vehicles
237 238
        delegate:
            VehicleMapItem {
Don Gagne's avatar
Don Gagne committed
239 240 241 242
            vehicle:        object
            coordinate:     object.coordinate
            isSatellite:    flightMap.isSatelliteMap
            size:           _mainIsMap ? ScreenTools.defaultFontPixelHeight * 5 : ScreenTools.defaultFontPixelHeight * 2
243
            z:              QGroundControl.zOrderMapItems - 1
Don Gagne's avatar
Don Gagne committed
244
        }
245 246 247 248
    }

    // Add the mission items to the map
    MissionItemView {
249
        model: _mainIsMap ? missionController.visualItems : 0
250 251 252 253
    }

    // Add lines between waypoints
    MissionLineView {
254
        model: _mainIsMap ? missionController.waypointLines : 0
255 256
    }

257 258 259 260
    // GeoFence polygon
    MapPolygon {
        border.color:   "#80FF0000"
        border.width:   3
261
        path:           geoFenceController.polygon.path
262
        visible:        geoFenceController.polygonEnabled
263 264 265 266 267 268 269
    }

    // GeoFence circle
    MapCircle {
        border.color:   "#80FF0000"
        border.width:   3
        center:         missionController.plannedHomePosition
270
        radius:         geoFenceController.circleRadius
271
        z:              QGroundControl.zOrderMapItems
272
        visible:        geoFenceController.circleEnabled
273 274 275 276 277
    }

    // GeoFence breach return point
    MapQuickItem {
        anchorPoint:    Qt.point(sourceItem.width / 2, sourceItem.height / 2)
278
        coordinate:     geoFenceController.breachReturnPoint
279
        visible:        geoFenceController.breachReturnEnabled
280
        sourceItem:     MissionItemIndexLabel { label: "F" }
281
        z:              QGroundControl.zOrderMapItems
282 283
    }

284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
    // Rally points on map
    MapItemView {
        model: rallyPointController.points

        delegate: MapQuickItem {
            id:             itemIndicator
            anchorPoint:    Qt.point(sourceItem.width / 2, sourceItem.height / 2)
            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
301 302 303
    // GoTo here waypoint
    MapQuickItem {
        coordinate:     _gotoHereCoordinate
Don Gagne's avatar
Don Gagne committed
304
        visible:        _activeVehicle && _activeVehicle.guidedMode && _gotoHereCoordinate.isValid
Don Gagne's avatar
Don Gagne committed
305 306 307 308 309
        z:              QGroundControl.zOrderMapItems
        anchorPoint.x:  sourceItem.width  / 2
        anchorPoint.y:  sourceItem.height / 2

        sourceItem: MissionItemIndexLabel {
310 311
            checked: true
            label:   qsTr("G", "Goto here waypoint") // second string is translator's hint.
Don Gagne's avatar
Don Gagne committed
312
        }
313 314 315 316 317 318 319 320 321
    }    

    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
322 323 324
    }

    // Handle guided mode clicks
325 326
    MouseArea {
        anchors.fill: parent
Don Gagne's avatar
Don Gagne committed
327 328

        onClicked: {
Don Gagne's avatar
Don Gagne committed
329
            if (_activeVehicle) {
330
                if (flightWidgets.guidedModeBar.state != "Shown") {
Don Gagne's avatar
Don Gagne committed
331
                    flightWidgets.guidedModeBar.state = "Shown"
332 333 334 335 336
                } 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
337
                }
Don Gagne's avatar
Don Gagne committed
338 339
            }
        }
340 341
    }
}