import QtQuick 			2.0
import QGroundControl   1.0
import QtLocation 5.11

Item {
    id: _root

    visible: true

    // Expects the following properties:
    property var map        ///< Map control to place item in
    property var generator
    property bool checked: false


    signal clicked()

    Item {
        id: refPointItem

        property var reference: generator.reference

        onReferenceChanged: {
            if (mapItem.coordinate !== reference){
                mapItem.coordinate = reference
            }
        }

        MapQuickItem {
            id: mapItem


            coordinate:     _root.generator.reference
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
            visible:        refPointItem.visible
            z:		        QGroundControl.zOrderMapItems

            sourceItem:
                MissionItemIndexLabel {
                checked:            true
                label:              qsTr("Reference")
                highlightSelected:  true
                onClicked:          _root.clicked(0)
                visible:            mapItem.visible
                z:				    mapItem.z
            }
        }

        ItemDragger {
            anchor:  mapItem
            z:				QGroundControl.zOrderMapItems+1
            draggable: true

            onDragStop:{
                _root.generator.reference = mapItem.coordinate
            }
        }

        Component.onCompleted: {
            _root.map.addMapItem(mapItem)
        }
    }
}
