OfflineMap.qml 59.3 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9

10 11
import QtQuick                  2.3
import QtQuick.Controls         1.2
12
import QtQuick.Controls.Styles  1.4
13
import QtQuick.Dialogs          1.2
14 15 16
import QtQuick.Layouts          1.2
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

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

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

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

36 37 38
    property Fact   _mapboxFact:        QGroundControl.settingsManager.appSettings.mapboxToken
    property Fact   _esriFact:          QGroundControl.settingsManager.appSettings.esriToken

39
    property string mapType:            _settings.mapProvider.enumStringValue + " " + _settings.mapType.enumStringValue
40
    property bool   isMapInteractive:   false
41 42 43
    property var    savedCenter:        undefined
    property real   savedZoom:          3
    property string savedMapType:       ""
Don Gagne's avatar
Don Gagne committed
44
    property bool   _showPreview:       true
dogmaphobic's avatar
dogmaphobic committed
45
    property bool   _defaultSet:        offlineMapView && offlineMapView._currentSelection && offlineMapView._currentSelection.defaultSet
46 47
    property real   _margins:           ScreenTools.defaultFontPixelWidth * 0.5
    property real   _buttonSize:        ScreenTools.defaultFontPixelWidth * 12
Gus Grubba's avatar
Gus Grubba committed
48
    property real   _bigButtonSize:     ScreenTools.defaultFontPixelWidth * 16
dogmaphobic's avatar
dogmaphobic committed
49

dogmaphobic's avatar
dogmaphobic committed
50 51
    property bool   _saveRealEstate:          ScreenTools.isTinyScreen || ScreenTools.isShortScreen
    property real   _adjustableFontPointSize: _saveRealEstate ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
Don Gagne's avatar
Don Gagne committed
52

53 54
    property var    _mapAdjustedColor:  _map.isSatelliteMap ? "white" : "black"
    property bool   _tooManyTiles:      QGroundControl.mapEngineManager.tileCount > _maxTilesForDownload
55
    property var    _settings:          QGroundControl.settingsManager.flightMapSettings
Don Gagne's avatar
Don Gagne committed
56

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

dogmaphobic's avatar
dogmaphobic committed
61
    readonly property int _maxTilesForDownload: 100000
62

Don Gagne's avatar
Don Gagne committed
63
    QGCPalette { id: qgcPal }
