OfflineMap.qml 63.1 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * 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
import QtQuick                  2.11
import QtQuick.Controls         2.4
import QtQuick.Layouts          1.11
import QtQuick.Dialogs          1.3
14
import QtQuick.Controls.Styles  1.4
15 16
import QtLocation               5.3
import QtPositioning            5.3
dogmaphobic's avatar
dogmaphobic committed
17

Gus Grubba's avatar
Gus Grubba committed
18 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
import QGroundControl.QGCMapEngineManager   1.0
24 25
import QGroundControl.FactSystem            1.0
import QGroundControl.FactControls          1.0
dogmaphobic's avatar
dogmaphobic committed
26

27
Item {
Don Gagne's avatar
Don Gagne committed
28 29
    id:             offlineMapView
    anchors.fill:   parent
dogmaphobic's avatar
dogmaphobic committed
30

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

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

35 36 37 38 39 40 41
    property var    _settingsManager:   QGroundControl.settingsManager
    property var    _settings:          _settingsManager ? _settingsManager.offlineMapsSettings : null
    property var    _fmSettings:        _settingsManager ? _settingsManager.flightMapSettings : null
    property Fact   _mapboxFact:        _settingsManager ? _settingsManager.appSettings.mapboxToken : null
    property Fact   _mapboxAccountFact: _settingsManager ? _settingsManager.appSettings.mapboxAccount : null
    property Fact   _mapboxStyleFact:   _settingsManager ? _settingsManager.appSettings.mapboxStyle : null
    property Fact   _esriFact:          _settingsManager ? _settingsManager.appSettings.esriToken : null
42

43
    property string mapType:            _fmSettings ? (_fmSettings.mapProvider.value + " " + _fmSettings.mapType.value) : ""
44
    property bool   isMapInteractive:   false
45 46 47
    property var    savedCenter:        undefined
    property real   savedZoom:          3
    property string savedMapType:       ""
Don Gagne's avatar
Don Gagne committed
48
    property bool   _showPreview:       true
dogmaphobic's avatar
dogmaphobic committed
49
    property bool   _defaultSet:        offlineMapView && offlineMapView._currentSelection && offlineMapView._currentSelection.defaultSet
50 51
    property real   _margins:           ScreenTools.defaultFontPixelWidth * 0.5
    property real   _buttonSize:        ScreenTools.defaultFontPixelWidth * 12
Gus Grubba's avatar
Gus Grubba committed
52
    property real   _bigButtonSize:     ScreenTools.defaultFontPixelWidth * 16
dogmaphobic's avatar
dogmaphobic committed
53

dogmaphobic's avatar
dogmaphobic committed
54 55
    property bool   _saveRealEstate:          ScreenTools.isTinyScreen || ScreenTools.isShortScreen
    property real   _adjustableFontPointSize: _saveRealEstate ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
Don Gagne's avatar
Don Gagne committed
56

57 58
    property var    _mapAdjustedColor:  _map.isSatelliteMap ? "white" : "black"
    property bool   _tooManyTiles:      QGroundControl.mapEngineManager.tileCount > _maxTilesForDownload
Don Gagne's avatar
Don Gagne committed
59

60
    readonly property real minZoomLevel:    1
61
    readonly property real maxZoomLevel:    20
62
    readonly property real sliderTouchArea: ScreenTools.defaultFontPixelWidth * (ScreenTools.isTinyScreen ? 5 : (ScreenTools.isMobile ? 6 : 3))
Don Gagne's avatar
Don Gagne committed
63

64
    readonly property int _maxTilesForDownload: _settings ? _settings.maxTilesForDownload.rawValue : 0
65

Don Gagne's avatar
Don Gagne committed
66
    QGCPalette { id: qgcPal }
67

dogmaphobic's avatar
dogmaphobic committed
68 69 70
    Component.onCompleted: {
        QGroundControl.mapEngineManager.loadTileSets()
        updateMap()
DonLakeFlyer's avatar
DonLakeFlyer committed
71
        savedCenter = _map.toCoordinate(Qt.point(_map.width / 2, _map.height / 2), false /* clipToViewPort */)
dogmaphobic's avatar
dogmaphobic committed
72 73 74 75 76 77 78 79 80 81 82 83 84
    }

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

    function handleChanges() {
85
        if(isMapInteractive) {
Don Gagne's avatar
Don Gagne committed
86 87
            var xl = 0
            var yl = 0
88 89
            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
DonLakeFlyer's avatar
DonLakeFlyer committed
90 91
            var c0 = _map.toCoordinate(Qt.point(xl, yl), false /* clipToViewPort */)
            var c1 = _map.toCoordinate(Qt.point(xr, yr), false /* clipToViewPort */)
92
            QGroundControl.mapEngineManager.updateForCurrentView(c0.longitude, c0.latitude, c1.longitude, c1.latitude, sliderMinZoom.value, sliderMaxZoom.value, mapType)
dogmaphobic's avatar
dogmaphobic committed
93 94 95 96 97 98 99 100 101 102 103 104 105
        }
    }

    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
106
    function addNewSet() {
107
        isMapInteractive = true
108
        mapType = _fmSettings.mapProvider.value + " " + _fmSettings.mapType.value
109 110
        resetMapToDefaults()
        handleChanges()
111
        _map.visible = true
dogmaphobic's avatar
dogmaphobic committed
112
        _tileSetList.visible = false
Don Gagne's avatar
Don Gagne committed
113
        infoView.visible = false
114
        _exporTiles.visible = false
Don Gagne's avatar
Don Gagne committed
115
        addNewSetView.visible = true
dogmaphobic's avatar
dogmaphobic committed
116 117 118
    }

    function showList() {
119
        _exporTiles.visible = false
120
        isMapInteractive = false
121
        _map.visible = false
dogmaphobic's avatar
dogmaphobic committed
122
        _tileSetList.visible = true
Don Gagne's avatar
Don Gagne committed
123 124
        infoView.visible = false
        addNewSetView.visible = false
Gus Grubba's avatar
Gus Grubba committed
125
        QGroundControl.mapEngineManager.resetAction();
dogmaphobic's avatar
dogmaphobic committed
126 127
    }

128 129 130 131 132 133 134 135 136
    function showExport() {
        isMapInteractive = false
        _map.visible = false
        _tileSetList.visible = false
        infoView.visible = false
        addNewSetView.visible = false
        _exporTiles.visible = true
    }

dogmaphobic's avatar
dogmaphobic committed
137
    function showInfo() {
138
        isMapInteractive = false
Don Gagne's avatar
Don Gagne committed
139
        if(_currentSelection && !offlineMapView._currentSelection.deleting) {
140
            enterInfoView()
dogmaphobic's avatar
dogmaphobic committed
141 142 143 144
        } else
            showList()
    }

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
    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
166 167
        _map.visible = true
        isMapInteractive = false
DonLakeFlyer's avatar
DonLakeFlyer committed
168
        savedCenter = _map.toCoordinate(Qt.point(_map.width / 2, _map.height / 2), false /* clipToViewPort */)
Don Gagne's avatar
Don Gagne committed
169 170
        savedZoom = _map.zoomLevel
        savedMapType = mapType
dogmaphobic's avatar
dogmaphobic committed
171
        if(!offlineMapView._currentSelection.defaultSet) {
Don Gagne's avatar
Don Gagne committed
172 173
            mapType = offlineMapView._currentSelection.mapTypeStr
            _map.center = midPoint(offlineMapView._currentSelection.topleftLat, offlineMapView._currentSelection.bottomRightLat, offlineMapView._currentSelection.topleftLon, offlineMapView._currentSelection.bottomRightLon)
174
            //-- Delineate Set Region
Don Gagne's avatar
Don Gagne committed
175 176 177 178
            var x0 = offlineMapView._currentSelection.topleftLon
            var x1 = offlineMapView._currentSelection.bottomRightLon
            var y0 = offlineMapView._currentSelection.topleftLat
            var y1 = offlineMapView._currentSelection.bottomRightLat
179 180 181
            mapBoundary.topLeft     = QtPositioning.coordinate(y0, x0)
            mapBoundary.bottomRight = QtPositioning.coordinate(y1, x1)
            mapBoundary.visible = true
dogmaphobic's avatar
dogmaphobic committed
182 183 184
            // 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)
185
            _map.fitViewportToMapItems()
186 187
        }
        _tileSetList.visible = false
188
        addNewSetView.visible = false
dogmaphobic's avatar
dogmaphobic committed
189
        infoView.visible = true
190 191 192
    }

    function leaveInfoView() {
193
        mapBoundary.visible = false
194 195 196
        _map.center = savedCenter
        _map.zoomLevel = savedZoom
        mapType = savedMapType
197 198 199 200 201
    }

    function resetMapToDefaults() {
        _map.center = QGroundControl.flightMapPosition
        _map.zoomLevel = QGroundControl.flightMapZoom
202 203
    }

