OfflineMap.qml 43.9 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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9 10 11 12 13 14 15


import QtQuick                  2.5
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.1
import QtQuick.Layouts          1.2
16 17
import QtLocation               5.5
import QtPositioning            5.5
dogmaphobic's avatar
dogmaphobic committed
18

Don Gagne's avatar
Don Gagne committed
19 20 21 22 23
import QGroundControl               1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Palette       1.0
import QGroundControl.FlightMap     1.0
dogmaphobic's avatar
dogmaphobic committed
24

Don Gagne's avatar
Don Gagne committed
25 26 27 28
QGCView {
    id:             offlineMapView
    viewPanel:      panel
    anchors.fill:   parent
dogmaphobic's avatar
dogmaphobic committed
29

dogmaphobic's avatar
dogmaphobic committed
30
    property var    _currentSelection:  null
dogmaphobic's avatar
dogmaphobic committed
31

dogmaphobic's avatar
dogmaphobic committed
32
    property string mapKey:             "lastMapType"
dogmaphobic's avatar
dogmaphobic committed
33

34
    property string mapType:            QGroundControl.flightMapSettings.mapProvider + " " + QGroundControl.flightMapSettings.mapType
35
    property bool   isMapInteractive:   false
36 37 38
    property var    savedCenter:        undefined
    property real   savedZoom:          3
    property string savedMapType:       ""
Don Gagne's avatar
Don Gagne committed
39
    property bool   _showPreview:       true
dogmaphobic's avatar
dogmaphobic committed
40

Don Gagne's avatar
Don Gagne committed
41 42 43
    property bool _saveRealEstate:          ScreenTools.isTinyScreen || ScreenTools.isShortScreen
    property real _adjustableFontPointSize: _saveRealEstate ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize

Don Gagne's avatar
Don Gagne committed
44 45
    property var _mapAdjustedColor: _map.isSatelliteMap ? "white" : "black"

Don Gagne's avatar
Don Gagne committed
46 47 48
    readonly property real minZoomLevel: 3
    readonly property real maxZoomLevel: 20

49 50
    readonly property int _maxTilesForDownload: 60000

Don Gagne's avatar
Don Gagne committed
51
    QGCPalette { id: qgcPal }
52

dogmaphobic's avatar
dogmaphobic committed
53 54 55
    Component.onCompleted: {
        QGroundControl.mapEngineManager.loadTileSets()
        updateMap()
56
        savedCenter = _map.toCoordinate(Qt.point(_map.width / 2, _map.height / 2))
dogmaphobic's avatar
dogmaphobic committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    }

    Connections {
        target: QGroundControl.mapEngineManager
        onTileSetsChanged: {
            setName.text = QGroundControl.mapEngineManager.getUniqueName()
        }
        onErrorMessageChanged: {
            errorDialog.visible = true
        }
    }

    ExclusiveGroup { id: setGroup }

    function handleChanges() {
72
        if(isMapInteractive) {
Don Gagne's avatar
Don Gagne committed
73 74
            var xl = 0
            var yl = 0
75 76
            var xr = _map.width.toFixed(0) - 1  // Must be within boundaries of visible map
            var yr = _map.height.toFixed(0) - 1 // Must be within boundaries of visible map
77 78
            var c0 = _map.toCoordinate(Qt.point(xl, yl))
            var c1 = _map.toCoordinate(Qt.point(xr, yr))
79
            QGroundControl.mapEngineManager.updateForCurrentView(c0.longitude, c0.latitude, c1.longitude, c1.latitude, sliderMinZoom.value, sliderMaxZoom.value, mapType)
dogmaphobic's avatar
dogmaphobic committed
80 81 82 83 84 85 86 87 88 89 90 91 92
        }
    }

    function updateMap() {
        for (var i = 0; i < _map.supportedMapTypes.length; i++) {
            if (mapType === _map.supportedMapTypes[i].name) {
                _map.activeMapType = _map.supportedMapTypes[i]
                handleChanges()
                return
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
93
    function addNewSet() {
94
        isMapInteractive = true
95
        mapType = QGroundControl.flightMapSettings.mapProvider + " " + QGroundControl.flightMapSettings.mapType
96 97
        resetMapToDefaults()
        handleChanges()
98
        _map.visible = true
dogmaphobic's avatar
dogmaphobic committed
99
        _tileSetList.visible = false
Don Gagne's avatar
Don Gagne committed
100 101 102
        infoView.visible = false
        defaultInfoView.visible = false
        addNewSetView.visible = true
dogmaphobic's avatar
dogmaphobic committed
103 104 105
    }

    function showList() {
106
        isMapInteractive = false
107
        _map.visible = false
dogmaphobic's avatar
dogmaphobic committed
108
        _tileSetList.visible = true
Don Gagne's avatar
Don Gagne committed
109 110 111
        infoView.visible = false
        defaultInfoView.visible = false
        addNewSetView.visible = false
dogmaphobic's avatar
dogmaphobic committed
112 113 114
    }

    function showInfo() {
115
        isMapInteractive = false
Don Gagne's avatar
Don Gagne committed
116
        if(_currentSelection && !offlineMapView._currentSelection.deleting) {
117
            enterInfoView()
dogmaphobic's avatar
dogmaphobic committed
118 119 120 121
        } else
            showList()
    }

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
    function toRadian(deg) {
        return deg * Math.PI / 180
    }

    function toDegree(rad) {
        return rad * 180 / Math.PI
    }

    function midPoint(lat1, lat2, lon1, lon2) {
        var dLon = toRadian(lon2 - lon1);
        lat1 = toRadian(lat1);
        lat2 = toRadian(lat2);
        lon1 = toRadian(lon1);
        var Bx = Math.cos(lat2) * Math.cos(dLon);
        var By = Math.cos(lat2) * Math.sin(dLon);
        var lat3 = Math.atan2(Math.sin(lat1) + Math.sin(lat2), Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By));
        var lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);
        return QtPositioning.coordinate(toDegree(lat3), toDegree(lon3))
    }

    function enterInfoView() {
Don Gagne's avatar
Don Gagne committed
143 144 145 146 147 148
        var isDefaultSet = offlineMapView._currentSelection.defaultSet
        _map.visible = true
        isMapInteractive = false
        savedCenter = _map.toCoordinate(Qt.point(_map.width / 2, _map.height / 2))
        savedZoom = _map.zoomLevel
        savedMapType = mapType
149
        if(!isDefaultSet) {
Don Gagne's avatar
Don Gagne committed
150 151
            mapType = offlineMapView._currentSelection.mapTypeStr
            _map.center = midPoint(offlineMapView._currentSelection.topleftLat, offlineMapView._currentSelection.bottomRightLat, offlineMapView._currentSelection.topleftLon, offlineMapView._currentSelection.bottomRightLon)
152
            //-- Delineate Set Region
Don Gagne's avatar
Don Gagne committed
153 154 155 156
            var x0 = offlineMapView._currentSelection.topleftLon
            var x1 = offlineMapView._currentSelection.bottomRightLon
            var y0 = offlineMapView._currentSelection.topleftLat
            var y1 = offlineMapView._currentSelection.bottomRightLat
157 158 159 160
            mapBoundary.topLeft     = QtPositioning.coordinate(y0, x0)
            mapBoundary.bottomRight = QtPositioning.coordinate(y1, x1)
            mapBoundary.visible = true
            _map.fitViewportToMapItems()
161 162
        }
        _tileSetList.visible = false
163
        addNewSetView.visible = false
164
        if(isDefaultSet) {
Don Gagne's avatar
Don Gagne committed
165
            defaultInfoView.visible = true
166
        } else {
167
            infoView.visible = true
168 169 170 171
        }
    }

    function leaveInfoView() {
172
        mapBoundary.visible = false
173 174 175
        _map.center = savedCenter
        _map.zoomLevel = savedZoom
        mapType = savedMapType
176 177 178 179 180
    }

    function resetMapToDefaults() {
        _map.center = QGroundControl.flightMapPosition
        _map.zoomLevel = QGroundControl.flightMapZoom
181 182
    }

dogmaphobic's avatar
dogmaphobic committed
183 184 185 186 187 188
    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
    }

    onMapTypeChanged: {
        updateMap()
189 190 191
        if(isMapInteractive) {
            QGroundControl.mapEngineManager.saveSetting(mapKey, mapType)
        }
dogmaphobic's avatar
dogmaphobic committed
192 193 194 195 196 197 198 199
    }

    MessageDialog {
        id:         errorDialog
        visible:    false
        text:       QGroundControl.mapEngineManager.errorMessage
        icon:       StandardIcon.Critical
        standardButtons: StandardButton.Ok
Don Gagne's avatar
Don Gagne committed
200
        title:      qsTr("Error Message")
dogmaphobic's avatar
dogmaphobic committed
201 202 203 204
        onYes: {
            errorDialog.visible = false
        }
    }
Don Gagne's avatar
Don Gagne committed
205

Don Gagne's avatar
Don Gagne committed
206 207 208 209 210 211 212 213 214 215 216
    Component {
        id: optionsDialogComponent

        QGCViewDialog {
            id: optionDialog

            function accept() {
                QGroundControl.mapEngineManager.mapboxToken  = mapBoxToken.text
                QGroundControl.mapEngineManager.maxDiskCache = parseInt(maxCacheSize.text)
                QGroundControl.mapEngineManager.maxMemCache  = parseInt(maxCacheMemSize.text)
                optionDialog.hideDialog()
dogmaphobic's avatar
dogmaphobic committed
217
            }
Don Gagne's avatar
Don Gagne committed
218

Don Gagne's avatar
Don Gagne committed
219 220 221
            QGCFlickable {
                anchors.fill:   parent
                contentHeight:  optionsColumn.height
222

Don Gagne's avatar
Don Gagne committed
223 224 225 226 227 228 229
                Column {
                    id:                 optionsColumn
                    anchors.margins:    ScreenTools.defaultFontPixelWidth
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    anchors.top:        parent.top
                    spacing:            ScreenTools.defaultFontPixelHeight / 2
230

Don Gagne's avatar
Don Gagne committed
231
                    QGCLabel { text:       qsTr("Max Cache Disk Size (MB):") }
232

Don Gagne's avatar
Don Gagne committed
233 234 235 236 237 238 239
                    QGCTextField {
                        id:                 maxCacheSize
                        maximumLength:      6
                        inputMethodHints:   Qt.ImhDigitsOnly
                        validator:          IntValidator {bottom: 1; top: 262144;}
                        text:               QGroundControl.mapEngineManager.maxDiskCache
                    }
240

Don Gagne's avatar
Don Gagne committed
241 242 243 244 245 246 247 248 249 250
                    Item { width: 1; height: 1 }

                    QGCLabel { text:       qsTr("Max Cache Memory Size (MB):") }

                    QGCTextField {
                        id:                 maxCacheMemSize
                        maximumLength:      4
                        inputMethodHints:   Qt.ImhDigitsOnly
                        validator:          IntValidator {bottom: 1; top: 4096;}
                        text:               QGroundControl.mapEngineManager.maxMemCache
dogmaphobic's avatar
dogmaphobic committed
251
                    }
Don Gagne's avatar
Don Gagne committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289

                    QGCLabel {
                        font.pointSize: _adjustableFontPointSize
                        text:           qsTr("Memory cache changes require a restart to take effect.")
                    }

                    Item { width: 1; height: 1 }

                    QGCLabel { text: qsTr("MapBox Access Token") }

                    QGCTextField {
                        id:             mapBoxToken
                        maximumLength:  256
                        width:          ScreenTools.defaultFontPixelWidth * 30
                        text:           QGroundControl.mapEngineManager.mapboxToken
                    }

                    QGCLabel {
                        text:           qsTr("With an access token, you can use MapBox Maps.")
                        font.pointSize: _adjustableFontPointSize
                    }
                } // GridLayout
            } // QGCFlickable
        } // QGCViewDialog - optionsDialog
    } // Component - optionsDialogComponent

    Component {
        id: deleteConfirmationDialogComponent

        QGCViewMessage {
            id:         deleteConfirmationDialog
            message:    qsTr("Delete %1 and all its tiles.\n\nIs this really what you want?").arg(offlineMapView._currentSelection.name)

            function accept() {
                QGroundControl.mapEngineManager.deleteTileSet(offlineMapView._currentSelection)
                deleteConfirmationDialog.hideDialog()
                leaveInfoView()
                showList()
dogmaphobic's avatar
dogmaphobic committed
290 291 292
            }
        }
    }
Don Gagne's avatar
Don Gagne committed
293

Don Gagne's avatar
Don Gagne committed
294 295
    Component {
        id: deleteSystemSetConfirmationDialogComponent
Don Gagne's avatar
Don Gagne committed
296

Don Gagne's avatar
Don Gagne committed
297 298 299 300 301 302 303 304 305
        QGCViewMessage {
            id:         deleteSystemSetConfirmationDialog
            message:    qsTr("This will delete all tiles INCLUDING the tile sets you have created yourself.\n\nIs this really what you want?")

            function accept() {
                QGroundControl.mapEngineManager.deleteTileSet(offlineMapView._currentSelection)
                deleteSystemSetConfirmationDialog.hideDialog()
                leaveInfoView()
                showList()
dogmaphobic's avatar
dogmaphobic committed
306 307
            }
        }
Don Gagne's avatar
Don Gagne committed
308 309 310 311 312 313 314 315 316
    }

    QGCViewPanel {
        id:                 panel
        anchors.fill:       parent

        Map {
            id:                 _map
            anchors.fill:       parent
317
            center:             QGroundControl.lastKnownHomePosition
Don Gagne's avatar
Don Gagne committed
318 319 320
            visible:            false
            gesture.flickDeceleration:  3000

Don Gagne's avatar
Don Gagne committed
321 322
            property bool isSatelliteMap: activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1

Don Gagne's avatar
Don Gagne committed
323 324 325 326 327 328 329 330 331 332 333
            plugin: Plugin { name: "QGroundControl" }

            MapRectangle {
                id:             mapBoundary
                border.width:   2
                border.color:   "red"
                color:          Qt.rgba(1,0,0,0.05)
                smooth:         true
                antialiasing:   true
            }

334
            Component.onCompleted: resetMapToDefaults()
Don Gagne's avatar
Don Gagne committed
335

336 337 338 339 340 341 342 343
            onCenterChanged:    handleChanges()
            onZoomLevelChanged: handleChanges()
            onWidthChanged:     handleChanges()
            onHeightChanged:    handleChanges()

            // Used to make pinch zoom work
            MouseArea {
                anchors.fill: parent
dogmaphobic's avatar
dogmaphobic committed
344
            }
345

Don Gagne's avatar
Don Gagne committed
346 347 348 349 350 351
            MapScale {
                anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
                anchors.bottomMargin:   anchors.leftMargin
                anchors.left:           parent.left
                anchors.bottom:         parent.bottom
                mapControl:             _map
352
            }
Don Gagne's avatar
Don Gagne committed
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375

            //-- Show Set Info
            Rectangle {
                id:                 infoView
                anchors.margins:    ScreenTools.defaultFontPixelWidth
                y:                  Math.max(anchors.margins, (parent.height - (anchors.margins * 2) - height) / 2)
                anchors.right:      parent.right
                width:              Math.max(ScreenTools.defaultFontPixelWidth  * 20, controlInfoFlickable.width + (infoView._margins * 2))
                height:             Math.min(parent.height - (anchors.margins * 2), controlInfoFlickable.y + controlInfoColumn.height + ScreenTools.defaultFontPixelHeight)
                color:              qgcPal.window
                opacity:            0.85
                radius:             ScreenTools.defaultFontPixelWidth * 0.5
                visible:            false

                readonly property real _margins: ScreenTools.defaultFontPixelHeight / 2

                QGCLabel {
                    anchors.margins:    ScreenTools.defaultFontPixelHeight / 4
                    anchors.top:        parent.top
                    anchors.right:      parent.right
                    text:               "X"
                }

376
                Column {
Don Gagne's avatar
Don Gagne committed
377 378 379 380 381 382
                    id:                 titleColumn
                    anchors.margins:    infoView._margins
                    anchors.top:        parent.top
                    anchors.left:       parent.left
                    anchors.right:      parent.right

383
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
384 385 386 387 388 389
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
                        text:           offlineMapView._currentSelection ? offlineMapView._currentSelection.name : ""
                        font.pointSize: _saveRealEstate ? ScreenTools.defaultFontPointSize : ScreenTools.mediumFontPointSize
                        horizontalAlignment: Text.AlignHCenter
390
                    }
Don Gagne's avatar
Don Gagne committed
391

392
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
393 394 395 396 397 398
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
                        text:           offlineMapView._currentSelection ? offlineMapView._currentSelection.description : ""
                        visible:        text !== qsTr("Description")
                        horizontalAlignment: Text.AlignHCenter
399
                    }
Don Gagne's avatar
Don Gagne committed
400

401
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
402 403 404 405 406
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
                        text:           offlineMapView._currentSelection ? "(" + offlineMapView._currentSelection.mapTypeStr + ")" : ""
                        horizontalAlignment: Text.AlignHCenter
407
                    }
Don Gagne's avatar
Don Gagne committed
408

409
                }
Don Gagne's avatar
Don Gagne committed
410 411 412 413 414 415 416 417

                MouseArea {
                    anchors.fill:       titleColumn
                    preventStealing:    true

                    onClicked: {
                        leaveInfoView()
                        showList()
418 419
                    }
                }
Don Gagne's avatar
Don Gagne committed
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450

                QGCFlickable {
                    id:                 controlInfoFlickable
                    anchors.margins:    infoView._margins
                    anchors.top:        titleColumn.bottom
                    anchors.bottom:     parent.bottom
                    anchors.left:       parent.left
                    width:              controlInfoColumn.width
                    clip:               true
                    contentHeight:      controlInfoColumn.height

                    Column {
                        id:         controlInfoColumn
                        spacing:    ScreenTools.defaultFontPixelHeight

                        GridLayout {
                            columns:    2
                            rowSpacing: 0

                            QGCLabel { text: qsTr("Min Zoom:") }
                            QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.minZoom : "" }

                            QGCLabel { text: qsTr("Max Zoom:") }
                            QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.maxZoom : "" }

                            QGCLabel { text: qsTr("Total:") }
                            QGCLabel { text: (offlineMapView._currentSelection ? offlineMapView._currentSelection.numTilesStr : "") + " (" + (offlineMapView._currentSelection ? offlineMapView._currentSelection.tilesSizeStr : "") + ")" }

                            QGCLabel {
                                text:       qsTr("Downloaded:")
                                visible:    offlineMapView._currentSelection && !offlineMapView._currentSelection.complete
451
                            }
Don Gagne's avatar
Don Gagne committed
452 453 454
                            QGCLabel {
                                text:       (offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTilesStr : "") + " (" + (offlineMapView._currentSelection ? offlineMapView._currentSelection.savedSizeStr : "") + ")"
                                visible:    offlineMapView._currentSelection && !offlineMapView._currentSelection.complete
455
                            }
Don Gagne's avatar
Don Gagne committed
456 457 458 459 460 461 462 463

                            QGCLabel {
                                text:       qsTr("Error Count:")
                                visible:    offlineMapView._currentSelection && !offlineMapView._currentSelection.complete
                            }
                            QGCLabel {
                                text:       offlineMapView._currentSelection ? offlineMapView._currentSelection.errorCountStr : ""
                                visible:    offlineMapView._currentSelection && !offlineMapView._currentSelection.complete
464 465
                            }
                        }
Don Gagne's avatar
Don Gagne committed
466 467 468 469 470 471 472 473 474

                        QGCButton {
                            text:       qsTr("Resume Download")
                            visible:    offlineMapView._currentSelection && (!offlineMapView._currentSelection.complete && !offlineMapView._currentSelection.downloading)

                            onClicked: {
                                if(offlineMapView._currentSelection)
                                    offlineMapView._currentSelection.resumeDownloadTask()
                            }
475
                        }
Don Gagne's avatar
Don Gagne committed
476 477 478 479 480 481 482 483 484

                        QGCButton {
                            text:       qsTr("Cancel Download")
                            visible:    offlineMapView._currentSelection && (!offlineMapView._currentSelection.complete && offlineMapView._currentSelection.downloading)

                            onClicked: {
                                if(offlineMapView._currentSelection)
                                    offlineMapView._currentSelection.cancelDownloadTask()
                            }
485
                        }
Don Gagne's avatar
Don Gagne committed
486 487 488 489

                        QGCButton {
                            text:       qsTr("Delete")
                            onClicked:  showDialog(deleteConfirmationDialogComponent, qsTr("Confirm Delete"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
490
                        }
Don Gagne's avatar
Don Gagne committed
491 492 493
                    } // Column
                } // QGCFlickable
            } // Rectangle - infoView