64

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

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

    ExclusiveGroup { id: setGroup }

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

    function updateMap() {
        for (var i = 0; i < _map.supportedMapTypes.length; i++) {
Gus Grubba's avatar
Gus Grubba committed
97
            //console.log(_map.supportedMapTypes[i].name)
dogmaphobic's avatar
dogmaphobic committed
98 99
            if (mapType === _map.supportedMapTypes[i].name) {
                _map.activeMapType = _map.supportedMapTypes[i]
Gus Grubba's avatar
Gus Grubba committed
100
                //console.log("Update Map:" + " " + _map.activeMapType)
dogmaphobic's avatar
dogmaphobic committed
101 102 103 104 105 106
                handleChanges()
                return
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
107
    function addNewSet() {
108
        isMapInteractive = true
109
        mapType = _settings.mapProvider.enumStringValue + " " + _settings.mapType.enumStringValue
110 111
        resetMapToDefaults()
        handleChanges()
112
        _map.visible = true
dogmaphobic's avatar
dogmaphobic committed
113
        _tileSetList.visible = false
Don Gagne's avatar
Don Gagne committed
114
        infoView.visible = false
115
        _exporTiles.visible = false
Don Gagne's avatar
Don Gagne committed
116
        addNewSetView.visible = true
dogmaphobic's avatar
dogmaphobic committed
117 118 119
    }

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

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

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

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

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

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

dogmaphobic's avatar
dogmaphobic committed
205 206 207 208 209 210
    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
    }

    onMapTypeChanged: {
        updateMap()
211 212 213
        if(isMapInteractive) {
            QGroundControl.mapEngineManager.saveSetting(mapKey, mapType)
        }
dogmaphobic's avatar
dogmaphobic committed
214 215 216 217 218 219 220 221
    }

    MessageDialog {
        id:         errorDialog
        visible:    false
        text:       QGroundControl.mapEngineManager.errorMessage
        icon:       StandardIcon.Critical
        standardButtons: StandardButton.Ok
Don Gagne's avatar
Don Gagne committed
222
        title:      qsTr("Error Message")
dogmaphobic's avatar
dogmaphobic committed
223 224 225 226
        onYes: {
            errorDialog.visible = false
        }
    }
Don Gagne's avatar
Don Gagne committed
227

Don Gagne's avatar
Don Gagne committed
228 229 230 231 232 233 234 235 236 237
    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
238
            }
Don Gagne's avatar
Don Gagne committed
239

Don Gagne's avatar
Don Gagne committed
240 241 242
            QGCFlickable {
                anchors.fill:   parent
                contentHeight:  optionsColumn.height
243

Don Gagne's avatar
Don Gagne committed
244 245 246 247 248 249 250
                Column {
                    id:                 optionsColumn
                    anchors.margins:    ScreenTools.defaultFontPixelWidth
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    anchors.top:        parent.top
                    spacing:            ScreenTools.defaultFontPixelHeight / 2
251

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

Don Gagne's avatar
Don Gagne committed
254 255 256 257 258 259 260
                    QGCTextField {
                        id:                 maxCacheSize
                        maximumLength:      6
                        inputMethodHints:   Qt.ImhDigitsOnly
                        validator:          IntValidator {bottom: 1; top: 262144;}
                        text:               QGroundControl.mapEngineManager.maxDiskCache
                    }
261

Don Gagne's avatar
Don Gagne committed
262 263 264 265 266 267 268 269
                    Item { width: 1; height: 1 }

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

                    QGCTextField {
                        id:                 maxCacheMemSize
                        maximumLength:      4
                        inputMethodHints:   Qt.ImhDigitsOnly
270
                        validator:          IntValidator {bottom: 1; top: 1024;}
Don Gagne's avatar
Don Gagne committed
271
                        text:               QGroundControl.mapEngineManager.maxMemCache
dogmaphobic's avatar
dogmaphobic committed
272
                    }
Don Gagne's avatar
Don Gagne committed
273 274 275 276 277 278

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

279
                    Item { width: 1; height: 1; visible: _mapboxFact ? _mapboxFact.visible : false }
Gus Grubba's avatar
Gus Grubba committed
280
                    QGCLabel { text: qsTr("Mapbox Access Token"); visible: _mapboxFact ? _mapboxFact.visible : false }
281 282
                    FactTextField {
                        fact:               _mapboxFact
283
                        visible:            _mapboxFact ? _mapboxFact.visible : false
284 285
                        maximumLength:      256
                        width:              ScreenTools.defaultFontPixelWidth * 30
Don Gagne's avatar
Don Gagne committed
286 287
                    }
                    QGCLabel {
Gus Grubba's avatar
Gus Grubba committed
288
                        text:           qsTr("To enable Mapbox maps, enter your access token.")
289
                        visible:        _mapboxFact ? _mapboxFact.visible : false
Don Gagne's avatar
Don Gagne committed
290 291
                        font.pointSize: _adjustableFontPointSize
                    }
Gus Grubba's avatar
Gus Grubba committed
292

293 294
                    Item { width: 1; height: 1; visible: _esriFact ? _esriFact.visible : false }
                    QGCLabel { text: qsTr("Esri Access Token"); visible: _esriFact ? _esriFact.visible : false }
295 296
                    FactTextField {
                        fact:               _esriFact
297
                        visible:            _esriFact ? _esriFact.visible : false
298 299
                        maximumLength:      256
                        width:              ScreenTools.defaultFontPixelWidth * 30
Gus Grubba's avatar
Gus Grubba committed
300 301
                    }
                    QGCLabel {
Gus Grubba's avatar
Gus Grubba committed
302
                        text:           qsTr("To enable Esri maps, enter your access token.")
303
                        visible:        _esriFact ? _esriFact.visible : false
Gus Grubba's avatar
Gus Grubba committed
304 305
                        font.pointSize: _adjustableFontPointSize
                    }
Don Gagne's avatar
Don Gagne committed
306 307 308 309 310 311 312 313
                } // GridLayout
            } // QGCFlickable
        } // QGCViewDialog - optionsDialog
    } // Component - optionsDialogComponent

    Component {
        id: deleteConfirmationDialogComponent
        QGCViewMessage {
dogmaphobic's avatar
dogmaphobic committed
314 315 316 317 318 319
            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
320
            }
Don Gagne's avatar
Don Gagne committed
321 322
            function accept() {
                QGroundControl.mapEngineManager.deleteTileSet(offlineMapView._currentSelection)
dogmaphobic's avatar
dogmaphobic committed
323
                deleteConfirmationDialog.hideDialog()
Don Gagne's avatar
Don Gagne committed
324 325
                leaveInfoView()
                showList()
dogmaphobic's avatar
dogmaphobic committed
326 327
            }
        }