dogmaphobic's avatar
dogmaphobic committed
204 205
    onMapTypeChanged: {
        updateMap()
206 207 208
        if(isMapInteractive) {
            QGroundControl.mapEngineManager.saveSetting(mapKey, mapType)
        }
dogmaphobic's avatar
dogmaphobic committed
209 210
    }

211 212 213 214 215 216 217
    QGCFileDialog {
        id:             fileDialog
        folder:         QGroundControl.settingsManager.appSettings.missionSavePath
        nameFilters:    ["Tile Sets (*.qgctiledb)"]

        onAcceptedForSave: {
            if (QGroundControl.mapEngineManager.exportSets(file)) {
218
                exportToDiskProgress.open()
219 220 221 222 223 224 225 226 227 228 229 230 231 232
            } else {
                showList()
            }
            close()
        }

        onAcceptedForLoad: {
            if(!QGroundControl.mapEngineManager.importSets(file)) {
                showList();
            }
            close()
        }
    }

dogmaphobic's avatar
dogmaphobic committed
233 234 235 236 237 238
    MessageDialog {
        id:         errorDialog
        visible:    false
        text:       QGroundControl.mapEngineManager.errorMessage
        icon:       StandardIcon.Critical
        standardButtons: StandardButton.Ok
Don Gagne's avatar
Don Gagne committed
239
        title:      qsTr("Error Message")
dogmaphobic's avatar
dogmaphobic committed
240 241 242 243
        onYes: {
            errorDialog.visible = false
        }
    }
Don Gagne's avatar
Don Gagne committed
244