494

Don Gagne's avatar
Don Gagne committed
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
            //-- Show Default Set Info
            Rectangle {
                id:                 defaultInfoView
                anchors.margins:    ScreenTools.defaultFontPixelWidth
                y:                  Math.max(anchors.margins, (parent.height - (anchors.margins * 2) - height) / 2)
                anchors.right:      parent.right
                width:              ScreenTools.defaultFontPixelWidth  * 20
                height:             Math.min(parent.height - (anchors.margins * 2), defaultControlInfoFlickable.y + defaultControlInfoColumn.height + ScreenTools.defaultFontPixelHeight)
                color:              qgcPal.window
                opacity:            0.85
                radius:             ScreenTools.defaultFontPixelWidth * 0.5
                visible:            false

                QGCLabel {
                    anchors.margins:    ScreenTools.defaultFontPixelHeight / 4
                    anchors.top:        parent.top
                    anchors.right:      parent.right
                    text:               "X"
dogmaphobic's avatar
dogmaphobic committed
513
                }
Don Gagne's avatar
Don Gagne committed
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536

                Column {
                    id:                 defaultTitleColumn
                    anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
                    anchors.top:        parent.top
                    anchors.left:       parent.left
                    anchors.right:      parent.right

                    QGCLabel {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
                        text:           offlineMapView._currentSelection ? offlineMapView._currentSelection.name : ""
                        font.pointSize: _saveRealEstate ? ScreenTools.defaultFontPointSize : ScreenTools.mediumFontPointSize
                        horizontalAlignment: Text.AlignHCenter
                    }

                    QGCLabel {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
                        text:           qsTr("System Wide Tile Cache")
                        horizontalAlignment: Text.AlignHCenter
dogmaphobic's avatar
dogmaphobic committed
537 538
                    }
                }
Don Gagne's avatar
Don Gagne committed
539 540 541 542 543 544 545 546

                MouseArea {
                    anchors.fill:       defaultTitleColumn
                    preventStealing:    true

                    onClicked: {
                        leaveInfoView()
                        showList()
dogmaphobic's avatar
dogmaphobic committed
547
                    }
dogmaphobic's avatar
dogmaphobic committed
548
                }
Don Gagne's avatar
Don Gagne committed
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572

                QGCFlickable {
                    id:                 defaultControlInfoFlickable
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    anchors.top:        defaultTitleColumn.bottom
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    anchors.bottom:     parent.bottom
                    clip:               true
                    contentHeight:      defaultControlInfoColumn.height

                    Column {
                        id:                 defaultControlInfoColumn
                        anchors.left:       parent.left
                        anchors.right:      parent.right
                        spacing:            ScreenTools.defaultFontPixelHeight

                        GridLayout {
                            columns:    2
                            rowSpacing: 0

                            QGCLabel {
                                Layout.columnSpan:  2
                                text:               qsTr("System Cache")
dogmaphobic's avatar
dogmaphobic committed
573
                            }
Don Gagne's avatar
Don Gagne committed
574 575 576 577 578 579 580 581 582 583 584

                            QGCLabel { text: qsTr("Size:") }
                            QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.tilesSizeStr : "" }

                            QGCLabel { text: qsTr("Tile Count:") }
                            QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.numTilesStr : "" }

                            Item {
                                width:              1
                                height:             ScreenTools.defaultFontPixelHeight
                                Layout.columnSpan:  2
dogmaphobic's avatar
dogmaphobic committed
585
                            }
Don Gagne's avatar
Don Gagne committed
586 587 588 589 590 591 592 593 594 595 596

                            QGCLabel {
                                Layout.columnSpan:  2
                                text:               qsTr("All Sets")
                            }

                            QGCLabel { text: qsTr("Size:") }
                            QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.savedSizeStr : "" }

                            QGCLabel { text: qsTr("Tile Count:") }
                            QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTilesStr : ""}