Don Gagne's avatar
Don Gagne committed
328 329 330 331 332 333
    }

    QGCViewPanel {
        id:                 panel
        anchors.fill:       parent

334 335 336 337 338 339
        FlightMap {
            id:                         _map
            anchors.fill:               parent
            visible:                    false
            allowGCSLocationCenter:     true
            allowVehicleLocationCenter: false
Don Gagne's avatar
Don Gagne committed
340
            gesture.flickDeceleration:  3000
341
            mapName:                    "OfflineMap"
Don Gagne's avatar
Don Gagne committed
342

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

Don Gagne's avatar
Don Gagne committed
345 346 347 348 349 350 351 352 353
            MapRectangle {
                id:             mapBoundary
                border.width:   2
                border.color:   "red"
                color:          Qt.rgba(1,0,0,0.05)
                smooth:         true
                antialiasing:   true
            }

354
            Component.onCompleted: resetMapToDefaults()
Don Gagne's avatar
Don Gagne committed
355

356 357 358 359 360 361 362 363
            onCenterChanged:    handleChanges()
            onZoomLevelChanged: handleChanges()
            onWidthChanged:     handleChanges()
            onHeightChanged:    handleChanges()

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

Don Gagne's avatar
Don Gagne committed
366 367 368 369 370 371
            MapScale {
                anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
                anchors.bottomMargin:   anchors.leftMargin
                anchors.left:           parent.left
                anchors.bottom:         parent.bottom
                mapControl:             _map
372
            }
Don Gagne's avatar
Don Gagne committed
373

dogmaphobic's avatar
dogmaphobic committed
374
            //-----------------------------------------------------------------
Don Gagne's avatar
Don Gagne committed
375 376 377
            //-- Show Set Info
            Rectangle {
                id:                 infoView
dogmaphobic's avatar
dogmaphobic committed
378
                anchors.margins:    ScreenTools.defaultFontPixelHeight
Don Gagne's avatar
Don Gagne committed
379
                anchors.right:      parent.right
dogmaphobic's avatar
dogmaphobic committed
380 381 382 383
                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
384 385
                radius:             ScreenTools.defaultFontPixelWidth * 0.5
                visible:            false
386 387 388 389 390 391 392 393

                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
394 395
                property real       _labelWidth:    ScreenTools.defaultFontPixelWidth * 10
                property real       _valueWidth:    ScreenTools.defaultFontPixelWidth * 14
396
                Column {
dogmaphobic's avatar
dogmaphobic committed
397 398 399 400
                    id:                 tileInfoColumn
                    anchors.margins:    ScreenTools.defaultFontPixelHeight * 0.5
                    spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                    anchors.centerIn:   parent
401
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
402 403 404 405 406 407
                        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
408 409 410 411 412 413 414 415
                        visible:        _defaultSet
                    }
                    QGCTextField {
                        id:             editSetName
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        visible:        !_defaultSet
                        text:           offlineMapView._currentSelection ? offlineMapView._currentSelection.name : ""
416 417
                    }
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
418 419 420
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
dogmaphobic's avatar
dogmaphobic committed
421 422 423 424 425 426 427 428 429
                        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
430
                        horizontalAlignment: Text.AlignHCenter
431
                    }
dogmaphobic's avatar
dogmaphobic committed
432 433 434 435 436 437 438
                    //-- 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; }
439
                    }
dogmaphobic's avatar
dogmaphobic committed
440 441 442 443 444 445 446 447 448 449 450 451 452
                    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; }
