SafeAreaMapVisual.qml 4.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

import QtQuick          2.3
import QtQuick.Controls 1.2
import QtLocation       5.3
import QtPositioning    5.3

import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.FlightMap     1.0

Item {
    id: _root

Valentin Platzgummer's avatar
Valentin Platzgummer committed
24 25
    property var map: undefined        ///< Map control to place item in
    property var geoArea: undefined   ///< GeoArea derived class.
26

Valentin Platzgummer's avatar
Valentin Platzgummer committed
27 28 29 30 31
    property var _depotVisual: 			undefined
    property var _depotDrag: 			undefined
    property bool _showDepot: 		geoArea.interactive

    opacity: 0.3
32 33 34 35 36

    signal clicked(int sequenceNumber)

    on_ShowDepotChanged: {
        if (_showDepot){
Valentin Platzgummer's avatar
Valentin Platzgummer committed
37 38
            _addDepotVisual()
            _addDepotDrag()
39
        } else {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
40 41
            _destroyDepotVisual()
            _destroyDepotDrag()
42 43 44 45 46
        }
    }

    Component.onCompleted: {
        if (_showDepot){
Valentin Platzgummer's avatar
Valentin Platzgummer committed
47 48
            _addDepotVisual()
            _addDepotDrag()
49
        }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
50 51
        console.assert(map !== undefined, "please set the map property")
        console.assert(geoArea !== undefined, "please set the geoArea property")
52 53 54
    }

    Component.onDestruction: {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
55
        _destroyDepotVisual()
56 57 58 59 60 61
    }

    // Area polygon
    QGCMapPolygonVisuals {
        id:                 mapPolygonVisuals
        mapControl:         map
Valentin Platzgummer's avatar
Valentin Platzgummer committed
62 63 64 65
        mapPolygon:         geoArea
        interactive:        geoArea.interactive
        borderWidth:        2
        borderColor:        "blue"
66 67 68 69 70 71 72 73
        interiorColor:      "blue"
        altColor:           QGroundControl.globalPalette.surveyPolygonTerrainCollision
        interiorOpacity:    _root.opacity
    }

    // Depot Point.
    Component {
        id: depotPointComponent
Valentin Platzgummer's avatar
Valentin Platzgummer committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87

        MapQuickItem {
            coordinate:     _root.geoArea.depot
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
            visible:        true

            sourceItem:
                MissionItemIndexLabel {
                    checked:            geoArea.interactive
                    label:              qsTr("Launch")
                    highlightSelected:  true
                    onClicked:          _root.clicked(0)
                    visible:            true
88
                }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
89 90
        }
    }
91

Valentin Platzgummer's avatar
Valentin Platzgummer committed
92 93 94 95 96 97 98 99
    Component {
        id: depotDragComponent

        MissionItemIndicatorDrag {
            mapControl:     _root.map
            itemIndicator:  _depot
            itemCoordinate: geoArea.depot
            visible:        geoArea.interactive
100

Valentin Platzgummer's avatar
Valentin Platzgummer committed
101 102 103 104 105 106 107 108 109 110
            property var depot: geoArea.depot

            onItemCoordinateChanged: {
                if (itemCoordinate.latitude !== depot.latitude ||
                        itemCoordinate.longitude !== depot.longitude){
                    if (_root.areaItem.containsCoordinate(itemCoordinate)){
                        _root.areaItem.depot = itemCoordinate
                    }
                }
                itemCoordinate = Qt.binding(function(){return _root.geoArea.depot})
111
            }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
112 113 114 115 116 117 118 119 120
        }
    }

    function _addDepotVisual() {
        if (!_depotVisual){
            _depotVisual = depotPointComponent.createObject(_root)
            map.addMapItem(_depotVisual)
        }
    }
121

Valentin Platzgummer's avatar
Valentin Platzgummer committed
122 123 124 125 126
    function _destroyDepotVisual() {
        if (_depotVisual){
            map.removeMapItem(_depotVisual)
            _depotVisual.destroy()
            _depotVisual = undefined
127 128 129
        }
    }

Valentin Platzgummer's avatar
Valentin Platzgummer committed
130 131 132
    function _addDepotDrag() {
        if (!_depotDrag){
            _depotDrag = depotDragComponent.createObject(_root)
133 134 135
        }
    }

Valentin Platzgummer's avatar
Valentin Platzgummer committed
136 137 138 139
    function _destroyDepotDrag() {
        if (_depotDrag){
            _depotDrag.destroy()
            _depotDrag = undefined
140 141 142
        }
    }
}