Don Gagne's avatar
Don Gagne committed
245 246 247 248 249 250 251 252 253 254
    Component {
        id: optionsDialogComponent

        QGCViewDialog {
            id: optionDialog

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

Don Gagne's avatar
Don Gagne committed
257 258 259
            QGCFlickable {
                anchors.fill:   parent
                contentHeight:  optionsColumn.height
260

Don Gagne's avatar
Don Gagne committed
261 262 263 264 265 266 267
                Column {
                    id:                 optionsColumn
                    anchors.margins:    ScreenTools.defaultFontPixelWidth
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    anchors.top:        parent.top
                    spacing:            ScreenTools.defaultFontPixelHeight / 2
268

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

Don Gagne's avatar
Don Gagne committed
271 272 273 274 275 276 277
                    QGCTextField {
                        id:                 maxCacheSize
                        maximumLength:      6
                        inputMethodHints:   Qt.ImhDigitsOnly
                        validator:          IntValidator {bottom: 1; top: 262144;}
                        text:               QGroundControl.mapEngineManager.maxDiskCache
                    }
278

Don Gagne's avatar
Don Gagne committed
279 280
                    Item { width: 1; height: 1 }

Don Gagne's avatar
Don Gagne committed
281 282 283 284 285 286
                    QGCLabel {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
                        text:           qsTr("Max Cache Memory Size (MB):")
                    }
Don Gagne's avatar
Don Gagne committed
287 288 289 290 291

                    QGCTextField {
                        id:                 maxCacheMemSize
                        maximumLength:      4
                        inputMethodHints:   Qt.ImhDigitsOnly
292
                        validator:          IntValidator {bottom: 1; top: 1024;}
Don Gagne's avatar
Don Gagne committed
293
                        text:               QGroundControl.mapEngineManager.maxMemCache
dogmaphobic's avatar
dogmaphobic committed
294
                    }
Don Gagne's avatar
Don Gagne committed
295 296

                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
297 298 299
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
Don Gagne's avatar
Don Gagne committed
300 301 302 303
                        font.pointSize: _adjustableFontPointSize
                        text:           qsTr("Memory cache changes require a restart to take effect.")
                    }

304
                    Item { width: 1; height: 1; visible: _mapboxFact ? _mapboxFact.visible : false }
Gus Grubba's avatar
Gus Grubba committed
305
                    QGCLabel { text: qsTr("Mapbox Access Token"); visible: _mapboxFact ? _mapboxFact.visible : false }
306 307
                    FactTextField {
                        fact:               _mapboxFact
308
                        visible:            _mapboxFact ? _mapboxFact.visible : false
309 310
                        maximumLength:      256
                        width:              ScreenTools.defaultFontPixelWidth * 30
Don Gagne's avatar
Don Gagne committed
311 312
                    }
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
313 314 315
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
Gus Grubba's avatar
Gus Grubba committed
316
                        text:           qsTr("To enable Mapbox maps, enter your access token.")
317
                        visible:        _mapboxFact ? _mapboxFact.visible : false
Don Gagne's avatar
Don Gagne committed
318 319
                        font.pointSize: _adjustableFontPointSize
                    }
Gus Grubba's avatar
Gus Grubba committed
320

321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
                    Item { width: 1; height: 1; visible: _mapboxAccountFact ? _mapboxAccountFact.visible : false }
                    QGCLabel { text: qsTr("Mapbox User Name"); visible: _mapboxAccountFact ? _mapboxAccountFact.visible : false }
                    FactTextField {
                        fact:               _mapboxAccountFact
                        visible:            _mapboxAccountFact ? _mapboxAccountFact.visible : false
                        maximumLength:      256
                        width:              ScreenTools.defaultFontPixelWidth * 30
                    }
                    QGCLabel {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
                        text:           qsTr("To enable custom Mapbox styles, enter your account name.")
                        visible:        _mapboxAccountFact ? _mapboxAccountFact.visible : false
                        font.pointSize: _adjustableFontPointSize
                    }

                    Item { width: 1; height: 1; visible: _mapboxStyleFact ? _mapboxStyleFact.visible : false }
                    QGCLabel { text: qsTr("Mapbox Style ID"); visible: _mapboxStyleFact ? _mapboxStyleFact.visible : false }
                    FactTextField {
                        fact:               _mapboxStyleFact
                        visible:            _mapboxStyleFact ? _mapboxStyleFact.visible : false
                        maximumLength:      256
                        width:              ScreenTools.defaultFontPixelWidth * 30
                    }
                    QGCLabel {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
                        text:           qsTr("To enable custom Mapbox styles, enter your style ID.")
                        visible:        _mapboxStyleFact ? _mapboxStyleFact.visible : false
                        font.pointSize: _adjustableFontPointSize
                    }

355 356
                    Item { width: 1; height: 1; visible: _esriFact ? _esriFact.visible : false }
                    QGCLabel { text: qsTr("Esri Access Token"); visible: _esriFact ? _esriFact.visible : false }
357 358
                    FactTextField {
                        fact:               _esriFact
359
                        visible:            _esriFact ? _esriFact.visible : false
360 361
                        maximumLength:      256
                        width:              ScreenTools.defaultFontPixelWidth * 30
Gus Grubba's avatar
Gus Grubba committed
362 363
                    }
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
364 365 366
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
Gus Grubba's avatar
Gus Grubba committed
367
                        text:           qsTr("To enable Esri maps, enter your access token.")
368
                        visible:        _esriFact ? _esriFact.visible : false
Gus Grubba's avatar
Gus Grubba committed
369 370
                        font.pointSize: _adjustableFontPointSize
                    }
Don Gagne's avatar
Don Gagne committed
371 372 373 374 375 376 377 378
                } // GridLayout
            } // QGCFlickable
        } // QGCViewDialog - optionsDialog
    } // Component - optionsDialogComponent

    Component {
        id: deleteConfirmationDialogComponent
        QGCViewMessage {
dogmaphobic's avatar
dogmaphobic committed
379 380 381 382 383 384
            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
385
            }
Don Gagne's avatar
Don Gagne committed
386 387
            function accept() {
                QGroundControl.mapEngineManager.deleteTileSet(offlineMapView._currentSelection)
dogmaphobic's avatar
dogmaphobic committed
388
                deleteConfirmationDialog.hideDialog()
Don Gagne's avatar
Don Gagne committed
389 390
                leaveInfoView()
                showList()
dogmaphobic's avatar
dogmaphobic committed
391 392
            }
        }
Don Gagne's avatar
Don Gagne committed
393 394
    }