453
                    }
Don Gagne's avatar
Don Gagne committed
454

dogmaphobic's avatar
dogmaphobic committed
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
                    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
487 488
                        QGCButton {
                            text:       qsTr("Resume Download")
dogmaphobic's avatar
dogmaphobic committed
489 490
                            visible:    offlineMapView._currentSelection && offlineMapView._currentSelection && !_defaultSet && (!offlineMapView._currentSelection.complete && !offlineMapView._currentSelection.downloading)
                            width:      ScreenTools.defaultFontPixelWidth * 16
Don Gagne's avatar
Don Gagne committed
491 492 493 494
                            onClicked: {
                                if(offlineMapView._currentSelection)
                                    offlineMapView._currentSelection.resumeDownloadTask()
                            }
495
                        }
Don Gagne's avatar
Don Gagne committed
496 497
                        QGCButton {
                            text:       qsTr("Cancel Download")
dogmaphobic's avatar
dogmaphobic committed
498 499
                            visible:    offlineMapView._currentSelection && offlineMapView._currentSelection && !_defaultSet && (!offlineMapView._currentSelection.complete && offlineMapView._currentSelection.downloading)
                            width:      ScreenTools.defaultFontPixelWidth * 16
Don Gagne's avatar
Don Gagne committed
500 501 502 503
                            onClicked: {
                                if(offlineMapView._currentSelection)
                                    offlineMapView._currentSelection.cancelDownloadTask()
                            }
504
                        }
Don Gagne's avatar
Don Gagne committed
505 506
                        QGCButton {
                            text:       qsTr("Delete")
dogmaphobic's avatar
dogmaphobic committed
507
                            width:      ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
Don Gagne's avatar
Don Gagne committed
508
                            onClicked:  showDialog(deleteConfirmationDialogComponent, qsTr("Confirm Delete"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
509
                        }
Don Gagne's avatar
Don Gagne committed
510
                        QGCButton {
Gus Grubba's avatar
Gus Grubba committed
511 512 513 514 515 516 517 518 519 520 521 522 523 524
                            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
525 526 527 528 529
                            width:      ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
                            onClicked: {
                                leaveInfoView()
                                showList()
                            }
530
                        }
dogmaphobic's avatar
dogmaphobic committed
531 532 533
                    }
                }
            } // Rectangle - infoView
Don Gagne's avatar
Don Gagne committed
534

dogmaphobic's avatar
dogmaphobic committed
535 536
            //-----------------------------------------------------------------
            //-- Add new set
Don Gagne's avatar
Don Gagne committed
537 538 539 540
            Item {
                id:             addNewSetView
                anchors.fill:   parent
                visible:        false
Don Gagne's avatar
Don Gagne committed
541

542 543 544 545 546 547 548 549 550 551
                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
552
                    }
553

554 555 556 557 558 559 560 561 562 563
                    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

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

566 567 568 569 570 571 572 573 574
                        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
575

576 577 578 579
                        Rectangle {
                            anchors.fill:   parent
                            border.color:   _mapAdjustedColor
                            color:          "transparent"
Don Gagne's avatar
Don Gagne committed
580

581
                            QGCMapLabel {
582
                                anchors.centerIn:   parent
583
                                map:                minZoomPreview
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
                                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

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

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

620
                            QGCMapLabel {
621
                                anchors.centerIn:   parent
622
                                map:                maxZoomPreview
623 624 625 626 627 628 629 630
                                text:               qsTr("Max Zoom: %1").arg(sliderMaxZoom.value)
                            }
                            MouseArea {
                                anchors.fill:   parent
                                onClicked:      _showPreview = false
                            }
                        }
                    } // Map
Don Gagne's avatar
Don Gagne committed
631
                }
632
            } // Item - Add new set view
