OfflineMap.qml 45.2 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

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

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

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

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

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

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

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

Don Gagne's avatar
Don Gagne committed
49 50 51
    readonly property real minZoomLevel: 3
    readonly property real maxZoomLevel: 20

dogmaphobic's avatar
dogmaphobic committed
52
    readonly property int _maxTilesForDownload: 100000
53

Don Gagne's avatar
Don Gagne committed
54
    QGCPalette { id: qgcPal }
55

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

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

    ExclusiveGroup { id: setGroup }

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

    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
96
    function addNewSet() {
97
        isMapInteractive = true
98
        mapType = QGroundControl.flightMapSettings.mapProvider + " " + QGroundControl.flightMapSettings.mapType
99 100
        resetMapToDefaults()
        handleChanges()
101
        _map.visible = true
dogmaphobic's avatar
dogmaphobic committed
102
        _tileSetList.visible = false
Don Gagne's avatar
Don Gagne committed
103
        infoView.visible = false
104
        _exporTiles.visible = false
Don Gagne's avatar
Don Gagne committed
105
        addNewSetView.visible = true
dogmaphobic's avatar
dogmaphobic committed
106 107 108
    }

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

117 118 119 120 121 122 123 124 125
    function showExport() {
        isMapInteractive = false
        _map.visible = false
        _tileSetList.visible = false
        infoView.visible = false
        addNewSetView.visible = false
        _exporTiles.visible = true
    }

dogmaphobic's avatar
dogmaphobic committed
126
    function showInfo() {
127
        isMapInteractive = false
Don Gagne's avatar
Don Gagne committed
128
        if(_currentSelection && !offlineMapView._currentSelection.deleting) {
129
            enterInfoView()
dogmaphobic's avatar
dogmaphobic committed
130 131 132 133
        } else
            showList()
    }

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

    function leaveInfoView() {
182
        mapBoundary.visible = false
183 184 185
        _map.center = savedCenter
        _map.zoomLevel = savedZoom
        mapType = savedMapType
186 187 188 189 190
    }

    function resetMapToDefaults() {
        _map.center = QGroundControl.flightMapPosition
        _map.zoomLevel = QGroundControl.flightMapZoom
191 192
    }

dogmaphobic's avatar
dogmaphobic committed
193 194 195 196 197 198
    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
    }

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

    MessageDialog {
        id:         errorDialog
        visible:    false
        text:       QGroundControl.mapEngineManager.errorMessage
        icon:       StandardIcon.Critical
        standardButtons: StandardButton.Ok
Don Gagne's avatar
Don Gagne committed
210
        title:      qsTr("Error Message")
dogmaphobic's avatar
dogmaphobic committed
211 212 213 214
        onYes: {
            errorDialog.visible = false
        }
    }
Don Gagne's avatar
Don Gagne committed
215