395
    Item {
Don Gagne's avatar
Don Gagne committed
396 397
        anchors.fill:       parent

398 399 400 401 402 403
        FlightMap {
            id:                         _map
            anchors.fill:               parent
            visible:                    false
            allowGCSLocationCenter:     true
            allowVehicleLocationCenter: false
Don Gagne's avatar
Don Gagne committed
404
            gesture.flickDeceleration:  3000
405
            mapName:                    "OfflineMap"
Don Gagne's avatar
Don Gagne committed
406

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

Don Gagne's avatar
Don Gagne committed
409 410 411 412 413 414 415 416 417
            MapRectangle {
                id:             mapBoundary
                border.width:   2
                border.color:   "red"
                color:          Qt.rgba(1,0,0,0.05)
                smooth:         true
                antialiasing:   true
            }

418
            Component.onCompleted: resetMapToDefaults()
Don Gagne's avatar
Don Gagne committed
419

420 421 422 423 424 425 426 427
            onCenterChanged:    handleChanges()
            onZoomLevelChanged: handleChanges()
            onWidthChanged:     handleChanges()
            onHeightChanged:    handleChanges()

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

Don Gagne's avatar
Don Gagne committed
430 431 432 433 434 435
            MapScale {
                anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
                anchors.bottomMargin:   anchors.leftMargin
                anchors.left:           parent.left
                anchors.bottom:         parent.bottom
                mapControl:             _map
436
                buttonsOnLeft:          true
437
            }
Don Gagne's avatar
Don Gagne committed
438

dogmaphobic's avatar
dogmaphobic committed
439
            //-----------------------------------------------------------------
Don Gagne's avatar
Don Gagne committed
440 441 442
            //-- Show Set Info
            Rectangle {
                id:                 infoView
dogmaphobic's avatar
dogmaphobic committed
443
                anchors.margins:    ScreenTools.defaultFontPixelHeight
Don Gagne's avatar
Don Gagne committed
444
                anchors.right:      parent.right
dogmaphobic's avatar
dogmaphobic committed
445 446 447 448
                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
449 450
                radius:             ScreenTools.defaultFontPixelWidth * 0.5
                visible:            false
451 452 453 454 455 456 457 458

                property bool       _extraButton: {
                    if(!offlineMapView._currentSelection)
                        return false;
                    var curSel = offlineMapView._currentSelection;
                    return !_defaultSet && ((!curSel.complete && !curSel.downloading) || (!curSel.complete && curSel.downloading));
                }

dogmaphobic's avatar
dogmaphobic committed
459 460
                property real       _labelWidth:    ScreenTools.defaultFontPixelWidth * 10
                property real       _valueWidth:    ScreenTools.defaultFontPixelWidth * 14
461
                Column {
dogmaphobic's avatar
dogmaphobic committed
462 463 464 465
                    id:                 tileInfoColumn
                    anchors.margins:    ScreenTools.defaultFontPixelHeight * 0.5
                    spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                    anchors.centerIn:   parent
466
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
467 468 469 470 471 472
                        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
Gus Grubba's avatar
Gus Grubba committed
473 474 475 476 477 478 479 480
                        visible:        _defaultSet
                    }
                    QGCTextField {
                        id:             editSetName
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        visible:        !_defaultSet
                        text:           offlineMapView._currentSelection ? offlineMapView._currentSelection.name : ""
481 482
                    }
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
483 484 485
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
dogmaphobic's avatar
dogmaphobic committed
486 487 488 489 490 491 492 493 494
                        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
495
                        horizontalAlignment: Text.AlignHCenter
496
                    }
dogmaphobic's avatar
dogmaphobic committed
497 498 499 500
                    //-- Tile Sets
                    Row {
                        spacing:    ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
501
                        visible:    !_defaultSet && mapType !== "Airmap Elevation"
dogmaphobic's avatar
dogmaphobic committed
502 503
                        QGCLabel {  text: qsTr("Zoom Levels:"); width: infoView._labelWidth; }
                        QGCLabel {  text: offlineMapView._currentSelection ? (offlineMapView._currentSelection.minZoom + " - " + offlineMapView._currentSelection.maxZoom) : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
504
                    }
dogmaphobic's avatar
dogmaphobic committed
505 506 507 508 509 510 511 512 513 514 515 516 517
                    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; }
518
                    }
Don Gagne's avatar
Don Gagne committed
519

dogmaphobic's avatar
dogmaphobic committed
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
                    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
552 553
                        QGCButton {
                            text:       qsTr("Resume Download")
dogmaphobic's avatar
dogmaphobic committed
554 555
                            visible:    offlineMapView._currentSelection && offlineMapView._currentSelection && !_defaultSet && (!offlineMapView._currentSelection.complete && !offlineMapView._currentSelection.downloading)
                            width:      ScreenTools.defaultFontPixelWidth * 16
Don Gagne's avatar
Don Gagne committed
556 557 558 559
                            onClicked: {
                                if(offlineMapView._currentSelection)
                                    offlineMapView._currentSelection.resumeDownloadTask()
                            }
560
                        }
Don Gagne's avatar
Don Gagne committed
561 562
                        QGCButton {
                            text:       qsTr("Cancel Download")
dogmaphobic's avatar
dogmaphobic committed
563 564
                            visible:    offlineMapView._currentSelection && offlineMapView._currentSelection && !_defaultSet && (!offlineMapView._currentSelection.complete && offlineMapView._currentSelection.downloading)
                            width:      ScreenTools.defaultFontPixelWidth * 16
Don Gagne's avatar
Don Gagne committed
565 566 567 568
                            onClicked: {
                                if(offlineMapView._currentSelection)
                                    offlineMapView._currentSelection.cancelDownloadTask()
                            }
569
                        }
Don Gagne's avatar
Don Gagne committed
570 571
                        QGCButton {
                            text:       qsTr("Delete")
dogmaphobic's avatar
dogmaphobic committed
572
                            width:      ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
573
                            onClicked:  mainWindow.showComponentDialog(deleteConfirmationDialogComponent, qsTr("Confirm Delete"), mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
574
                        }
Don Gagne's avatar
Don Gagne committed
575
                        QGCButton {
Gus Grubba's avatar
Gus Grubba committed
576 577 578 579 580 581 582 583 584 585 586 587 588 589
                            text:       qsTr("Ok")
                            width:      ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
                            visible:    !_defaultSet
                            enabled:    editSetName.text !== ""
                            onClicked: {
                                if(editSetName.text !== _currentSelection.name) {
                                    QGroundControl.mapEngineManager.renameTileSet(_currentSelection, editSetName.text)
                                }
                                leaveInfoView()
                                showList()
                            }
                        }
                        QGCButton {
                            text:       _defaultSet ? qsTr("Close") : qsTr("Cancel")
dogmaphobic's avatar
dogmaphobic committed
590 591 592 593 594
                            width:      ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
                            onClicked: {
                                leaveInfoView()
                                showList()
                            }
595
                        }
dogmaphobic's avatar
dogmaphobic committed
596 597 598
                    }
                }
            } // Rectangle - infoView
Don Gagne's avatar
Don Gagne committed
599

dogmaphobic's avatar
dogmaphobic committed
600 601
            //-----------------------------------------------------------------
            //-- Add new set
Don Gagne's avatar
Don Gagne committed
602 603 604 605
            Item {
                id:             addNewSetView
                anchors.fill:   parent
                visible:        false
Don Gagne's avatar
Don Gagne committed
606

607 608 609 610 611 612 613 614 615 616
                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
617
                    }
618

619 620 621 622 623 624 625 626 627 628
                    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

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

631 632 633 634 635 636 637 638
                        plugin: Plugin { name: "QGroundControl" }

                        MapScale {
                            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
                            anchors.bottomMargin:   anchors.leftMargin
                            anchors.left:           parent.left
                            anchors.bottom:         parent.bottom
                            mapControl:             parent
639
                            zoomButtonsVisible:     false
640
                        }
Don Gagne's avatar
Don Gagne committed
641

