SurveyMapVisual.qml 4.99 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

10 11 12 13
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtLocation       5.3
import QtPositioning    5.3
14

15
import QGroundControl               1.0
16 17 18
import QGroundControl.ScreenTools   1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
19
import QGroundControl.FlightMap     1.0
20 21 22

/// Survey Complex Mission Item visuals
Item {
23 24
    id: _root

25 26
    property var map    ///< Map control to place item in

27
    property var _missionItem:      object
28 29
    property var _mapPolygon:       object.mapPolygon
    property var _gridComponent
30 31
    property var _entryCoordinate
    property var _exitCoordinate
32

33 34
    signal clicked(int sequenceNumber)

35
    function _addVisualElements() {
36
        _gridComponent = gridComponent.createObject(map)
37 38
        _entryCoordinate = entryPointComponent.createObject(map)
        _exitCoordinate = exitPointComponent.createObject(map)
39
        map.addMapItem(_gridComponent)
40 41
        map.addMapItem(_entryCoordinate)
        map.addMapItem(_exitCoordinate)
42 43
    }

44
    function _destroyVisualElements() {
45
        _gridComponent.destroy()
46 47
        _entryCoordinate.destroy()
        _exitCoordinate.destroy()
48 49
    }

50 51
    /// Add an initial 4 sided polygon if there is none
    function _addInitialPolygon() {
52
        if (_mapPolygon.count < 3) {
53
            // Initial polygon is inset to take 2/3rds space
54 55
            var rect = Qt.rect(map.centerViewport.x, map.centerViewport.y, map.centerViewport.width, map.centerViewport.height)
            console.log(map.centerViewport)
56 57 58 59
            rect.x += (rect.width * 0.25) / 2
            rect.y += (rect.height * 0.25) / 2
            rect.width *= 0.75
            rect.height *= 0.75
60
            console.log(map.centerViewport)
61 62 63 64
            var topLeft = Qt.point(rect.x, rect.y)
            var topRight = Qt.point(rect.x + rect.width, rect.y)
            var bottomLeft = Qt.point(rect.x, rect.y + rect.height)
            var bottomRight = Qt.point(rect.x + rect.width, rect.y + rect.height)
65 66 67 68
            _mapPolygon.appendVertex(map.toCoordinate(topLeft, false /* clipToViewPort */))
            _mapPolygon.appendVertex(map.toCoordinate(topRight, false /* clipToViewPort */))
            _mapPolygon.appendVertex(map.toCoordinate(bottomRight, false /* clipToViewPort */))
            _mapPolygon.appendVertex(map.toCoordinate(bottomLeft, false /* clipToViewPort */))
69 70 71 72 73 74 75 76 77 78 79 80
        }
    }

    Component.onCompleted: {
        _addInitialPolygon()
        _addVisualElements()
    }

    Component.onDestruction: {
        _destroyVisualElements()
    }

81 82 83 84
    QGCMapPolygonVisuals {
        id:         mapPolygonVisuals
        mapControl: map
        mapPolygon: _mapPolygon
85

86 87
        Component.onCompleted: {
            mapPolygonVisuals.addVisuals()
88
            if (_missionItem.isCurrentItem) {
89
                mapPolygonVisuals.addHandles()
90 91 92
            }
        }

93 94
        Connections {
            target: _missionItem
95

96 97 98 99 100 101 102
            onIsCurrentItemChanged: {
                if (_missionItem.isCurrentItem) {
                    mapPolygonVisuals.addHandles()
                } else {
                    mapPolygonVisuals.removeHandles()
                }
            }
103 104 105 106 107 108 109 110 111 112
        }
    }

    // Survey grid lines
    Component {
        id: gridComponent

        MapPolyline {
            line.color: "white"
            line.width: 2
113 114 115 116 117 118 119 120 121
            path:       _missionItem.gridPoints
        }
    }

    // Entry point
    Component {
        id: entryPointComponent

        MapQuickItem {
122 123
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
124 125
            z:              QGroundControl.zOrderMapItems
            coordinate:     _missionItem.coordinate
126
            visible:        _missionItem.exitCoordinate.isValid
127

128
            sourceItem: MissionItemIndexLabel {
129
                index:      _missionItem.sequenceNumber
130 131
                label:      "Entry"
                checked:    _missionItem.isCurrentItem
132
                onClicked:  _root.clicked(_missionItem.sequenceNumber)
133 134 135 136 137 138 139 140 141
            }
        }
    }

    // Exit point
    Component {
        id: exitPointComponent

        MapQuickItem {
142 143
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
144 145
            z:              QGroundControl.zOrderMapItems
            coordinate:     _missionItem.exitCoordinate
146
            visible:        _missionItem.exitCoordinate.isValid
147

148
            sourceItem: MissionItemIndexLabel {
149
                index:      _missionItem.lastSequenceNumber
150 151
                label:      "Exit"
                checked:    _missionItem.isCurrentItem
152
                onClicked:  _root.clicked(_missionItem.sequenceNumber)
153
            }
154 155 156
        }
    }
}