/****************************************************************************
 *
 *   (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 QtLocation       5.3
import QtPositioning    5.3

import QGroundControl           1.0
import QGroundControl.Controls  1.0
import QGroundControl.FlightMap 1.0

// Adds visual items generated by wima planer to the map.
Item {
    id: _root

    property var        map                 ///< Map control to show items on
    property bool       largeMapView        ///< true: map takes up entire view, false: map is in small window
    property string     color: "green"      // Mission Items Color
    property var        missionItems
    property var        path
    property var        zOrderWP
    property var        zOrderLines

    property var    _map: map
    property var    _missionLineViewComponent

    property bool showItems:        true

    Component {
        id: missionLineViewComponent

        MapPolyline {
            line.width: 3
            line.color: showItems ? _root.color : "transparent"
            path:       _root.path
            z:          _root.zOrderLines
        }
    }

    Repeater {
        model: largeMapView ? ( showItems ? missionItems : 0) : 0

        delegate: WimaMissionItemMapVisual {
            map:        _map
            color:     _root.color
            zOrder:    _root.zOrderWP
            visible:   _root.visible
        }
    }

    Component.onCompleted: {
        _missionLineViewComponent = missionLineViewComponent.createObject(map)
        if (_missionLineViewComponent.status === Component.Error)
            console.log(_missionLineViewComponent.errorString())
        map.addMapItem(_missionLineViewComponent)
    }

    Component.onDestruction: {
        _missionLineViewComponent.destroy()
    }
}
