OfflineMap.qml 40.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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9

10
import QtQuick                  2.7
11
import QtQuick.Controls         1.4
12
import QtQuick.Controls.Styles  1.4
13
import QtQuick.Dialogs          1.2
14
import QtQuick.Layouts          1.3
Don Gagne's avatar
Don Gagne committed
15
import QtLocation               5.6
16
import QtPositioning            5.5
dogmaphobic's avatar
dogmaphobic committed
17

Don Gagne's avatar
Don Gagne committed
18 19 20 21 22
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
23

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

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

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

33
    property string mapType:            QGroundControl.flightMapSettings.mapProvider + " " + QGroundControl.flightMapSettings.mapType
34
    property bool   isMapInteractive:   false
35 36 37
    property var    savedCenter:        undefined
    property real   savedZoom:          3
    property string savedMapType:       ""
Don Gagne's avatar
Don Gagne committed
38
    property bool   _showPreview:       true
dogmaphobic's avatar
dogmaphobic committed
39
    property bool   _defaultSet:        offlineMapView && offlineMapView._currentSelection && offlineMapView._currentSelection.defaultSet
40
    property real   _margins:           ScreenTools.defaultFontPixelWidth /2
dogmaphobic's avatar
dogmaphobic committed
41

dogmaphobic's avatar
dogmaphobic committed
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

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

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

dogmaphobic's avatar
dogmaphobic committed
50
    readonly property int _maxTilesForDownload: 100000
51

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

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

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

    ExclusiveGroup { id: setGroup }

    function handleChanges() {
73
        if(isMapInteractive) {
Don Gagne's avatar
Don Gagne committed
74 75
            var xl = 0
            var yl = 0
76 77
            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
78 79
            var c0 = _map.toCoordinate(Qt.point(xl, yl))
            var c1 = _map.toCoordinate(Qt.point(xr, yr))
80
            QGroundControl.mapEngineManager.updateForCurrentView(c0.longitude, c0.latitude, c1.longitude, c1.latitude, sliderMinZoom.value, sliderMaxZoom.value, mapType)
dogmaphobic's avatar
dogmaphobic committed
81 82 83 84 85 86 87 88 89 90 91 92 93
        }
    }

    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
94
    function addNewSet() {
95
        isMapInteractive = true
96
        mapType = QGroundControl.flightMapSettings.mapProvider + " " + QGroundControl.flightMapSettings.mapType
97 98
        resetMapToDefaults()
        handleChanges()
99
        _map.visible = true
dogmaphobic's avatar
dogmaphobic committed
100
        _tileSetList.visible = false
Don Gagne's avatar
Don Gagne committed
101 102
        infoView.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
        infoView.visible = false
        addNewSetView.visible = false
dogmaphobic's avatar
dogmaphobic committed
111 112 113
    }

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

121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    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
142 143 144 145 146
        _map.visible = true
        isMapInteractive = false
        savedCenter = _map.toCoordinate(Qt.point(_map.width / 2, _map.height / 2))
        savedZoom = _map.zoomLevel
        savedMapType = mapType
dogmaphobic's avatar
dogmaphobic committed
147
        if(!offlineMapView._currentSelection.defaultSet) {
Don Gagne's avatar
Don Gagne committed
148 149
            mapType = offlineMapView._currentSelection.mapTypeStr
            _map.center = midPoint(offlineMapView._currentSelection.topleftLat, offlineMapView._currentSelection.bottomRightLat, offlineMapView._currentSelection.topleftLon, offlineMapView._currentSelection.bottomRightLon)
150
            //-- Delineate Set Region
Don Gagne's avatar
Don Gagne committed
151 152 153 154
            var x0 = offlineMapView._currentSelection.topleftLon
            var x1 = offlineMapView._currentSelection.bottomRightLon
            var y0 = offlineMapView._currentSelection.topleftLat
            var y1 = offlineMapView._currentSelection.bottomRightLat
155 156 157
            mapBoundary.topLeft     = QtPositioning.coordinate(y0, x0)
            mapBoundary.bottomRight = QtPositioning.coordinate(y1, x1)
            mapBoundary.visible = true
dogmaphobic's avatar
dogmaphobic committed
158 159 160
            // Some times, for whatever reason, the bounding box is correct (around ETH for instance), but the rectangle is drawn across the planet.
            // When that happens, the "_map.fitViewportToMapItems()" below makes the map to zoom to the entire earth.
            //console.log("Map boundary: " + mapBoundary.topLeft + " " + mapBoundary.bottomRight)
161
            _map.fitViewportToMapItems()
162 163
        }
        _tileSetList.visible = false