Don Gagne's avatar
Don Gagne committed
216 217 218 219 220 221 222 223 224 225 226
    Component {
        id: optionsDialogComponent

        QGCViewDialog {
            id: optionDialog

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

Don Gagne's avatar
Don Gagne committed
229 230 231
            QGCFlickable {
                anchors.fill:   parent
                contentHeight:  optionsColumn.height
232

Don Gagne's avatar
Don Gagne committed
233 234 235 236 237 238 239
                Column {
                    id:                 optionsColumn
                    anchors.margins:    ScreenTools.defaultFontPixelWidth
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    anchors.top:        parent.top
                    spacing:            ScreenTools.defaultFontPixelHeight / 2
240

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

Don Gagne's avatar
Don Gagne committed
243 244 245 246 247 248 249
                    QGCTextField {
                        id:                 maxCacheSize
                        maximumLength:      6
                        inputMethodHints:   Qt.ImhDigitsOnly
                        validator:          IntValidator {bottom: 1; top: 262144;}
                        text:               QGroundControl.mapEngineManager.maxDiskCache
                    }
250

Don Gagne's avatar
Don Gagne committed
251 252 253 254 255 256 257 258
                    Item { width: 1; height: 1 }

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

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

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

                    Item { width: 1; height: 1 }

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

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

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

    Component {
        id: deleteConfirmationDialogComponent
        QGCViewMessage {
dogmaphobic's avatar
dogmaphobic committed
291 292 293 294 295 296
            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
297
            }
Don Gagne's avatar
Don Gagne committed
298 299
            function accept() {
                QGroundControl.mapEngineManager.deleteTileSet(offlineMapView._currentSelection)
dogmaphobic's avatar
dogmaphobic committed
300
                deleteConfirmationDialog.hideDialog()
Don Gagne's avatar
Don Gagne committed
301 302
                leaveInfoView()
                showList()
dogmaphobic's avatar
dogmaphobic committed
303 304
            }
        }
Don Gagne's avatar
Don Gagne committed
305 306 307 308 309 310 311 312 313
    }

    QGCViewPanel {
        id:                 panel
        anchors.fill:       parent

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

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

Don Gagne's avatar
Don Gagne committed
320 321 322 323 324 325 326 327 328 329 330
            plugin: Plugin { name: "QGroundControl" }

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

331
            Component.onCompleted: resetMapToDefaults()
Don Gagne's avatar
Don Gagne committed
332

333 334 335 336 337 338 339 340
            onCenterChanged:    handleChanges()
            onZoomLevelChanged: handleChanges()
            onWidthChanged:     handleChanges()
            onHeightChanged:    handleChanges()

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

343 344 345 346 347 348 349 350 351 352 353
            CenterMapDropButton {
                anchors.margins:    _margins
                anchors.left:       parent.left
                anchors.top:        parent.top
                map:                _map
                z:                  QGroundControl.zOrderTopMost
                showMission:        false
                showAllItems:       false
                visible:            addNewSetView.visible
            }

Don Gagne's avatar
Don Gagne committed
354 355 356 357 358 359
            MapScale {
                anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
                anchors.bottomMargin:   anchors.leftMargin
                anchors.left:           parent.left
                anchors.bottom:         parent.bottom
                mapControl:             _map
360
            }
Don Gagne's avatar
Don Gagne committed
361

dogmaphobic's avatar
dogmaphobic committed
362
            //-----------------------------------------------------------------
Don Gagne's avatar
Don Gagne committed
363 364 365
            //-- Show Set Info
            Rectangle {
                id:                 infoView
dogmaphobic's avatar
dogmaphobic committed
366
                anchors.margins:    ScreenTools.defaultFontPixelHeight
Don Gagne's avatar
Don Gagne committed
367
                anchors.right:      parent.right
dogmaphobic's avatar
dogmaphobic committed
368 369 370 371
                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
372 373
                radius:             ScreenTools.defaultFontPixelWidth * 0.5
                visible:            false
374 375 376 377 378 379 380 381

                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
382 383
                property real       _labelWidth:    ScreenTools.defaultFontPixelWidth * 10
                property real       _valueWidth:    ScreenTools.defaultFontPixelWidth * 14
384
                Column {
dogmaphobic's avatar
dogmaphobic committed
385 386 387 388
                    id:                 tileInfoColumn
                    anchors.margins:    ScreenTools.defaultFontPixelHeight * 0.5
                    spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                    anchors.centerIn:   parent
389
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
390 391 392 393 394 395
                        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
396 397
                    }
                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
398 399 400
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
dogmaphobic's avatar
dogmaphobic committed
401 402 403 404 405 406 407 408 409
                        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
410
                        horizontalAlignment: Text.AlignHCenter
411
                    }
dogmaphobic's avatar
dogmaphobic committed
412 413 414 415 416 417 418
                    //-- 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; }
419
                    }
dogmaphobic's avatar
dogmaphobic committed
420 421 422 423 424 425 426 427 428 429 430 431 432
                    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; }
433
                    }
Don Gagne's avatar
Don Gagne committed
434

dogmaphobic's avatar
dogmaphobic committed
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
                    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
467 468
                        QGCButton {
                            text:       qsTr("Resume Download")
dogmaphobic's avatar
dogmaphobic committed
469 470
                            visible:    offlineMapView._currentSelection && offlineMapView._currentSelection && !_defaultSet && (!offlineMapView._currentSelection.complete && !offlineMapView._currentSelection.downloading)
                            width:      ScreenTools.defaultFontPixelWidth * 16
Don Gagne's avatar
Don Gagne committed
471 472 473 474
                            onClicked: {
                                if(offlineMapView._currentSelection)
                                    offlineMapView._currentSelection.resumeDownloadTask()
                            }
475
                        }
Don Gagne's avatar
Don Gagne committed
476 477
                        QGCButton {
                            text:       qsTr("Cancel Download")
dogmaphobic's avatar
dogmaphobic committed
478 479
                            visible:    offlineMapView._currentSelection && offlineMapView._currentSelection && !_defaultSet && (!offlineMapView._currentSelection.complete && offlineMapView._currentSelection.downloading)
                            width:      ScreenTools.defaultFontPixelWidth * 16
Don Gagne's avatar
Don Gagne committed
480 481 482 483
                            onClicked: {
                                if(offlineMapView._currentSelection)
                                    offlineMapView._currentSelection.cancelDownloadTask()
                            }
484
                        }
Don Gagne's avatar
Don Gagne committed
485 486
                        QGCButton {
                            text:       qsTr("Delete")
dogmaphobic's avatar
dogmaphobic committed
487
                            width:      ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
Don Gagne's avatar
Don Gagne committed
488
                            onClicked:  showDialog(deleteConfirmationDialogComponent, qsTr("Confirm Delete"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
489
                        }
Don Gagne's avatar
Don Gagne committed
490
                        QGCButton {
dogmaphobic's avatar
dogmaphobic committed
491 492 493 494 495 496
                            text:       qsTr("Close")
                            width:      ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
                            onClicked: {
                                leaveInfoView()
                                showList()
                            }
497
                        }
dogmaphobic's avatar
dogmaphobic committed
498 499 500
                    }
                }
            } // Rectangle - infoView