dogmaphobic's avatar
dogmaphobic committed
597
                        }
Don Gagne's avatar
Don Gagne committed
598 599 600 601

                        QGCButton {
                            text:       qsTr("Delete All")
                            onClicked:  showDialog(deleteSystemSetConfirmationDialogComponent, qsTr("Confirm Delete All"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
602
                        }
Don Gagne's avatar
Don Gagne committed
603 604 605 606
                    } // Column
                } // QGCFlickable
            } // Rectangle - defaultInfoView

Don Gagne's avatar
Don Gagne committed
607 608 609 610
            Item {
                id:             addNewSetView
                anchors.fill:   parent
                visible:        false
Don Gagne's avatar
Don Gagne committed
611

Don Gagne's avatar
Don Gagne committed
612 613 614 615
                Map {
                    id:                 minZoomPreview
                    anchors.leftMargin: ScreenTools.defaultFontPixelWidth /2
                    anchors.topMargin:  anchors.leftMargin
Don Gagne's avatar
Don Gagne committed
616
                    anchors.top:        parent.top
Don Gagne's avatar
Don Gagne committed
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
                    anchors.left:       parent.left
                    width:              parent.width / 4
                    height:             parent.height / 4
                    center:             _map.center
                    activeMapType:      _map.activeMapType
                    zoomLevel:          sliderMinZoom.value
                    gesture.enabled:    false
                    visible:            _showPreview

                    property bool isSatelliteMap: activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1

                    plugin: Plugin { name: "QGroundControl" }

                    MapScale {
                        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
                        anchors.bottomMargin:   anchors.leftMargin
                        anchors.left:           parent.left
                        anchors.bottom:         parent.bottom
                        mapControl:             parent
                    }
dogmaphobic's avatar
dogmaphobic committed
637
                }
638

Don Gagne's avatar
Don Gagne committed
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
                Map {
                    id:                 maxZoomPreview
                    anchors.topMargin:  minZoomPreview.anchors.topMargin
                    anchors.left:       minZoomPreview.left
                    anchors.top:        minZoomPreview.bottom
                    width:              minZoomPreview.width
                    height:             minZoomPreview.height
                    center:             _map.center
                    activeMapType:      _map.activeMapType
                    zoomLevel:          sliderMaxZoom.value
                    gesture.enabled:    false
                    visible:            _showPreview

                    property bool isSatelliteMap: activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1

                    plugin: Plugin { name: "QGroundControl" }

                    MapScale {
                        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
                        anchors.bottomMargin:   anchors.leftMargin
                        anchors.left:           parent.left
                        anchors.bottom:         parent.bottom
                        mapControl:             parent
                    }
                }

                Rectangle {
                    anchors.fill:   minZoomPreview
                    border.color:   _mapAdjustedColor
                    color:          "transparent"
                    visible:        _showPreview

                    QGCLabel {
                        anchors.fill:           parent
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                        color:                  _mapAdjustedColor
                        text:                   qsTr("Min Zoom: %1").arg(sliderMinZoom.value)
                    }
                }

                Rectangle {
                    anchors.fill:   maxZoomPreview
                    border.color:   _mapAdjustedColor
                    color:          "transparent"
                    visible:        _showPreview

                    QGCLabel {
                        anchors.fill:           parent
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                        color:                  _mapAdjustedColor
                        text:                   qsTr("Max Zoom: %1").arg(sliderMaxZoom.value)
                    }
dogmaphobic's avatar
dogmaphobic committed
693
                }
Don Gagne's avatar
Don Gagne committed
694 695

                MouseArea {
Don Gagne's avatar
Don Gagne committed
696 697 698
                    anchors.fill:   minZoomPreview
                    visible:        _showPreview
                    onClicked:      _showPreview = false
dogmaphobic's avatar
dogmaphobic committed
699
                }
Don Gagne's avatar
Don Gagne committed
700

Don Gagne's avatar
Don Gagne committed
701 702 703 704 705
                MouseArea {
                    anchors.fill:   maxZoomPreview
                    visible:        _showPreview
                    onClicked:      _showPreview = false
                }
Don Gagne's avatar
Don Gagne committed
706

Don Gagne's avatar
Don Gagne committed
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
                QGCButton {
                    anchors.left:   minZoomPreview.left
                    anchors.top:    minZoomPreview.top
                    text:           "Show zoom previews"
                    visible:        !_showPreview
                    onClicked:      _showPreview = !_showPreview
                }

                //-- Add new set dialog
                Rectangle {
                    anchors.margins:    ScreenTools.defaultFontPixelWidth
                    y:                  Math.max(anchors.margins, (parent.height - (anchors.margins * 2) - height) / 2)
                    anchors.right:      parent.right
                    width:              ScreenTools.defaultFontPixelWidth  * 20
                    height:             Math.min(parent.height - (anchors.margins * 2), addNewSetFlickable.y + addNewSetColumn.height + ScreenTools.defaultFontPixelHeight)
                    color:              qgcPal.window
                    opacity:            0.85
                    radius:             ScreenTools.defaultFontPixelWidth * 0.5

                    QGCLabel {
                        anchors.margins:    ScreenTools.defaultFontPixelHeight / 4
                        anchors.top:        parent.top
Don Gagne's avatar
Don Gagne committed
729
                        anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
730 731
                        text:               "X"
                    }
Don Gagne's avatar
Don Gagne committed
732

Don Gagne's avatar
Don Gagne committed
733 734 735 736 737 738 739 740 741 742 743
                    QGCLabel {
                        id:                 addNewSetLabel
                        anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
                        anchors.top:        parent.top
                        anchors.left:       parent.left
                        anchors.right:      parent.right
                        wrapMode:           Text.WordWrap
                        text:               qsTr("Add New Set")
                        font.pointSize:     _saveRealEstate ? ScreenTools.defaultFontPointSize : ScreenTools.mediumFontPointSize
                        horizontalAlignment: Text.AlignHCenter
                    }
Don Gagne's avatar
Don Gagne committed
744

Don Gagne's avatar
Don Gagne committed
745 746 747 748 749
                    MouseArea {
                        anchors.fill:       addNewSetLabel
                        preventStealing:    true
                        onClicked:          showList()
                    }
Don Gagne's avatar
Don Gagne committed
750

Don Gagne's avatar
Don Gagne committed
751 752 753 754 755 756 757 758 759 760 761 762
                    QGCFlickable {
                        id:                     addNewSetFlickable
                        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth
                        anchors.rightMargin:    anchors.leftMargin
                        anchors.topMargin:      ScreenTools.defaultFontPixelWidth / 3
                        anchors.bottomMargin:   anchors.topMargin
                        anchors.top:            addNewSetLabel.bottom
                        anchors.left:           parent.left
                        anchors.right:          parent.right
                        anchors.bottom:         parent.bottom
                        clip:                   true
                        contentHeight:          addNewSetColumn.height
Don Gagne's avatar
Don Gagne committed
763 764

                        Column {
Don Gagne's avatar
Don Gagne committed
765
                            id:                 addNewSetColumn
Don Gagne's avatar
Don Gagne committed
766 767
                            anchors.left:       parent.left
                            anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
768
                            spacing:            ScreenTools.defaultFontPixelHeight / (ScreenTools.isTinyScreen ? 4 : 2)
Don Gagne's avatar
Don Gagne committed
769

Don Gagne's avatar
Don Gagne committed
770 771 772
                            Column {
                                anchors.left:       parent.left
                                anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
773

Don Gagne's avatar
Don Gagne committed
774
                                QGCLabel { text: qsTr("Name:") }
Don Gagne's avatar
Don Gagne committed
775

Don Gagne's avatar
Don Gagne committed
776 777 778 779
                                QGCTextField {
                                    id:             setName
                                    anchors.left:   parent.left
                                    anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
780
                                }
dogmaphobic's avatar
dogmaphobic committed
781
                            }
Don Gagne's avatar
Don Gagne committed
782 783 784 785 786 787

                            Column {
                                anchors.left:       parent.left
                                anchors.right:      parent.right

                                QGCLabel {
Don Gagne's avatar
Don Gagne committed
788 789
                                    text:       qsTr("Map type:")
                                    visible:    !_saveRealEstate
Don Gagne's avatar
Don Gagne committed
790 791
                                }

Don Gagne's avatar
Don Gagne committed
792 793 794 795 796 797 798 799 800 801 802
                                QGCComboBox {
                                    id:             mapCombo
                                    anchors.left:   parent.left
                                    anchors.right:  parent.right
                                    model:          QGroundControl.mapEngineManager.mapList

                                    onActivated: {
                                        mapType = textAt(index)
                                        if(_dropButtonsExclusiveGroup.current)
                                            _dropButtonsExclusiveGroup.current.checked = false
                                        _dropButtonsExclusiveGroup.current = null
Don Gagne's avatar
Don Gagne committed
803 804
                                    }

Don Gagne's avatar
Don Gagne committed
805 806 807 808 809 810
                                    Component.onCompleted: {
                                        var index = mapCombo.find(mapType)
                                        if (index === -1) {
                                            console.warn("Active map name not in combo", mapType)
                                        } else {
                                            mapCombo.currentIndex = index
Don Gagne's avatar
Don Gagne committed
811 812
                                        }
                                    }
Don Gagne's avatar
Don Gagne committed
813 814
                                }
                            }
Don Gagne's avatar
Don Gagne committed
815

Don Gagne's avatar
Don Gagne committed
816 817 818 819 820 821 822 823 824 825 826 827 828 829
                            Rectangle {
                                anchors.left:   parent.left
                                anchors.right:  parent.right
                                height:         zoomColumn.height + ScreenTools.defaultFontPixelHeight / 2
                                color:          qgcPal.window
                                border.color:   qgcPal.text
                                radius:         ScreenTools.defaultFontPixelWidth * 0.5

                                Column {
                                    id:                 zoomColumn
                                    anchors.margins:    ScreenTools.defaultFontPixelHeight / 4
                                    anchors.top:        parent.top
                                    anchors.left:       parent.left
                                    anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
830 831

                                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
832
                                        text:           qsTr("Min Zoom: %1").arg(sliderMinZoom.value)
Don Gagne's avatar
Don Gagne committed
833 834 835
                                        font.pointSize: _adjustableFontPointSize
                                    }

Don Gagne's avatar
Don Gagne committed
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
                                    Slider {
                                        id:                         sliderMinZoom
                                        anchors.left:               parent.left
                                        anchors.right:              parent.right
                                        height:                     setName.height
                                        minimumValue:               minZoomLevel
                                        maximumValue:               maxZoomLevel
                                        stepSize:                   1
                                        updateValueWhileDragging:   true

                                        property real _savedZoom

                                        Component.onCompleted: sliderMinZoom.value = _map.zoomLevel - 2

                                        onValueChanged: {
                                            if(sliderMinZoom.value > sliderMaxZoom.value) {
                                                sliderMaxZoom.value = sliderMinZoom.value
                                            }
                                            handleChanges()
                                        }
                                    } // Slider - min zoom

Don Gagne's avatar
Don Gagne committed
858
                                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
859 860
                                        text:                   qsTr("Max Zoom: %1").arg(sliderMaxZoom.value)
                                        font.pointSize:         _adjustableFontPointSize
Don Gagne's avatar
Don Gagne committed
861
                                    }
Don Gagne's avatar
Don Gagne committed
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905

                                    Slider {
                                        id:                         sliderMaxZoom
                                        anchors.left:               parent.left
                                        anchors.right:              parent.right
                                        height:                     setName.height
                                        minimumValue:               minZoomLevel
                                        maximumValue:               maxZoomLevel
                                        stepSize:                   1
                                        updateValueWhileDragging:   true

                                        property real _savedZoom

                                        Component.onCompleted: sliderMaxZoom.value = _map.zoomLevel + 2

                                        onValueChanged: {
                                            if(sliderMaxZoom.value < sliderMinZoom.value) {
                                                sliderMinZoom.value = sliderMaxZoom.value
                                            }
                                            handleChanges()
                                        }
                                    } // Slider - max zoom

                                    GridLayout {
                                        columns:    2
                                        rowSpacing: 0

                                        QGCLabel {
                                            text:           qsTr("Tile Count")
                                            font.pointSize: _adjustableFontPointSize
                                        }
                                        QGCLabel {
                                            text:           QGroundControl.mapEngineManager.tileCountStr
                                            font.pointSize: _adjustableFontPointSize
                                        }

                                        QGCLabel {
                                            text:           qsTr("Set Size (Est)")
                                            font.pointSize: _adjustableFontPointSize
                                        }
                                        QGCLabel {
                                            text:           QGroundControl.mapEngineManager.tileSizeStr
                                            font.pointSize: _adjustableFontPointSize
                                        }
Don Gagne's avatar
Don Gagne committed
906
                                    }
Don Gagne's avatar
Don Gagne committed
907 908
                                } // Column - Zoom info
                            } // Rectangle - Zoom info
Don Gagne's avatar
Don Gagne committed
909

Don Gagne's avatar
Don Gagne committed
910 911 912 913
                            QGCButton {
                                text:       _tooManyTiles ? qsTr("Too many tiles") : qsTr("Download")
                                enabled:    !_tooManyTiles && setName.text.length > 0
                                anchors.horizontalCenter: parent.horizontalCenter
Don Gagne's avatar
Don Gagne committed
914

Don Gagne's avatar
Don Gagne committed
915
                                property bool _tooManyTiles: QGroundControl.mapEngineManager.tileCount > _maxTilesForDownload
916

Don Gagne's avatar
Don Gagne committed
917 918 919 920 921
                                onClicked: {
                                    if(QGroundControl.mapEngineManager.findName(setName.text)) {
                                        duplicateName.visible = true
                                    } else {
                                        /* This does not work if hosted by QQuickWidget. Waiting until we're 100% QtQuick
Don Gagne's avatar
Don Gagne committed
922 923 924 925
                                    var mapImage
                                    _map.grabToImage(function(result) { mapImage = result; })
                                    QGroundControl.mapEngineManager.startDownload(setName.text, "Description", mapType, mapImage);
                                    */
Don Gagne's avatar
Don Gagne committed
926 927 928
                                        QGroundControl.mapEngineManager.startDownload(setName.text, "Description" /* Description */, mapType);
                                        showList()
                                    }
Don Gagne's avatar
Don Gagne committed
929
                                }
dogmaphobic's avatar
dogmaphobic committed
930
                            }
Don Gagne's avatar
Don Gagne committed
931 932 933 934
                        } // Column
                    } // QGCFlickable
                } // Rectangle - Add new set dialog
            } // Item - Add new set view
