/****************************************************************************
 *
 *   (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

    property var map: undefined        ///< Map control to place item in
    property var geoArea: undefined   ///< GeoArea derived class.

    signal clicked(int sequenceNumber)

    Component.onCompleted: {
        console.assert(map !== undefined, "please set the map property")
        console.assert(geoArea !== undefined, "please set the geoArea property")
    }


    // Area polygon
    QGCMapPolygonVisuals {
        id:                 mapPolygonVisuals
        mapControl:         map
        mapPolygon:         geoArea
        interactive:        geoArea.interactive
        borderWidth:        2
        borderColor:        "blue"
        interiorColor:      "blue"
        altColor:           QGroundControl.globalPalette.surveyPolygonTerrainCollision
        z: 					QGroundControl.zOrderMapItems-1
        interiorOpacity:    0.3
    }

    Item {
        id: depotMapItem

        MapQuickItem {
            id: mapItem


            coordinate:     _root.geoArea.depot
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
            visible:        depotMapItem.visible
            z:		        QGroundControl.zOrderMapItems

            Component.onCompleted: {
                coordinate = Qt.binding(function(){return _root.geoArea.depot})
            }

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

        ItemDragger {
            anchor:  mapItem
            z:				QGroundControl.zOrderMapItems+1
            draggable: _root.geoArea.interactive

            onDragStop:{
                _root.geoArea.depot = mapItem.coordinate
                mapItem.coordinate = Qt.binding(function(){return _root.geoArea.depot})
            }
        }

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