Don Gagne's avatar
Don Gagne committed
501

dogmaphobic's avatar
dogmaphobic committed
502 503
            //-----------------------------------------------------------------
            //-- Add new set
Don Gagne's avatar
Don Gagne committed
504 505 506 507
            Item {
                id:             addNewSetView
                anchors.fill:   parent
                visible:        false
Don Gagne's avatar
Don Gagne committed
508

509 510 511 512 513 514 515 516 517 518
                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
519
                    }
520

521 522 523 524 525 526 527 528 529 530
                    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

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

533 534 535 536 537 538 539 540 541
                        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
542

543 544 545 546
                        Rectangle {
                            anchors.fill:   parent
                            border.color:   _mapAdjustedColor
                            color:          "transparent"
Don Gagne's avatar
Don Gagne committed
547

548
                            QGCMapLabel {
549
                                anchors.centerIn:   parent
550
                                map:                minZoomPreview
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
                                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

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

572 573 574 575 576 577 578 579 580 581 582 583 584 585
                        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
586

587
                            QGCMapLabel {
588
                                anchors.centerIn:   parent
589
                                map:                maxZoomPreview
590 591 592 593 594 595 596 597
                                text:               qsTr("Max Zoom: %1").arg(sliderMaxZoom.value)
                            }
                            MouseArea {
                                anchors.fill:   parent
                                onClicked:      _showPreview = false
                            }
                        }
                    } // Map