164
        addNewSetView.visible = false
dogmaphobic's avatar
dogmaphobic committed
165
        infoView.visible = true
166 167 168
    }

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

    function resetMapToDefaults() {
        _map.center = QGroundControl.flightMapPosition
        _map.zoomLevel = QGroundControl.flightMapZoom
178 179
    }

dogmaphobic's avatar
dogmaphobic committed
180 181 182 183 184 185
    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
    }

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

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

Don Gagne's avatar
Don Gagne committed
203 204 205 206 207 208 209 210 211 212 213
    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
214
            }
Don Gagne's avatar
Don Gagne committed
215

Don Gagne's avatar
Don Gagne committed
216 217 218
            QGCFlickable {
                anchors.fill:   parent
                contentHeight:  optionsColumn.height
219

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

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

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

Don Gagne's avatar
Don Gagne committed
238 239 240 241 242 243 244 245
                    Item { width: 1; height: 1 }

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

                    QGCTextField {
                        id:                 maxCacheMemSize
                        maximumLength:      4
                        inputMethodHints:   Qt.ImhDigitsOnly
246
                        validator:          IntValidator {bottom: 1; top: 1024;}
Don Gagne's avatar
Don Gagne committed
247
                        text:               QGroundControl.mapEngineManager.maxMemCache
dogmaphobic's avatar
dogmaphobic committed
248
                    }
Don Gagne's avatar
Don Gagne committed
249 250 251 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

                    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 {
dogmaphobic's avatar
dogmaphobic committed
278 279 280 281 282 283
            id:  deleteConfirmationDialog
            message: {
                if(offlineMapView._currentSelection.defaultSet)
                    return qsTr("This will delete all tiles INCLUDING the tile sets you have created yourself.\n\nIs this really what you want?");
                else
                    return qsTr("Delete %1 and all its tiles.\n\nIs this really what you want?").arg(offlineMapView._currentSelection.name);
dogmaphobic's avatar
dogmaphobic committed
284
            }
Don Gagne's avatar
Don Gagne committed
285 286
            function accept() {
                QGroundControl.mapEngineManager.deleteTileSet(offlineMapView._currentSelection)
dogmaphobic's avatar
dogmaphobic committed
287
                deleteConfirmationDialog.hideDialog()
Don Gagne's avatar
Don Gagne committed
288 289
                leaveInfoView()
                showList()
dogmaphobic's avatar
dogmaphobic committed
290 291
            }
        }
Don Gagne's avatar
Don Gagne committed
292 293 294 295 296 297 298 299 300
    }

    QGCViewPanel {
        id:                 panel
        anchors.fill:       parent

        Map {
            id:                 _map
            anchors.fill:       parent
301
            center:             QGroundControl.lastKnownHomePosition
Don Gagne's avatar
Don Gagne committed
302 303 304
            visible:            false
            gesture.flickDeceleration:  3000

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

Don Gagne's avatar
Don Gagne committed
307 308 309 310 311 312 313 314 315 316 317
            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
            }

318
            Component.onCompleted: resetMapToDefaults()
Don Gagne's avatar
Don Gagne committed
319

320 321 322 323 324 325 326 327
            onCenterChanged:    handleChanges()
            onZoomLevelChanged: handleChanges()
            onWidthChanged:     handleChanges()
            onHeightChanged:    handleChanges()

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

330 331 332 333 334 335 336 337 338 339 340
            CenterMapDropButton {
                anchors.margins:    _margins
                anchors.left:       parent.left
                anchors.top:        parent.top
                map:                _map
                z:                  QGroundControl.zOrderTopMost
                showMission:        false
                showAllItems:       false
                visible:            addNewSetView.visible
            }

Don Gagne's avatar
Don Gagne committed
341 342 343 344 345 346
            MapScale {
                anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
                anchors.bottomMargin:   anchors.leftMargin
                anchors.left:           parent.left
                anchors.bottom:         parent.bottom
                mapControl:             _map
347
            }
Don Gagne's avatar
Don Gagne committed
348

dogmaphobic's avatar
dogmaphobic committed
349
            //-----------------------------------------------------------------
Don Gagne's avatar
Don Gagne committed
350 351 352
            //-- Show Set Info
            Rectangle {
                id:                 infoView
dogmaphobic's avatar
dogmaphobic committed
353
                anchors.margins:    ScreenTools.defaultFontPixelHeight
Don Gagne's avatar
Don Gagne committed
354
                anchors.right:      parent.right
dogmaphobic's avatar
dogmaphobic committed
355 356 357 358
                anchors.verticalCenter: parent.verticalCenter
                width:              tileInfoColumn.width  + (ScreenTools.defaultFontPixelWidth  * 2)
                height:             tileInfoColumn.height + (ScreenTools.defaultFontPixelHeight * 2)
                color:              Qt.rgba(qgcPal.window.r, qgcPal.window.g, qgcPal.window.b, 0.85)
Don Gagne's avatar
Don Gagne committed
359 360
                radius:             ScreenTools.defaultFontPixelWidth * 0.5
                visible:            false
dogmaphobic's avatar
dogmaphobic committed
361 362 363
                property bool       _extraButton:   !_defaultSet && ((!offlineMapView._currentSelection.complete && !offlineMapView._currentSelection.downloading) || (!offlineMapView._currentSelection.complete && offlineMapView._currentSelection.downloading))
                property real       _labelWidth:    ScreenTools.defaultFontPixelWidth * 10
                property real       _valueWidth:    ScreenTools.defaultFontPixelWidth * 14
364
                Column {
dogmaphobic's avatar
dogmaphobic committed
365 366 367 368
                    id:                 tileInfoColumn
                    anchors.margins:    ScreenTools.defaultFontPixelHeight * 0.5
                    spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                    anchors.centerIn:   parent
369
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
370 371 372 373 374 375
                        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
376 377
                    }
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
378 379 380
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
dogmaphobic's avatar
dogmaphobic committed
381 382 383 384 385 386 387 388 389
                        text: {
                            if(offlineMapView._currentSelection) {
                                if(offlineMapView._currentSelection.defaultSet)
                                    return qsTr("System Wide Tile Cache");
                                else
                                    return "(" + offlineMapView._currentSelection.mapTypeStr + ")"
                            } else
                                return "";
                        }
Don Gagne's avatar
Don Gagne committed
390
                        horizontalAlignment: Text.AlignHCenter
391
                    }
dogmaphobic's avatar
dogmaphobic committed
392 393 394 395 396 397 398
                    //-- Tile Sets
                    Row {
                        spacing:    ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    !_defaultSet
                        QGCLabel {  text: qsTr("Zoom Levels:"); width: infoView._labelWidth; }
                        QGCLabel {  text: offlineMapView._currentSelection ? (offlineMapView._currentSelection.minZoom + " - " + offlineMapView._currentSelection.maxZoom) : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
399
                    }
dogmaphobic's avatar
dogmaphobic committed
400 401 402 403 404 405 406 407 408 409 410 411 412
                    Row {
                        spacing:    ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    !_defaultSet
                        QGCLabel {  text: qsTr("Total:"); width: infoView._labelWidth; }
                        QGCLabel {  text: (offlineMapView._currentSelection ? offlineMapView._currentSelection.totalTileCountStr : "") + " (" + (offlineMapView._currentSelection ? offlineMapView._currentSelection.totalTilesSizeStr : "") + ")"; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }
                    Row {
                        spacing:    ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    offlineMapView && offlineMapView._currentSelection && !_defaultSet && offlineMapView._currentSelection.uniqueTileCount > 0
                        QGCLabel {  text: qsTr("Unique:"); width: infoView._labelWidth; }
                        QGCLabel {  text: (offlineMapView._currentSelection ? offlineMapView._currentSelection.uniqueTileCountStr : "") + " (" + (offlineMapView._currentSelection ? offlineMapView._currentSelection.uniqueTileSizeStr : "") + ")"; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
413
                    }
Don Gagne's avatar
Don Gagne committed
414

dogmaphobic's avatar
dogmaphobic committed
415 416 417 418 419 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
                    Row {
                        spacing:    ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    offlineMapView && offlineMapView._currentSelection && !_defaultSet && !offlineMapView._currentSelection.complete
                        QGCLabel {  text: qsTr("Downloaded:"); width: infoView._labelWidth; }
                        QGCLabel {  text: (offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTileCountStr : "") + " (" + (offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTileSizeStr : "") + ")"; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }
                    Row {
                        spacing:    ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    offlineMapView && offlineMapView._currentSelection && !_defaultSet && !offlineMapView._currentSelection.complete && offlineMapView._currentSelection.errorCount > 0
                        QGCLabel {  text: qsTr("Error Count:"); width: infoView._labelWidth; }
                        QGCLabel {  text: offlineMapView._currentSelection ? offlineMapView._currentSelection.errorCountStr : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }
                    //-- Default Tile Set
                    Row {
                        spacing:    ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    _defaultSet
                        QGCLabel { text: qsTr("Size:"); width: infoView._labelWidth; }
                        QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTileSizeStr  : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }
                    Row {
                        spacing:    ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    _defaultSet
                        QGCLabel { text: qsTr("Tile Count:"); width: infoView._labelWidth; }
                        QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTileCountStr : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }
                    Row {
                        spacing:    ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
Don Gagne's avatar
Don Gagne committed
447 448
                        QGCButton {
                            text:       qsTr("Resume Download")
dogmaphobic's avatar
dogmaphobic committed
449 450
                            visible:    offlineMapView._currentSelection && offlineMapView._currentSelection && !_defaultSet && (!offlineMapView._currentSelection.complete && !offlineMapView._currentSelection.downloading)
                            width:      ScreenTools.defaultFontPixelWidth * 16
Don Gagne's avatar
Don Gagne committed
451 452 453 454
                            onClicked: {
                                if(offlineMapView._currentSelection)
                                    offlineMapView._currentSelection.resumeDownloadTask()
                            }
455
                        }
Don Gagne's avatar
Don Gagne committed
456 457
                        QGCButton {
                            text:       qsTr("Cancel Download")
dogmaphobic's avatar
dogmaphobic committed
458 459
                            visible:    offlineMapView._currentSelection && offlineMapView._currentSelection && !_defaultSet && (!offlineMapView._currentSelection.complete && offlineMapView._currentSelection.downloading)
                            width:      ScreenTools.defaultFontPixelWidth * 16
Don Gagne's avatar
Don Gagne committed
460 461 462 463
                            onClicked: {
                                if(offlineMapView._currentSelection)
                                    offlineMapView._currentSelection.cancelDownloadTask()
                            }
464
                        }
Don Gagne's avatar
Don Gagne committed
465 466
                        QGCButton {
                            text:       qsTr("Delete")
dogmaphobic's avatar
dogmaphobic committed
467
                            width:      ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
Don Gagne's avatar
Don Gagne committed
468
                            onClicked:  showDialog(deleteConfirmationDialogComponent, qsTr("Confirm Delete"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
469
                        }
Don Gagne's avatar
Don Gagne committed
470
                        QGCButton {
dogmaphobic's avatar
dogmaphobic committed
471 472 473 474 475 476
                            text:       qsTr("Close")
                            width:      ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
                            onClicked: {
                                leaveInfoView()
                                showList()
                            }
477
                        }
dogmaphobic's avatar
dogmaphobic committed
478 479 480
                    }
                }
            } // Rectangle - infoView
Don Gagne's avatar
Don Gagne committed
481

dogmaphobic's avatar
dogmaphobic committed
482 483
            //-----------------------------------------------------------------
            //-- Add new set
Don Gagne's avatar
Don Gagne committed
484 485 486 487
            Item {
                id:             addNewSetView
                anchors.fill:   parent
                visible:        false
Don Gagne's avatar
Don Gagne committed
488

489 490 491 492 493 494 495 496 497 498
                Column {
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.leftMargin:     _margins
                    anchors.left:           parent.left
                    spacing:                _margins

                    QGCButton {
                        text:       "Show zoom previews"
                        visible:    !_showPreview
                        onClicked:  _showPreview = !_showPreview
Don Gagne's avatar
Don Gagne committed
499
                    }
500

501 502 503 504 505 506 507 508 509 510
                    Map {
                        id:                 minZoomPreview
                        width:              addNewSetView.width / 4
                        height:             addNewSetView.height / 4
                        center:             _map.center
                        activeMapType:      _map.activeMapType
                        zoomLevel:          sliderMinZoom.value
                        gesture.enabled:    false
                        visible:            _showPreview

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

513 514 515 516 517 518 519 520 521
                        plugin: Plugin { name: "QGroundControl" }

                        MapScale {
                            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
                            anchors.bottomMargin:   anchors.leftMargin
                            anchors.left:           parent.left
                            anchors.bottom:         parent.bottom
                            mapControl:             parent
                        }
Don Gagne's avatar
Don Gagne committed
522

523 524 525 526
                        Rectangle {
                            anchors.fill:   parent
                            border.color:   _mapAdjustedColor
                            color:          "transparent"
Don Gagne's avatar
Don Gagne committed
527

528
                            QGCMapLabel {
529
                                anchors.centerIn:   parent
530
                                map:                minZoomPreview
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
                                text:               qsTr("Min Zoom: %1").arg(sliderMinZoom.value)
                            }
                            MouseArea {
                                anchors.fill:   parent
                                onClicked:      _showPreview = false
                            }
                        }
                    } // Map

                    Map {
                        id:                 maxZoomPreview
                        width:              minZoomPreview.width
                        height:             minZoomPreview.height
                        center:             _map.center
                        activeMapType:      _map.activeMapType
                        zoomLevel:          sliderMaxZoom.value
                        gesture.enabled:    false
                        visible:            _showPreview

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

552 553 554 555 556 557 558 559 560 561 562 563 564 565
                        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:   parent
                            border.color:   _mapAdjustedColor
                            color:          "transparent"
Don Gagne's avatar
Don Gagne committed
566

567
                            QGCMapLabel {
568
                                anchors.centerIn:   parent
569
                                map:                maxZoomPreview
570 571 572 573 574 575 576 577
                                text:               qsTr("Max Zoom: %1").arg(sliderMaxZoom.value)
                            }
                            MouseArea {
                                anchors.fill:   parent
                                onClicked:      _showPreview = false
                            }
                        }
                    } // Map
Don Gagne's avatar
Don Gagne committed
578 579 580 581 582
                }

                //-- Add new set dialog
                Rectangle {
                    anchors.margins:    ScreenTools.defaultFontPixelWidth
dogmaphobic's avatar
dogmaphobic committed
583
                    anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
584
                    anchors.right:      parent.right
dogmaphobic's avatar
dogmaphobic committed
585
                    width:              ScreenTools.defaultFontPixelWidth * 24
586
                    height:             Math.min(parent.height - (anchors.margins * 2), addNewSetFlickable.y + addNewSetColumn.height + addNewSetLabel.anchors.margins)
dogmaphobic's avatar
dogmaphobic committed
587
                    color:              Qt.rgba(qgcPal.window.r, qgcPal.window.g, qgcPal.window.b, 0.85)
Don Gagne's avatar
Don Gagne committed
588 589 590 591 592 593 594 595 596 597 598 599 600
                    radius:             ScreenTools.defaultFontPixelWidth * 0.5

                    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
601

Don Gagne's avatar
Don Gagne committed
602 603 604 605 606 607 608 609 610 611 612 613
                    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
614 615

                        Column {
Don Gagne's avatar
Don Gagne committed
616
                            id:                 addNewSetColumn
Don Gagne's avatar
Don Gagne committed
617 618
                            anchors.left:       parent.left
                            anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
619
                            spacing:            ScreenTools.defaultFontPixelHeight / (ScreenTools.isTinyScreen ? 4 : 2)
Don Gagne's avatar
Don Gagne committed
620

Don Gagne's avatar
Don Gagne committed
621 622 623 624 625 626 627 628
                            Column {
                                anchors.left:       parent.left
                                anchors.right:      parent.right
                                QGCLabel { text: qsTr("Name:") }
                                QGCTextField {
                                    id:             setName
                                    anchors.left:   parent.left
                                    anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
629
                                }
dogmaphobic's avatar
dogmaphobic committed
630
                            }
Don Gagne's avatar
Don Gagne committed
631 632 633 634 635

                            Column {
                                anchors.left:       parent.left
                                anchors.right:      parent.right
                                QGCLabel {
Don Gagne's avatar
Don Gagne committed
636 637
                                    text:       qsTr("Map type:")
                                    visible:    !_saveRealEstate
Don Gagne's avatar
Don Gagne committed
638
                                }
Don Gagne's avatar
Don Gagne committed
639 640 641 642 643 644 645 646 647 648
                                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
649
                                    }
Don Gagne's avatar
Don Gagne committed
650 651 652 653 654 655
                                    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
656 657
                                        }
                                    }
Don Gagne's avatar
Don Gagne committed
658 659
                                }
                            }
Don Gagne's avatar
Don Gagne committed
660

Don Gagne's avatar
Don Gagne committed
661 662 663 664 665 666 667 668 669 670
                            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
dogmaphobic's avatar
dogmaphobic committed
671
                                    anchors.margins:    ScreenTools.defaultFontPixelHeight * 0.25
Don Gagne's avatar
Don Gagne committed
672 673 674
                                    anchors.top:        parent.top
                                    anchors.left:       parent.left
                                    anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
675 676

                                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
677
                                        text:           qsTr("Min Zoom: %1").arg(sliderMinZoom.value)
Don Gagne's avatar
Don Gagne committed
678 679 680
                                        font.pointSize: _adjustableFontPointSize
                                    }

Don Gagne's avatar
Don Gagne committed
681 682 683 684 685 686 687 688 689 690
                                    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
dogmaphobic's avatar
dogmaphobic committed
691
                                        Component.onCompleted:      Math.max(sliderMinZoom.value = _map.zoomLevel - 4, 2)
Don Gagne's avatar
Don Gagne committed
692 693 694 695 696 697 698 699
                                        onValueChanged: {
                                            if(sliderMinZoom.value > sliderMaxZoom.value) {
                                                sliderMaxZoom.value = sliderMinZoom.value
                                            }
                                            handleChanges()
                                        }
                                    } // Slider - min zoom

Don Gagne's avatar
Don Gagne committed
700
                                    QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
701 702
                                        text:                       qsTr("Max Zoom: %1").arg(sliderMaxZoom.value)
                                        font.pointSize:             _adjustableFontPointSize
Don Gagne's avatar
Don Gagne committed
703
                                    }
Don Gagne's avatar
Don Gagne committed
704 705 706 707 708 709 710 711 712 713 714

                                    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
dogmaphobic's avatar
dogmaphobic committed
715
                                        Component.onCompleted:      Math.min(sliderMaxZoom.value = _map.zoomLevel + 2, 20)
Don Gagne's avatar
Don Gagne committed
716 717 718 719 720 721 722 723 724 725 726 727
                                        onValueChanged: {
                                            if(sliderMaxZoom.value < sliderMinZoom.value) {
                                                sliderMinZoom.value = sliderMaxZoom.value
                                            }
                                            handleChanges()
                                        }
                                    } // Slider - max zoom

                                    GridLayout {
                                        columns:    2
                                        rowSpacing: 0
                                        QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
728
                                            text:           qsTr("Count:")
Don Gagne's avatar
Don Gagne committed
729 730 731
                                            font.pointSize: _adjustableFontPointSize
                                        }
                                        QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