642 643 644 645
                        Rectangle {
                            anchors.fill:   parent
                            border.color:   _mapAdjustedColor
                            color:          "transparent"
Don Gagne's avatar
Don Gagne committed
646

647
                            QGCMapLabel {
648
                                anchors.centerIn:   parent
649
                                map:                minZoomPreview
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
                                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

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

671 672 673 674 675 676 677 678
                        plugin: Plugin { name: "QGroundControl" }

                        MapScale {
                            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
                            anchors.bottomMargin:   anchors.leftMargin
                            anchors.left:           parent.left
                            anchors.bottom:         parent.bottom
                            mapControl:             parent
679
                            zoomButtonsVisible:     false
680 681 682 683 684 685
                        }

                        Rectangle {
                            anchors.fill:   parent
                            border.color:   _mapAdjustedColor
                            color:          "transparent"
Don Gagne's avatar
Don Gagne committed
686

687
                            QGCMapLabel {
688
                                anchors.centerIn:   parent
689
                                map:                maxZoomPreview
690 691 692 693 694 695 696 697
                                text:               qsTr("Max Zoom: %1").arg(sliderMaxZoom.value)
                            }
                            MouseArea {
                                anchors.fill:   parent
                                onClicked:      _showPreview = false
                            }
                        }
                    } // Map
Don Gagne's avatar
Don Gagne committed
698
                }
699
            } // Item - Add new set view
700 701 702 703 704 705 706 707 708 709 710

            CenterMapDropButton {
                topMargin:          0
                anchors.margins:    _margins
                anchors.left:       map.left
                anchors.top:        map.top
                map:                _map
                showMission:        false
                showAllItems:       false
                visible:            addNewSetView.visible
            }
711
        } // Map
Don Gagne's avatar
Don Gagne committed
712