Don Gagne's avatar
Don Gagne committed
598 599 600 601 602
                }

                //-- Add new set dialog
                Rectangle {
                    anchors.margins:    ScreenTools.defaultFontPixelWidth
dogmaphobic's avatar
dogmaphobic committed
603
                    anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
604
                    anchors.right:      parent.right
605
                    width:              ScreenTools.defaultFontPixelWidth * (ScreenTools.isTinyScreen ? 24 : 28)
606
                    height:             Math.min(parent.height - (anchors.margins * 2), addNewSetFlickable.y + addNewSetColumn.height + addNewSetLabel.anchors.margins)
dogmaphobic's avatar
dogmaphobic committed
607
                    color:              Qt.rgba(qgcPal.window.r, qgcPal.window.g, qgcPal.window.b, 0.85)
Don Gagne's avatar
Don Gagne committed
608 609 610 611 612 613 614 615 616 617 618 619 620
                    radius:             ScreenTools.defaultFontPixelWidth * 0.5

                    QGCLabel {
                        id:                 addNewSetLabel
                        anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
                        anchors.top:        parent.top
                        anchors.left:       parent.left
                        anchors.right:      parent.right
                        wrapMode:           Text.WordWrap
                        text:               qsTr("Add New Set")
                        font.pointSize:     _saveRealEstate ? ScreenTools.defaultFontPointSize : ScreenTools.mediumFontPointSize
                        horizontalAlignment: Text.AlignHCenter
                    }
Don Gagne's avatar
Don Gagne committed
621

Don Gagne's avatar
Don Gagne committed
622 623 624 625 626 627 628 629 630 631 632 633
                    QGCFlickable {
                        id:                     addNewSetFlickable
                        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth
                        anchors.rightMargin:    anchors.leftMargin
                        anchors.topMargin:      ScreenTools.defaultFontPixelWidth / 3
                        anchors.bottomMargin:   anchors.topMargin
                        anchors.top:            addNewSetLabel.bottom
                        anchors.left:           parent.left
                        anchors.right:          parent.right
                        anchors.bottom:         parent.bottom
                        clip:                   true
                        contentHeight:          addNewSetColumn.height
Don Gagne's avatar
Don Gagne committed
634 635

                        Column {
Don Gagne's avatar
Don Gagne committed
636
                            id:                 addNewSetColumn
Don Gagne's avatar
Don Gagne committed
637 638
                            anchors.left:       parent.left
                            anchors.right:      parent.right
639
                            spacing:            ScreenTools.defaultFontPixelHeight * (ScreenTools.isTinyScreen ? 0.25 : 0.5)
Don Gagne's avatar
Don Gagne committed
640
                            Column {
641
                                spacing:            ScreenTools.isTinyScreen ? 0 : ScreenTools.defaultFontPixelHeight * 0.25
Don Gagne's avatar
Don Gagne committed
642 643 644 645 646 647 648
                                anchors.left:       parent.left
                                anchors.right:      parent.right
                                QGCLabel { text: qsTr("Name:") }
                                QGCTextField {
                                    id:             setName
                                    anchors.left:   parent.left
                                    anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
649
                                }
dogmaphobic's avatar
dogmaphobic committed
650
                            }
Don Gagne's avatar
Don Gagne committed
651
                            Column {
652
                                spacing:            ScreenTools.isTinyScreen ? 0 : ScreenTools.defaultFontPixelHeight * 0.25
Don Gagne's avatar
Don Gagne committed
653 654 655
                                anchors.left:       parent.left
                                anchors.right:      parent.right
                                QGCLabel {
Don Gagne's avatar
Don Gagne committed
656 657
                                    text:       qsTr("Map type:")
                                    visible:    !_saveRealEstate
Don Gagne's avatar
Don Gagne committed
658
                                }
Don Gagne's avatar
Don Gagne committed
659 660 661 662 663 664 665 666 667 668
                                QGCComboBox {
                                    id:             mapCombo
                                    anchors.left:   parent.left
                                    anchors.right:  parent.right
                                    model:          QGroundControl.mapEngineManager.mapList
                                    onActivated: {
                                        mapType = textAt(index)
                                        if(_dropButtonsExclusiveGroup.current)
                                            _dropButtonsExclusiveGroup.current.checked = false
                                        _dropButtonsExclusiveGroup.current = null
Don Gagne's avatar
Don Gagne committed
669
                                    }
Don Gagne's avatar
Don Gagne committed
670 671 672 673 674 675
                                    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
676 677
                                        }
                                    }
Don Gagne's avatar
Don Gagne committed
678 679
                                }
                            }
Don Gagne's avatar
Don Gagne committed
680

Don Gagne's avatar
Don Gagne committed
681 682 683
                            Rectangle {
                                anchors.left:   parent.left
                                anchors.right:  parent.right
684
                                height:         zoomColumn.height + ScreenTools.defaultFontPixelHeight * 0.5
Don Gagne's avatar
Don Gagne committed
685 686 687 688 689 690
                                color:          qgcPal.window
                                border.color:   qgcPal.text
                                radius:         ScreenTools.defaultFontPixelWidth * 0.5

                                Column {
                                    id:                 zoomColumn
dogmaphobic's avatar
dogmaphobic committed
691
                                    anchors.margins:    ScreenTools.defaultFontPixelHeight * 0.25
Don Gagne's avatar
Don Gagne committed
692 693 694
                                    anchors.top:        parent.top
                                    anchors.left:       parent.left
                                    anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
695 696

                                    QGCLabel {
Don Gagne's avatar
Don Gagne committed
697
                                        text:           qsTr("Min Zoom: %1").arg(sliderMinZoom.value)
Don Gagne's avatar
Don Gagne committed
698 699 700
                                        font.pointSize: _adjustableFontPointSize
                                    }

Don Gagne's avatar
Don Gagne committed
701 702 703 704 705 706 707 708 709 710
                                    Slider {
                                        id:                         sliderMinZoom
                                        anchors.left:               parent.left
                                        anchors.right:              parent.right
                                        height:                     setName.height
                                        minimumValue:               minZoomLevel
                                        maximumValue:               maxZoomLevel
                                        stepSize:                   1
                                        updateValueWhileDragging:   true
                                        property real _savedZoom
dogmaphobic's avatar
dogmaphobic committed
711
                                        Component.onCompleted:      Math.max(sliderMinZoom.value = _map.zoomLevel - 4, 2)
Don Gagne's avatar
Don Gagne committed
712 713 714 715 716 717 718 719
                                        onValueChanged: {
                                            if(sliderMinZoom.value > sliderMaxZoom.value) {
                                                sliderMaxZoom.value = sliderMinZoom.value
                                            }
                                            handleChanges()
                                        }
                                    } // Slider - min zoom

Don Gagne's avatar
Don Gagne committed
720
                                    QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
721 722
                                        text:                       qsTr("Max Zoom: %1").arg(sliderMaxZoom.value)
                                        font.pointSize:             _adjustableFontPointSize
Don Gagne's avatar
Don Gagne committed
723
                                    }
Don Gagne's avatar
Don Gagne committed
724 725 726 727 728 729 730 731 732 733 734

                                    Slider {
                                        id:                         sliderMaxZoom
                                        anchors.left:               parent.left
                                        anchors.right:              parent.right
                                        height:                     setName.height
                                        minimumValue:               minZoomLevel
                                        maximumValue:               maxZoomLevel
                                        stepSize:                   1
                                        updateValueWhileDragging:   true
                                        property real _savedZoom
dogmaphobic's avatar
dogmaphobic committed
735
                                        Component.onCompleted:      Math.min(sliderMaxZoom.value = _map.zoomLevel + 2, 20)
Don Gagne's avatar
Don Gagne committed
736 737 738 739 740 741 742 743 744 745
                                        onValueChanged: {
                                            if(sliderMaxZoom.value < sliderMinZoom.value) {
                                                sliderMinZoom.value = sliderMaxZoom.value
                                            }
                                            handleChanges()
                                        }
                                    } // Slider - max zoom

                                    GridLayout {
                                        columns:    2
746
                                        rowSpacing: ScreenTools.isTinyScreen ? 0 : ScreenTools.defaultFontPixelHeight * 0.5
Don Gagne's avatar
Don Gagne committed
747
                                        QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
748
                                            text:           qsTr("Count:")
Don Gagne's avatar
Don Gagne committed
749 750 751
                                            font.pointSize: _adjustableFontPointSize
                                        }
                                        QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
752
                                            text:            QGroundControl.mapEngineManager.tileCountStr
Don Gagne's avatar
Don Gagne committed
753 754 755 756
                                            font.pointSize: _adjustableFontPointSize
                                        }

                                        QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
757
                                            text:           qsTr("Est Size:")
Don Gagne's avatar
Don Gagne committed
758 759 760 761 762 763
                                            font.pointSize: _adjustableFontPointSize
                                        }
                                        QGCLabel {
                                            text:           QGroundControl.mapEngineManager.tileSizeStr
                                            font.pointSize: _adjustableFontPointSize
                                        }