732
                                            text:            QGroundControl.mapEngineManager.tileCountStr
Don Gagne's avatar
Don Gagne committed
733 734 735 736
                                            font.pointSize: _adjustableFontPointSize
                                        }

                                        QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
737
                                            text:           qsTr("Est Size:")
Don Gagne's avatar
Don Gagne committed
738 739 740 741 742 743
                                            font.pointSize: _adjustableFontPointSize
                                        }
                                        QGCLabel {
                                            text:           QGroundControl.mapEngineManager.tileSizeStr
                                            font.pointSize: _adjustableFontPointSize
                                        }
Don Gagne's avatar
Don Gagne committed
744
                                    }
Don Gagne's avatar
Don Gagne committed
745 746
                                } // Column - Zoom info
                            } // Rectangle - Zoom info
Don Gagne's avatar
Don Gagne committed
747

dogmaphobic's avatar
dogmaphobic committed
748 749
                            Row {
                                spacing: ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
750
                                anchors.horizontalCenter: parent.horizontalCenter
dogmaphobic's avatar
dogmaphobic committed
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
                                QGCButton {
                                    text:       _tooManyTiles ? qsTr("Too many tiles") : qsTr("Download")
                                    enabled:    !_tooManyTiles && setName.text.length > 0
                                    property bool _tooManyTiles: QGroundControl.mapEngineManager.tileCount > _maxTilesForDownload
                                    onClicked: {
                                        if(QGroundControl.mapEngineManager.findName(setName.text)) {
                                            duplicateName.visible = true
                                        } else {
                                            QGroundControl.mapEngineManager.startDownload(setName.text, mapType);
                                            showList()
                                        }
                                    }
                                }
                                QGCButton {
                                    text: qsTr("Cancel")
                                    onClicked: {
Don Gagne's avatar
Don Gagne committed
767 768
                                        showList()
                                    }
Don Gagne's avatar
Don Gagne committed
769
                                }
dogmaphobic's avatar
dogmaphobic committed
770
                            }