Don Gagne's avatar
Don Gagne committed
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
        } // Map

        QGCFlickable {
            id:                 _tileSetList
            clip:               true
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.top:        parent.top
            anchors.bottom:     _optionsButton.top
            anchors.left:       parent.left
            anchors.right:      parent.right
            contentHeight:      _cacheList.height

            Column {
                id:         _cacheList
                width:      Math.min(_tileSetList.width, (ScreenTools.defaultFontPixelWidth  * 50).toFixed(0))
                spacing:    ScreenTools.defaultFontPixelHeight * 0.5
                anchors.horizontalCenter: parent.horizontalCenter

                OfflineMapButton {
                    id:             firstButton
                    text:           qsTr("Add new set")
                    width:          _cacheList.width
                    height:         ScreenTools.defaultFontPixelHeight * 2
                    onClicked: {
                        offlineMapView._currentSelection = null
                        addNewSet()
dogmaphobic's avatar
dogmaphobic committed
961 962
                    }
                }
Don Gagne's avatar
Don Gagne committed
963 964 965 966 967 968 969 970 971 972 973
                Repeater {
                    model: QGroundControl.mapEngineManager.tileSets
                    delegate: OfflineMapButton {
                        text:           object.name
                        size:           object.downloadStatus
                        complete:       object.complete
                        width:          firstButton.width
                        height:         ScreenTools.defaultFontPixelHeight * 2
                        onClicked: {
                            offlineMapView._currentSelection = object
                            showInfo()
dogmaphobic's avatar
dogmaphobic committed
974
                        }
dogmaphobic's avatar
dogmaphobic committed
975 976 977 978
                    }
                }
            }
        }
Don Gagne's avatar
Don Gagne committed
979 980 981 982 983 984 985 986 987 988 989 990

        QGCButton {
            id:              _optionsButton
            text:            qsTr("Options")
            visible:         _tileSetList.visible
            anchors.bottom:  parent.bottom
            anchors.right:   parent.right
            anchors.margins: ScreenTools.defaultFontPixelWidth
            onClicked:       showDialog(optionsDialogComponent, qsTr("Offline Maps Options"), qgcView.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
        }
    } // QGCViewPanel
} // QGCView