Don Gagne's avatar
Don Gagne committed
764
                                    }
Don Gagne's avatar
Don Gagne committed
765 766
                                } // Column - Zoom info
                            } // Rectangle - Zoom info
Don Gagne's avatar
Don Gagne committed
767

768 769 770 771 772 773 774
                            QGCLabel {
                                text:       qsTr("Too many tiles")
                                visible:    _tooManyTiles
                                color:      qgcPal.warningText
                                anchors.horizontalCenter: parent.horizontalCenter
                            }

dogmaphobic's avatar
dogmaphobic committed
775 776
                            Row {
                                spacing: ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
777
                                anchors.horizontalCenter: parent.horizontalCenter
dogmaphobic's avatar
dogmaphobic committed
778
                                QGCButton {
779 780
                                    id:         downloadButton
                                    text:       qsTr("Download")
dogmaphobic's avatar
dogmaphobic committed
781 782 783 784 785 786 787 788 789 790 791
                                    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 {
792 793
                                    text:   qsTr("Cancel")
                                    width:  downloadButton.width
dogmaphobic's avatar
dogmaphobic committed
794
                                    onClicked: {
Don Gagne's avatar
Don Gagne committed
795 796
                                        showList()
                                    }
Don Gagne's avatar
Don Gagne committed
797
                                }
dogmaphobic's avatar
dogmaphobic committed
798
                            }
dogmaphobic's avatar
dogmaphobic committed
799

Don Gagne's avatar
Don Gagne committed
800 801 802 803
                        } // Column
                    } // QGCFlickable
                } // Rectangle - Add new set dialog
            } // Item - Add new set view