dogmaphobic's avatar
dogmaphobic committed
771

Don Gagne's avatar
Don Gagne committed
772 773 774 775
                        } // Column
                    } // QGCFlickable
                } // Rectangle - Add new set dialog
            } // Item - Add new set view
Don Gagne's avatar
Don Gagne committed
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
        } // 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
802 803
                    }
                }
Don Gagne's avatar
Don Gagne committed
804 805 806 807 808
                Repeater {
                    model: QGroundControl.mapEngineManager.tileSets
                    delegate: OfflineMapButton {
                        text:           object.name
                        size:           object.downloadStatus
dogmaphobic's avatar
dogmaphobic committed
809
                        tiles:          object.totalTileCount
Don Gagne's avatar
Don Gagne committed
810 811 812 813 814 815
                        complete:       object.complete
                        width:          firstButton.width
                        height:         ScreenTools.defaultFontPixelHeight * 2
                        onClicked: {
                            offlineMapView._currentSelection = object
                            showInfo()
dogmaphobic's avatar
dogmaphobic committed
816
                        }
dogmaphobic's avatar
dogmaphobic committed
817 818 819 820
                    }
                }
            }
        }
Don Gagne's avatar
Don Gagne committed
821 822 823 824 825 826 827 828 829 830 831 832

        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