633 634 635 636 637 638 639 640 641 642 643

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

646 647 648 649 650
        //-- Add new set dialog
        Rectangle {
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.verticalCenter: parent.verticalCenter
            anchors.right:      parent.right
651
            visible:            addNewSetView.visible
652 653 654 655 656
            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

657 658 659
            //-- Eat mouse events
            DeadMouseArea {
                anchors.fill: parent
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
            }

            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
690
                    anchors.right:      parent.right
691
                    spacing:            ScreenTools.defaultFontPixelHeight * (ScreenTools.isTinyScreen ? 0.25 : 0.5)
Don Gagne's avatar
Don Gagne committed
692

693 694
                    Column {
                        spacing:            ScreenTools.isTinyScreen ? 0 : ScreenTools.defaultFontPixelHeight * 0.25
Don Gagne's avatar
Don Gagne committed
695 696
                        anchors.left:       parent.left
                        anchors.right:      parent.right
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
                        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)
                                if(_dropButtonsExclusiveGroup.current)
                                    _dropButtonsExclusiveGroup.current.checked = false
                                _dropButtonsExclusiveGroup.current = null
                            }
                            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
733
                    }
Don Gagne's avatar
Don Gagne committed
734

735 736 737 738 739 740 741
                    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
742 743

                        Column {
744 745 746 747
                            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
748 749
                            anchors.left:       parent.left
                            anchors.right:      parent.right
750 751 752 753 754

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

757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
                            Slider {
                                id:                         sliderMinZoom
                                anchors.left:               parent.left
                                anchors.right:              parent.right
                                height:                     sliderTouchArea * 1.25
                                minimumValue:               minZoomLevel
                                maximumValue:               maxZoomLevel
                                stepSize:                   1
                                updateValueWhileDragging:   true
                                property real _savedZoom
                                Component.onCompleted:      Math.max(sliderMinZoom.value = _map.zoomLevel - 4, 2)
                                onValueChanged: {
                                    if(sliderMinZoom.value > sliderMaxZoom.value) {
                                        sliderMaxZoom.value = sliderMinZoom.value
                                    }
                                    handleChanges()
Don Gagne's avatar
Don Gagne committed
773
                                }
774 775 776 777 778 779
                                style: SliderStyle {
                                    groove: Rectangle {
                                        implicitWidth:  sliderMinZoom.width
                                        implicitHeight: 4
                                        color:          qgcPal.colorBlue
                                        radius:         4
Don Gagne's avatar
Don Gagne committed
780
                                    }
781 782 783 784 785 786 787 788 789 790 791 792 793 794
                                    handle: Rectangle {
                                        anchors.centerIn: parent
                                        color:          qgcPal.button
                                        border.color:   qgcPal.buttonText
                                        border.width:   1
                                        implicitWidth:  sliderTouchArea
                                        implicitHeight: sliderTouchArea
                                        radius:         sliderTouchArea * 0.5
                                        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
795 796
                                        }
                                    }
Don Gagne's avatar
Don Gagne committed
797
                                }
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
                            } // Slider - min zoom

                            Slider {
                                id:                         sliderMaxZoom
                                anchors.left:               parent.left
                                anchors.right:              parent.right
                                height:                     sliderTouchArea * 1.25
                                minimumValue:               minZoomLevel
                                maximumValue:               maxZoomLevel
                                stepSize:                   1
                                updateValueWhileDragging:   true
                                property real _savedZoom
                                Component.onCompleted:      Math.min(sliderMaxZoom.value = _map.zoomLevel + 2, 20)
                                onValueChanged: {
                                    if(sliderMaxZoom.value < sliderMinZoom.value) {
                                        sliderMinZoom.value = sliderMaxZoom.value
Don Gagne's avatar
Don Gagne committed
814
                                    }
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
                                    handleChanges()
                                }
                                style: SliderStyle {
                                    groove: Rectangle {
                                        implicitWidth:  sliderMaxZoom.width
                                        implicitHeight: 4
                                        color:          qgcPal.colorBlue
                                        radius:         4
                                    }
                                    handle: Rectangle {
                                        anchors.centerIn: parent
                                        color:          qgcPal.button
                                        border.color:   qgcPal.buttonText
                                        border.width:   1
                                        implicitWidth:  sliderTouchArea
                                        implicitHeight: sliderTouchArea
                                        radius:         sliderTouchArea * 0.5
                                        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
838
                                        }
Don Gagne's avatar
Don Gagne committed
839
                                    }
840 841
                                }
                            } // Slider - max zoom