713 714 715 716 717
        //-- Add new set dialog
        Rectangle {
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.verticalCenter: parent.verticalCenter
            anchors.right:      parent.right
718
            visible:            addNewSetView.visible
719 720 721 722 723
            width:              ScreenTools.defaultFontPixelWidth * (ScreenTools.isTinyScreen ? 24 : 28)
            height:             Math.min(parent.height - (anchors.margins * 2), addNewSetFlickable.y + addNewSetColumn.height + addNewSetLabel.anchors.margins)
            color:              Qt.rgba(qgcPal.window.r, qgcPal.window.g, qgcPal.window.b, 0.85)
            radius:             ScreenTools.defaultFontPixelWidth * 0.5

724 725 726
            //-- Eat mouse events
            DeadMouseArea {
                anchors.fill: parent
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
            }

            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
            }

            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

                Column {
                    id:                 addNewSetColumn
                    anchors.left:       parent.left
Don Gagne's avatar
Don Gagne committed
757
                    anchors.right:      parent.right
758
                    spacing:            ScreenTools.defaultFontPixelHeight * (ScreenTools.isTinyScreen ? 0.25 : 0.5)
Don Gagne's avatar
Don Gagne committed
759

760 761
                    Column {
                        spacing:            ScreenTools.isTinyScreen ? 0 : ScreenTools.defaultFontPixelHeight * 0.25
Don Gagne's avatar
Don Gagne committed
762 763
                        anchors.left:       parent.left
                        anchors.right:      parent.right
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
                        QGCLabel { text: qsTr("Name:") }
                        QGCTextField {
                            id:             setName
                            anchors.left:   parent.left
                            anchors.right:  parent.right
                        }
                    }

                    Column {
                        spacing:            ScreenTools.isTinyScreen ? 0 : ScreenTools.defaultFontPixelHeight * 0.25
                        anchors.left:       parent.left
                        anchors.right:      parent.right
                        QGCLabel {
                            text:       qsTr("Map type:")
                            visible:    !_saveRealEstate
                        }
                        QGCComboBox {
                            id:             mapCombo
                            anchors.left:   parent.left
                            anchors.right:  parent.right
                            model:          QGroundControl.mapEngineManager.mapList
                            onActivated: {
                                mapType = textAt(index)
                            }
                            Component.onCompleted: {
                                var index = mapCombo.find(mapType)
                                if (index === -1) {
                                    console.warn("Active map name not in combo", mapType)
                                } else {
                                    mapCombo.currentIndex = index
                                }
                            }
                        }
797 798 799 800 801
                        QGCCheckBox {
                            anchors.left:   parent.left
                            anchors.right:  parent.right
                            text:           qsTr("Fetch elevation data")
                            checked:        QGroundControl.mapEngineManager.fetchElevation
802 803 804 805
                            onClicked: {
                                QGroundControl.mapEngineManager.fetchElevation = checked
                                handleChanges()
                            }
806
                        }
Don Gagne's avatar
Don Gagne committed
807
                    }
Don Gagne's avatar
Don Gagne committed
808

809 810 811 812 813 814 815
                    Rectangle {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        height:         zoomColumn.height + ScreenTools.defaultFontPixelHeight * 0.5
                        color:          qgcPal.window
                        border.color:   qgcPal.text
                        radius:         ScreenTools.defaultFontPixelWidth * 0.5
Don Gagne's avatar
Don Gagne committed
816 817

                        Column {
818 819 820 821
                            id:                 zoomColumn
                            spacing:            ScreenTools.isTinyScreen ? 0 : ScreenTools.defaultFontPixelHeight * 0.5
                            anchors.margins:    ScreenTools.defaultFontPixelHeight * 0.25
                            anchors.top:        parent.top
Don Gagne's avatar
Don Gagne committed
822 823
                            anchors.left:       parent.left
                            anchors.right:      parent.right
824 825 826 827 828

                            QGCLabel {
                                text:           qsTr("Min/Max Zoom Levels")
                                font.pointSize: _adjustableFontPointSize
                                anchors.horizontalCenter: parent.horizontalCenter
dogmaphobic's avatar
dogmaphobic committed
829
                            }
830

831 832 833 834 835
                            Slider {
                                id:                         sliderMinZoom
                                anchors.left:               parent.left
                                anchors.right:              parent.right
                                height:                     sliderTouchArea * 1.25
836 837
                                from:                       minZoomLevel
                                to:                         maxZoomLevel
838
                                stepSize:                   1
839 840 841 842 843 844
                                live:                       true
                                property bool _updateSetting: false
                                Component.onCompleted: {
                                    sliderMinZoom.value = _settings.minZoomLevelDownload.rawValue
                                    _updateSetting = true
                                }
845 846 847 848
                                onValueChanged: {
                                    if(sliderMinZoom.value > sliderMaxZoom.value) {
                                        sliderMaxZoom.value = sliderMinZoom.value
                                    }
849 850 851 852
                                    if (_updateSetting) {
                                        // Don't update setting until after Component.onCompleted since bad values come through before that
                                        _settings.minZoomLevelDownload.rawValue = value
                                    }
853
                                    handleChanges()
Don Gagne's avatar
Don Gagne committed
854
                                }
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
                                handle: Rectangle {
                                    x: sliderMinZoom.leftPadding + sliderMinZoom.visualPosition  * (sliderMinZoom.availableWidth - width)
                                    y: sliderMinZoom.topPadding  + sliderMinZoom.availableHeight * 0.5 - height * 0.5
                                    implicitWidth:  sliderTouchArea
                                    implicitHeight: sliderTouchArea
                                    radius:         sliderTouchArea * 0.5
                                    color:          qgcPal.button
                                    border.width:   1
                                    border.color:   qgcPal.buttonText
                                    Label {
                                        text:               sliderMinZoom.value
                                        anchors.centerIn:   parent
                                        font.family:        ScreenTools.normalFontFamily
                                        font.pointSize:     ScreenTools.smallFontPointSize
                                        color:              qgcPal.buttonText
Don Gagne's avatar
Don Gagne committed
870
                                    }
Don Gagne's avatar
Don Gagne committed
871
                                }
872 873 874 875 876 877 878
                            } // Slider - min zoom

                            Slider {
                                id:                         sliderMaxZoom
                                anchors.left:               parent.left
                                anchors.right:              parent.right
                                height:                     sliderTouchArea * 1.25
879 880
                                from:                       minZoomLevel
                                to:                         maxZoomLevel
881
                                stepSize:                   1
882 883 884 885 886 887
                                live:                       true
                                property bool _updateSetting: false
                                Component.onCompleted: {
                                    sliderMaxZoom.value = _settings.maxZoomLevelDownload.rawValue
                                    _updateSetting = true
                                }
888 889 890
                                onValueChanged: {
                                    if(sliderMaxZoom.value < sliderMinZoom.value) {
                                        sliderMinZoom.value = sliderMaxZoom.value
Don Gagne's avatar
Don Gagne committed
891
                                    }
892 893 894 895
                                    if (_updateSetting) {
                                        // Don't update setting until after Component.onCompleted since bad values come through before that
                                        _settings.maxZoomLevelDownload.rawValue = value
                                    }
896 897
                                    handleChanges()
                                }
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
                                handle: Rectangle {
                                    x: sliderMaxZoom.leftPadding + sliderMaxZoom.visualPosition  * (sliderMaxZoom.availableWidth - width)
                                    y: sliderMaxZoom.topPadding  + sliderMaxZoom.availableHeight * 0.5 - height * 0.5
                                    implicitWidth:  sliderTouchArea
                                    implicitHeight: sliderTouchArea
                                    radius:         sliderTouchArea * 0.5
                                    color:          qgcPal.button
                                    border.width:   1
                                    border.color:   qgcPal.buttonText
                                    Label {
                                        text:               sliderMaxZoom.value
                                        anchors.centerIn:   parent
                                        font.family:        ScreenTools.normalFontFamily
                                        font.pointSize:     ScreenTools.smallFontPointSize
                                        color:              qgcPal.buttonText
Don Gagne's avatar
Don Gagne committed
913
                                    }
914 915
                                }
                            } // Slider - max zoom
Don Gagne's avatar
Don Gagne committed
916

917 918 919 920 921 922 923 924 925 926 927
                            GridLayout {
                                columns:    2
                                rowSpacing: ScreenTools.isTinyScreen ? 0 : ScreenTools.defaultFontPixelHeight * 0.5
                                QGCLabel {
                                    text:           qsTr("Tile Count:")
                                    font.pointSize: _adjustableFontPointSize
                                }
                                QGCLabel {
                                    text:            QGroundControl.mapEngineManager.tileCountStr
                                    font.pointSize: _adjustableFontPointSize
                                }
928

929 930 931
                                QGCLabel {
                                    text:           qsTr("Est Size:")
                                    font.pointSize: _adjustableFontPointSize
dogmaphobic's avatar
dogmaphobic committed
932
                                }
933 934 935
                                QGCLabel {
                                    text:           QGroundControl.mapEngineManager.tileSizeStr
                                    font.pointSize: _adjustableFontPointSize
Don Gagne's avatar
Don Gagne committed
936
                                }
dogmaphobic's avatar
dogmaphobic committed
937
                            }
938 939
                        } // Column - Zoom info
                    } // Rectangle - Zoom info
dogmaphobic's avatar
dogmaphobic committed
940

941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976
                    QGCLabel {
                        text:       qsTr("Too many tiles")
                        visible:    _tooManyTiles
                        color:      qgcPal.warningText
                        anchors.horizontalCenter: parent.horizontalCenter
                    }

                    Row {
                        id: addButtonRow
                        spacing: ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
                        QGCButton {
                            text:       qsTr("Download")
                            width:      (addNewSetColumn.width * 0.5) - (addButtonRow.spacing * 0.5)
                            enabled:    !_tooManyTiles && setName.text.length > 0
                            onClicked: {
                                if(QGroundControl.mapEngineManager.findName(setName.text)) {
                                    duplicateName.visible = true
                                } else {
                                    QGroundControl.mapEngineManager.startDownload(setName.text, mapType);
                                    showList()
                                }
                            }
                        }
                        QGCButton {
                            text:       qsTr("Cancel")
                            width:      (addNewSetColumn.width * 0.5) - (addButtonRow.spacing * 0.5)
                            onClicked: {
                                showList()
                            }
                        }
                    }

                } // Column
            } // QGCFlickable
        } // Rectangle - Add new set dialog
