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

21
/// GeoFence map visuals
22 23 24 25 26 27 28 29 30
Item {
    z: QGroundControl.zOrderMapItems

    property var    map
    property var    myGeoFenceController
    property bool   interactive:            false   ///< true: user can interact with items
    property bool   planView:               false   ///< true: visuals showing in plan view
    property var    homePosition

31 32 33 34 35 36 37 38 39 40
    property var    _breachReturnPointComponent
    property var    _mouseAreaComponent
    property var    _circleComponent
    property var    _mapPolygon:                    myGeoFenceController.mapPolygon
    property bool   _interactive:                   interactive
    property bool   _circleSupported:               myGeoFenceController.circleRadiusFact !== null
    property bool   _circleEnabled:                 myGeoFenceController.circleEnabled
    property real   _circleRadius:                  _circleSupported ? myGeoFenceController.circleRadiusFact.rawValue : 0
    property bool   _polygonSupported:              myGeoFenceController.polygonSupported
    property bool   _polygonEnabled:                myGeoFenceController.polygonEnabled
41

42
    Component.onCompleted: {
43 44 45 46 47 48 49
        _circleComponent = circleComponent.createObject(map)
        map.addMapItem(_circleComponent)
        _breachReturnPointComponent = breachReturnPointComponent.createObject(map)
        map.addMapItem(_breachReturnPointComponent)
        _mouseAreaComponent = mouseAreaComponent.createObject(map)
    }

50
    Component.onDestruction: {
51 52 53 54 55 56
        _circleComponent.destroy()
        _breachReturnPointComponent.destroy()
        _mouseAreaComponent.destroy()
    }

    Connections {
57 58
        target:                     myGeoFenceController
        onAddInitialFencePolygon:   mapPolygonVisuals.addInitialPolygon()
59 60 61 62 63 64 65 66 67 68 69 70 71
    }

    // Mouse area to capture breach return point coordinate
    Component {
        id: mouseAreaComponent

        MouseArea {
            anchors.fill:   map
            visible:        interactive
            onClicked:      myGeoFenceController.breachReturnPoint = map.toCoordinate(Qt.point(mouse.x, mouse.y), false /* clipToViewPort */)
        }
    }

72 73 74 75 76 77 78 79
    QGCMapPolygonVisuals {
        id:             mapPolygonVisuals
        mapControl:     map
        mapPolygon:     _mapPolygon
        interactive:    _interactive
        borderWidth:    2
        borderColor:    "orange"
        visible:        _polygonSupported && (planView || _polygonEnabled)
80 81 82 83 84 85 86 87 88 89 90
    }

    // GeoFence circle
    Component {
        id: circleComponent

        MapCircle {
            z:              QGroundControl.zOrderMapItems
            border.width:   2
            border.color:   "orange"
            color:          "transparent"
91
            center:         homePosition ? homePosition : QtPositioning.coordinate()
92 93
            radius:         _circleRadius
            visible:        _circleSupported && _circleRadius > 0 && (planView || _circleEnabled)
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
        }
    }

    // Breach return point
    Component {
        id: breachReturnPointComponent

        MapQuickItem {
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
            z:              QGroundControl.zOrderMapItems
            coordinate:     myGeoFenceController.breachReturnPoint

            sourceItem: MissionItemIndexLabel {
                label: "B"
            }
        }
    }
}