Don Gagne's avatar
Don Gagne committed
842

843 844 845 846 847 848 849 850 851 852 853
                            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
                                }
854

855 856 857
                                QGCLabel {
                                    text:           qsTr("Est Size:")
                                    font.pointSize: _adjustableFontPointSize
dogmaphobic's avatar
dogmaphobic committed
858
                                }
859 860 861
                                QGCLabel {
                                    text:           QGroundControl.mapEngineManager.tileSizeStr
                                    font.pointSize: _adjustableFontPointSize
Don Gagne's avatar
Don Gagne committed
862
                                }
dogmaphobic's avatar
dogmaphobic committed
863
                            }
864 865
                        } // Column - Zoom info
                    } // Rectangle - Zoom info
dogmaphobic's avatar
dogmaphobic committed
866

867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
                    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
903 904 905 906 907 908

        QGCFlickable {
            id:                 _tileSetList
            clip:               true
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.top:        parent.top
909
            anchors.bottom:     _listButtonRow.top
Don Gagne's avatar
Don Gagne committed
910 911 912 913 914 915 916 917 918
            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
919
                ExclusiveGroup { id: selectionGroup }
Don Gagne's avatar
Don Gagne committed
920 921
                OfflineMapButton {
                    id:             firstButton
922
                    text:           qsTr("Add New Set")
Don Gagne's avatar
Don Gagne committed
923
                    width:          _cacheList.width
924 925 926
                    height:         ScreenTools.defaultFontPixelHeight * (ScreenTools.isMobile ? 3 : 2)
                    currentSet:     _currentSelection
                    exclusiveGroup: selectionGroup
Don Gagne's avatar
Don Gagne committed
927 928 929
                    onClicked: {
                        offlineMapView._currentSelection = null
                        addNewSet()
dogmaphobic's avatar
dogmaphobic committed
930 931
                    }
                }
Don Gagne's avatar
Don Gagne committed
932 933 934 935 936
                Repeater {
                    model: QGroundControl.mapEngineManager.tileSets
                    delegate: OfflineMapButton {
                        text:           object.name
                        size:           object.downloadStatus
dogmaphobic's avatar
dogmaphobic committed
937
                        tiles:          object.totalTileCount
Don Gagne's avatar
Don Gagne committed
938 939
                        complete:       object.complete
                        width:          firstButton.width
940 941 942 943
                        height:         ScreenTools.defaultFontPixelHeight * (ScreenTools.isMobile ? 3 : 2)
                        exclusiveGroup: selectionGroup
                        currentSet:     _currentSelection
                        tileSet:        object
Don Gagne's avatar
Don Gagne committed
944 945 946
                        onClicked: {
                            offlineMapView._currentSelection = object
                            showInfo()
dogmaphobic's avatar
dogmaphobic committed
947
                        }
dogmaphobic's avatar
dogmaphobic committed
948 949 950 951
                    }
                }
            }
        }
