PlanMapItems.qml 2.91 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/****************************************************************************
 *
 *   (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 associated with the Flight Plan 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 var    masterController    ///< Reference to PlanMasterController for vehicle
25
    property bool   isActiveVehicle     ///< true: vehicle associated with plan is active, false: in-active
Don Gagne's avatar
Don Gagne committed
26 27 28 29 30 31 32 33 34 35 36 37 38

    property var    _map:                       map
    property var    _missionController:         masterController.missionController
    property var    _geoFenceController:        masterController.geoFenceController
    property var    _rallyPointController:      masterController.rallyPointController
    property var    _missionLineViewComponent

    // Add the mission item visuals to the map
    Repeater {
        model: largeMapView ? _missionController.visualItems : 0

        delegate: MissionItemMapVisual {
            map:        _map
39 40 41 42 43 44
            onClicked: {
                if (isActiveVehicle) {
                    // Only active vehicle supports click to change current mission item
                    guidedActionsController.confirmAction(guidedActionsController.actionSetWaypoint, Math.max(object.sequenceNumber, 1))
                }
            }
Don Gagne's avatar
Don Gagne committed
45 46 47
        }
    }

48
    // Waypoint lines
Don Gagne's avatar
Don Gagne committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    Instantiator {
        model: largeMapView ? _missionController.waypointLines : 0

        Item {
            property var _missionLineViewComponent

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

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

    Component {
        id: missionLineViewComponent

        MapPolyline {
            line.width: 3
            line.color: "#be781c"                           // Hack, can't get palette to work in here
            z:          QGroundControl.zOrderWaypointLines
            path:       object ? [ object.coordinate1, object.coordinate2] : undefined

            property var object
        }
    }
}