Don Gagne's avatar
Don Gagne committed
804 805 806 807 808 809 810
        } // Map

        QGCFlickable {
            id:                 _tileSetList
            clip:               true
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.top:        parent.top
811
            anchors.bottom:     _listButtonRow.top
Don Gagne's avatar
Don Gagne committed
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
            anchors.left:       parent.left
            anchors.right:      parent.right
            contentHeight:      _cacheList.height

            Column {
                id:         _cacheList
                width:      Math.min(_tileSetList.width, (ScreenTools.defaultFontPixelWidth  * 50).toFixed(0))
                spacing:    ScreenTools.defaultFontPixelHeight * 0.5
                anchors.horizontalCenter: parent.horizontalCenter
                OfflineMapButton {
                    id:             firstButton
                    text:           qsTr("Add new set")
                    width:          _cacheList.width
                    height:         ScreenTools.defaultFontPixelHeight * 2
                    onClicked: {
                        offlineMapView._currentSelection = null
                        addNewSet()
dogmaphobic's avatar
dogmaphobic committed
829 830
                    }
                }
Don Gagne's avatar
Don Gagne committed
831 832 833 834 835
                Repeater {
                    model: QGroundControl.mapEngineManager.tileSets
                    delegate: OfflineMapButton {
                        text:           object.name
                        size:           object.downloadStatus
dogmaphobic's avatar
dogmaphobic committed
836
                        tiles:          object.totalTileCount
Don Gagne's avatar
Don Gagne committed
837 838 839 840 841 842
                        complete:       object.complete
                        width:          firstButton.width
                        height:         ScreenTools.defaultFontPixelHeight * 2
                        onClicked: {
                            offlineMapView._currentSelection = object
                            showInfo()
dogmaphobic's avatar
dogmaphobic committed
843
                        }
dogmaphobic's avatar
dogmaphobic committed
844 845 846 847
                    }
                }
            }
        }
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
        Row {
            id:                 _listButtonRow
            visible:            _tileSetList.visible
            spacing:            _margins
            anchors.bottom:     parent.bottom
            anchors.right:      parent.right
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            QGCButton {
                text:           qsTr("Import")
                width:          _buttonSize
            }
            QGCButton {
                text:           qsTr("Export")
                width:          _buttonSize
                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
871

872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
        //-- 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.right:      parent.right
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            QGCButton {
                text:           qsTr("All")
                width:          _buttonSize
                onClicked:      QGroundControl.mapEngineManager.selectAll()
            }
            QGCButton {
                text:           qsTr("None")
                width:          _buttonSize
                onClicked:      QGroundControl.mapEngineManager.selectNone()
            }
            QGCButton {
                text:           qsTr("Export")
                width:          _buttonSize
                enabled:        QGroundControl.mapEngineManager.selectedCount > 0
                onClicked: {
                    QGroundControl.mapEngineManager.exportSets()
                    showList()
                }
            }
            QGCButton {
                text:           qsTr("Cancel")
                width:          _buttonSize
                onClicked:       showList()
            }
Don Gagne's avatar
Don Gagne committed
936 937 938
        }
    } // QGCViewPanel
} // QGCView