952 953 954 955 956 957
        Row {
            id:                 _listButtonRow
            visible:            _tileSetList.visible
            spacing:            _margins
            anchors.bottom:     parent.bottom
            anchors.margins:    ScreenTools.defaultFontPixelWidth
Gus Grubba's avatar
Gus Grubba committed
958
            anchors.horizontalCenter: parent.horizontalCenter
959 960 961
            QGCButton {
                text:           qsTr("Import")
                width:          _buttonSize
962
                visible:        QGroundControl.corePlugin.options.showOfflineMapImport
963 964
                onClicked: {
                    QGroundControl.mapEngineManager.importAction = QGCMapEngineManager.ActionNone
965
                    rootLoader.sourceComponent = importDialog
966
                }
967 968 969 970
            }
            QGCButton {
                text:           qsTr("Export")
                width:          _buttonSize
971
                visible:        QGroundControl.corePlugin.options.showOfflineMapExport
972 973 974 975 976 977 978 979 980
                enabled:        QGroundControl.mapEngineManager.tileSets.count > 1
                onClicked:      showExport()
            }
            QGCButton {
                text:           qsTr("Options")
                width:          _buttonSize
                onClicked:      showDialog(optionsDialogComponent, qsTr("Offline Maps Options"), qgcView.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
            }
        }
Don Gagne's avatar
Don Gagne committed
981

982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
        //-- 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
                        onClicked: {
                            object.selected = checked
                        }
                    }
                }
            }
        }
        Row {
            id:                 _exportButtonRow
            visible:            _exporTiles.visible
            spacing:            _margins
            anchors.bottom:     parent.bottom
            anchors.margins:    ScreenTools.defaultFontPixelWidth
Gus Grubba's avatar
Gus Grubba committed
1021
            anchors.horizontalCenter: parent.horizontalCenter
1022
            QGCButton {
Gus Grubba's avatar
Gus Grubba committed
1023 1024
                text:           qsTr("Select All")
                width:          _bigButtonSize
1025 1026 1027
                onClicked:      QGroundControl.mapEngineManager.selectAll()
            }
            QGCButton {
Gus Grubba's avatar
Gus Grubba committed
1028 1029
                text:           qsTr("Select None")
                width:          _bigButtonSize
1030 1031 1032
                onClicked:      QGroundControl.mapEngineManager.selectNone()
            }
            QGCButton {
1033
                text:           qsTr("Export")
Gus Grubba's avatar
Gus Grubba committed
1034 1035 1036 1037
                width:          _bigButtonSize
                enabled:        QGroundControl.mapEngineManager.selectedCount > 0
                onClicked: {
                    showList();
Gus Grubba's avatar
Gus Grubba committed
1038
                    if(QGroundControl.mapEngineManager.exportSets()) {
1039
                        rootLoader.sourceComponent = exportToDiskProgress
Gus Grubba's avatar
Gus Grubba committed
1040
                    }
Gus Grubba's avatar
Gus Grubba committed
1041 1042
                }
            }
1043 1044
            QGCButton {
                text:           qsTr("Cancel")
Gus Grubba's avatar
Gus Grubba committed
1045
                width:          _bigButtonSize
1046 1047
                onClicked:       showList()
            }
Don Gagne's avatar
Don Gagne committed
1048 1049
        }
    } // QGCViewPanel