Don Gagne's avatar
Don Gagne committed
977 978 979 980 981 982

        QGCFlickable {
            id:                 _tileSetList
            clip:               true
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.top:        parent.top
983
            anchors.bottom:     _listButtonRow.top
Don Gagne's avatar
Don Gagne committed
984 985 986
            anchors.left:       parent.left
            anchors.right:      parent.right
            contentHeight:      _cacheList.height
987 988 989 990
            ButtonGroup {
                id:             buttonGroup
                buttons:        _cacheList.children
            }
Don Gagne's avatar
Don Gagne committed
991
            Column {
992 993 994
                id:             _cacheList
                width:          Math.min(_tileSetList.width, (ScreenTools.defaultFontPixelWidth  * 50).toFixed(0))
                spacing:        ScreenTools.defaultFontPixelHeight * 0.5
Don Gagne's avatar
Don Gagne committed
995 996 997
                anchors.horizontalCenter: parent.horizontalCenter
                OfflineMapButton {
                    id:             firstButton
998
                    text:           qsTr("Add New Set")
Don Gagne's avatar
Don Gagne committed
999
                    width:          _cacheList.width
1000 1001
                    height:         ScreenTools.defaultFontPixelHeight * (ScreenTools.isMobile ? 3 : 2)
                    currentSet:     _currentSelection
Don Gagne's avatar
Don Gagne committed
1002 1003
                    onClicked: {
                        offlineMapView._currentSelection = null
1004
                        checked = true
Don Gagne's avatar
Don Gagne committed
1005
                        addNewSet()
dogmaphobic's avatar
dogmaphobic committed
1006 1007
                    }
                }
Don Gagne's avatar
Don Gagne committed
1008 1009 1010 1011 1012
                Repeater {
                    model: QGroundControl.mapEngineManager.tileSets
                    delegate: OfflineMapButton {
                        text:           object.name
                        size:           object.downloadStatus
dogmaphobic's avatar
dogmaphobic committed
1013
                        tiles:          object.totalTileCount
Don Gagne's avatar
Don Gagne committed
1014 1015
                        complete:       object.complete
                        width:          firstButton.width
1016 1017 1018
                        height:         ScreenTools.defaultFontPixelHeight * (ScreenTools.isMobile ? 3 : 2)
                        currentSet:     _currentSelection
                        tileSet:        object
Don Gagne's avatar
Don Gagne committed
1019 1020
                        onClicked: {
                            offlineMapView._currentSelection = object
1021
                            checked = true
Don Gagne's avatar
Don Gagne committed
1022
                            showInfo()
dogmaphobic's avatar
dogmaphobic committed
1023
                        }
dogmaphobic's avatar
dogmaphobic committed
1024 1025 1026 1027
                    }
                }
            }
        }
1028 1029 1030 1031 1032 1033
        Row {
            id:                 _listButtonRow
            visible:            _tileSetList.visible
            spacing:            _margins
            anchors.bottom:     parent.bottom
            anchors.margins:    ScreenTools.defaultFontPixelWidth
Gus Grubba's avatar
Gus Grubba committed
1034
            anchors.horizontalCenter: parent.horizontalCenter
1035 1036 1037
            QGCButton {
                text:           qsTr("Import")
                width:          _buttonSize
1038
                visible:        QGroundControl.corePlugin.options.showOfflineMapImport
1039 1040
                onClicked: {
                    QGroundControl.mapEngineManager.importAction = QGCMapEngineManager.ActionNone
1041
                    importDialog.open()
1042
                }
1043 1044 1045 1046
            }
            QGCButton {
                text:           qsTr("Export")
                width:          _buttonSize
1047
                visible:        QGroundControl.corePlugin.options.showOfflineMapExport
1048 1049 1050 1051 1052
                onClicked:      showExport()
            }
            QGCButton {
                text:           qsTr("Options")
                width:          _buttonSize
1053
                onClicked:      mainWindow.showComponentDialog(optionsDialogComponent, qsTr("Offline Maps Options"), mainWindow.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
1054 1055
            }
        }
Don Gagne's avatar
Don Gagne committed
1056

1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
        //-- Export Tile Sets
        QGCFlickable {
            id:                 _exporTiles
            clip:               true
            visible:            false
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.top:        parent.top
            anchors.bottom:     _exportButtonRow.top
            anchors.left:       parent.left
            anchors.right:      parent.right
            contentHeight:      _exportList.height
            Column {
                id:         _exportList
                width:      Math.min(_exporTiles.width, (ScreenTools.defaultFontPixelWidth  * 50).toFixed(0))
                spacing:    ScreenTools.defaultFontPixelHeight * 0.5
                anchors.horizontalCenter: parent.horizontalCenter
                QGCLabel {
                    text:           qsTr("Select Tile Sets to Export")
                    font.pointSize: ScreenTools.mediumFontPointSize
                }
                Item { width: 1; height: ScreenTools.defaultFontPixelHeight; }
                Repeater {
                    model: QGroundControl.mapEngineManager.tileSets
                    delegate: QGCCheckBox {
                        text:           object.name
                        checked:        object.selected
DonLakeFlyer's avatar
DonLakeFlyer committed
1083 1084 1085 1086 1087 1088 1089
                        onClicked:      object.selected = checked
                        Connections {
                            // This connection should theoretically not be needed since the `checked: object.selected` binding should work.
                            // But for some reason when the user clicks the check box taht binding breaks. Which in turns causes
                            // Select All/None to update the internal state but check box visible state is out of sync
                            target:             object
                            onSelectedChanged:  checked = object.selected
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
                        }
                    }
                }
            }
        }
        Row {
            id:                 _exportButtonRow
            visible:            _exporTiles.visible
            spacing:            _margins
            anchors.bottom:     parent.bottom
            anchors.margins:    ScreenTools.defaultFontPixelWidth
Gus Grubba's avatar
Gus Grubba committed
1101
            anchors.horizontalCenter: parent.horizontalCenter
1102
            QGCButton {
Gus Grubba's avatar
Gus Grubba committed
1103 1104
                text:           qsTr("Select All")
                width:          _bigButtonSize
1105 1106 1107
                onClicked:      QGroundControl.mapEngineManager.selectAll()
            }
            QGCButton {
Gus Grubba's avatar
Gus Grubba committed
1108 1109
                text:           qsTr("Select None")
                width:          _bigButtonSize
1110 1111 1112
                onClicked:      QGroundControl.mapEngineManager.selectNone()
            }
            QGCButton {
1113
                text:           qsTr("Export")
Gus Grubba's avatar
Gus Grubba committed
1114 1115 1116
                width:          _bigButtonSize
                enabled:        QGroundControl.mapEngineManager.selectedCount > 0
                onClicked: {
1117 1118 1119
                    fileDialog.title = qsTr("Export Tile Set")
                    fileDialog.selectExisting = false
                    fileDialog.openForSave()
Gus Grubba's avatar
Gus Grubba committed
1120 1121
                }
            }
1122 1123
            QGCButton {
                text:           qsTr("Cancel")
Gus Grubba's avatar
Gus Grubba committed
1124
                width:          _bigButtonSize
1125 1126
                onClicked:       showList()
            }
Don Gagne's avatar
Don Gagne committed
1127
        }
1128
    }