Gus Grubba's avatar
Gus Grubba committed
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059

    Component {
        id: exportToDiskProgress
        Rectangle {
            width:      mainWindow.width
            height:     mainWindow.height
            color:      "black"
            anchors.centerIn: parent
            Rectangle {
                width:  parent.width  * 0.5
Gus Grubba's avatar
Gus Grubba committed
1060
                height: exportCol.height * 1.25
Gus Grubba's avatar
Gus Grubba committed
1061 1062 1063 1064 1065
                radius: ScreenTools.defaultFontPixelWidth
                color:  qgcPal.windowShadeDark
                border.color: qgcPal.text
                anchors.centerIn: parent
                Column {
Gus Grubba's avatar
Gus Grubba committed
1066
                    id:                 exportCol
Gus Grubba's avatar
Gus Grubba committed
1067 1068 1069 1070
                    spacing:            ScreenTools.defaultFontPixelHeight
                    width:              parent.width
                    anchors.centerIn:   parent
                    QGCLabel {
Gus Grubba's avatar
Gus Grubba committed
1071
                        text:               QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionExporting ? qsTr("Tile Set Export Progress") : qsTr("Tile Set Export Completed")
Gus Grubba's avatar
Gus Grubba committed
1072 1073 1074 1075 1076 1077 1078 1079
                        font.family:        ScreenTools.demiboldFontFamily
                        font.pointSize:     ScreenTools.mediumFontPointSize
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
                    ProgressBar {
                        id:             progressBar
                        width:          parent.width * 0.45
                        maximumValue:   100
Gus Grubba's avatar
Gus Grubba committed
1080
                        value:          QGroundControl.mapEngineManager.actionProgress
Gus Grubba's avatar
Gus Grubba committed
1081 1082 1083
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
                    BusyIndicator {
1084 1085
                        visible:        QGroundControl.mapEngineManager ? QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionExporting : false
                        running:        QGroundControl.mapEngineManager ? QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionExporting : false
Gus Grubba's avatar
Gus Grubba committed
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
                        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: {
1097 1098
                            mainWindow.enableToolbar()
                            rootLoader.sourceComponent = null
Gus Grubba's avatar
Gus Grubba committed
1099 1100 1101 1102 1103 1104 1105
                        }
                    }
                }
            }
        }
    }

Gus Grubba's avatar
Gus Grubba committed
1106 1107 1108 1109 1110 1111 1112 1113
    Component {
        id: importDialog
        Rectangle {
            width:      mainWindow.width
            height:     mainWindow.height
            color:      "black"
            anchors.centerIn: parent
            Rectangle {
1114
                width:  parent.width  * 0.5
Gus Grubba's avatar
Gus Grubba committed
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
                height: importCol.height * 1.5
                radius: ScreenTools.defaultFontPixelWidth
                color:  qgcPal.windowShadeDark
                border.color: qgcPal.text
                anchors.centerIn: parent
                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");
                            }
                        }
                        font.family:        ScreenTools.demiboldFontFamily
                        font.pointSize:     ScreenTools.mediumFontPointSize
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
                    ProgressBar {
                        id:             progressBar
                        width:          parent.width * 0.45
                        maximumValue:   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
Gus Grubba's avatar
Gus Grubba committed
1150 1151
                        width:          ScreenTools.defaultFontPixelWidth * 2
                        height:         width
Gus Grubba's avatar
Gus Grubba committed
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 1179
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
                    ExclusiveGroup { id: radioGroup }
                    Column {
                        spacing:            ScreenTools.defaultFontPixelHeight
                        width:              ScreenTools.defaultFontPixelWidth * 24
                        anchors.horizontalCenter: parent.horizontalCenter
                        QGCRadioButton {
                            exclusiveGroup: radioGroup
                            text:           qsTr("Append to existing set")
                            checked:        !QGroundControl.mapEngineManager.importReplace
                            onClicked:      QGroundControl.mapEngineManager.importReplace = !checked
                            visible:        QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionNone
                        }
                        QGCRadioButton {
                            exclusiveGroup: radioGroup
                            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: {
Gus Grubba's avatar
Gus Grubba committed
1180
                            showList();
1181 1182
                            mainWindow.enableToolbar()
                            rootLoader.sourceComponent = null
Gus Grubba's avatar
Gus Grubba committed
1183 1184 1185 1186 1187 1188 1189
                        }
                    }
                    Row {
                        spacing:            _margins
                        visible:            QGroundControl.mapEngineManager.importAction === QGCMapEngineManager.ActionNone
                        anchors.horizontalCenter: parent.horizontalCenter
                        QGCButton {
1190
                            text:           qsTr("Import")
Gus Grubba's avatar
Gus Grubba committed
1191 1192 1193 1194
                            width:          _bigButtonSize * 1.25
                            onClicked: {
                                if(!QGroundControl.mapEngineManager.importSets()) {
                                    showList();
1195 1196
                                    mainWindow.enableToolbar()
                                    rootLoader.sourceComponent = null
Gus Grubba's avatar
Gus Grubba committed
1197 1198 1199 1200 1201 1202 1203
                                }
                            }
                        }
                        QGCButton {
                            text:           qsTr("Cancel")
                            width:          _bigButtonSize * 1.25
                            onClicked: {
Gus Grubba's avatar
Gus Grubba committed
1204
                                showList();
1205 1206
                                mainWindow.enableToolbar()
                                rootLoader.sourceComponent = null
Gus Grubba's avatar
Gus Grubba committed
1207 1208 1209 1210 1211 1212 1213 1214
                            }
                        }
                    }
                }
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
1215
} // QGCView