Gus Grubba's avatar
Gus Grubba committed
1129

1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
    Popup {
        id:                 exportToDiskProgress
        width:              mainWindow.width  * 0.666
        height:             mainWindow.height * 0.333
        modal:              true
        focus:              true
        parent:             Overlay.overlay
        x:                  Math.round((mainWindow.width  - width)  * 0.5)
        y:                  Math.round((mainWindow.height - height) * 0.5)
        closePolicy:        Popup.NoAutoClose
        background: Rectangle {
            anchors.fill:   parent
            color:          qgcPal.windowShadeDark
            border.color:   qgcPal.text
            radius:         ScreenTools.defaultFontPixelWidth
        }
        Column {
            id:                 exportCol
            spacing:            ScreenTools.defaultFontPixelHeight
            width:              parent.width
            anchors.centerIn:   parent
            QGCLabel {
                text:               QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionExporting ? qsTr("Tile Set Export Progress") : qsTr("Tile Set Export Completed")
                font.family:        ScreenTools.demiboldFontFamily
                font.pointSize:     ScreenTools.mediumFontPointSize
                anchors.horizontalCenter: parent.horizontalCenter
            }
            ProgressBar {
                width:          parent.width * 0.45
                from:           0
                to:             100
                value:          QGroundControl.mapEngineManager.actionProgress
                anchors.horizontalCenter: parent.horizontalCenter
            }
            BusyIndicator {
                visible:        QGroundControl.mapEngineManager ? QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionExporting : false
                running:        QGroundControl.mapEngineManager ? QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionExporting : false
                width:          exportCloseButton.height
                height:         exportCloseButton.height
                anchors.horizontalCenter: parent.horizontalCenter
            }
            QGCButton {
                id:             exportCloseButton
                text:           qsTr("Close")
                width:          _buttonSize
                visible:        !QGroundControl.mapEngineManager.exporting
                anchors.horizontalCenter: parent.horizontalCenter
                onClicked: {
                    exportToDiskProgress.close()
Gus Grubba's avatar
Gus Grubba committed
1179 1180 1181 1182 1183
                }
            }
        }
    }

1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
    Popup {
        id:                 importDialog
        width:              mainWindow.width  * 0.666
        height:             importCol.height  * 1.5
        modal:              true
        focus:              true
        parent:             Overlay.overlay
        x:                  Math.round((mainWindow.width  - width)  * 0.5)
        y:                  Math.round((mainWindow.height - height) * 0.5)
        closePolicy:        Popup.NoAutoClose
        background: Rectangle {
            anchors.fill:   parent
            color:          qgcPal.windowShadeDark
            border.color:   qgcPal.text
            radius:         ScreenTools.defaultFontPixelWidth
        }
        Column {
            id:                 importCol
            spacing:            ScreenTools.defaultFontPixelHeight
            width:              parent.width
            anchors.centerIn:   parent
            QGCLabel {
                text: {
                    if(QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionNone) {
                        return qsTr("Map Tile Set Import");
                    } else if(QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionImporting) {
                        return qsTr("Map Tile Set Import Progress");
                    } else {
                        return qsTr("Map Tile Set Import Completed");
Gus Grubba's avatar
Gus Grubba committed
1213
                    }
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
                }
                font.family:        ScreenTools.demiboldFontFamily
                font.pointSize:     ScreenTools.mediumFontPointSize
                anchors.horizontalCenter: parent.horizontalCenter
            }
            ProgressBar {
                width:          parent.width * 0.45
                from:           0
                to:             100
                visible:        QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionImporting
                value:          QGroundControl.mapEngineManager.actionProgress
                anchors.horizontalCenter: parent.horizontalCenter
            }
            BusyIndicator {
                visible:        QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionImporting
                running:        QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionImporting
                width:          ScreenTools.defaultFontPixelWidth * 2
                height:         width
                anchors.horizontalCenter: parent.horizontalCenter
            }
            Column {
                id:                 mapSetButtons
                spacing:            ScreenTools.defaultFontPixelHeight
                width:              ScreenTools.defaultFontPixelWidth * 24
                anchors.horizontalCenter: parent.horizontalCenter
                QGCRadioButton {
                    text:           qsTr("Append to existing set")
                    checked:        !QGroundControl.mapEngineManager.importReplace
                    onClicked:      QGroundControl.mapEngineManager.importReplace = !checked
                    visible:        QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionNone
                }
                QGCRadioButton {
                    text:           qsTr("Replace existing set")
                    checked:        QGroundControl.mapEngineManager.importReplace
                    onClicked:      QGroundControl.mapEngineManager.importReplace = checked
                    visible:        QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionNone
                }
            }
            QGCButton {
                text:           qsTr("Close")
                width:          _bigButtonSize * 1.25
                visible:        QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionDone
                anchors.horizontalCenter: parent.horizontalCenter
                onClicked: {
                    showList();
                    importDialog.close()
                }
            }
            Row {
                spacing:            _margins
                visible:            QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionNone
                anchors.horizontalCenter: parent.horizontalCenter
                QGCButton {
                    text:           qsTr("Import")
                    width:          _bigButtonSize * 1.25
                    onClicked: {
                        importDialog.close()
                        fileDialog.title = qsTr("Import Tile Set")
                        fileDialog.selectExisting = true
                        fileDialog.openForLoad()
Gus Grubba's avatar
Gus Grubba committed
1274
                    }
1275 1276 1277 1278 1279 1280 1281
                }
                QGCButton {
                    text:           qsTr("Cancel")
                    width:          _bigButtonSize * 1.25
                    onClicked: {
                        showList();
                        importDialog.close()
Gus Grubba's avatar
Gus Grubba committed
1282 1283 1284 1285 1286
                    }
                }
            }
        }
    }
1287
}