/**************************************************************************** * * (c) 2009-2016 QGROUNDCONTROL PROJECT * * 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 /// Survey Complex Mission Item visuals Item { id: _root property var map: undefined ///< Map control to place item in property var _missionItem: object property bool _editing: _missionItem.editing property var _generator: _missionItem.generator property var _transectsComponent: undefined property var _entryCoordinate: undefined property var _exitCoordinate: undefined property var _generatorVisuals: undefined property bool _isCurrentItem: _missionItem.isCurrentItem signal clicked(int sequenceNumber) on_EditingChanged: { _destroyEntryCoordinate() _destroyExitCoordinate() _destroyTransectsComponent() _destroyGeneratorVisuals() } Component.onCompleted: { _addEntryCoordinate() _addExitCoordinate() _addTransectsComponent() _addGeneratorVisuals() var bbox = boundingBox() _missionItem.areaData.initialize(bbox[0], bbox[1]) console.assert(map != undefined, "please set the map property") } Component.onDestruction: { _destroyEntryCoordinate() _destroyExitCoordinate() _destroyTransectsComponent() _destroyGeneratorVisuals() } on_GeneratorChanged: { _destroyGeneratorVisuals() _addGeneratorVisuals() } // Transect lines Component { id: visualTransectsComponent MapPolyline { property var route: _missionItem.route line.color: "white" line.width: 2 path: route.length > 0 ? route : [] } } // Entry point Component { id: entryPointComponent MapQuickItem { anchorPoint.x: sourceItem.anchorPointX anchorPoint.y: sourceItem.anchorPointY z: QGroundControl.zOrderMapItems coordinate: _missionItem.coordinate visible: _missionItem.exitCoordinate.isValid sourceItem: MissionItemIndexLabel { index: _missionItem.sequenceNumber label: "Entry" checked: _missionItem.isCurrentItem onClicked: _root.clicked(_missionItem.sequenceNumber) } } } // Exit point Component { id: exitPointComponent MapQuickItem { anchorPoint.x: sourceItem.anchorPointX anchorPoint.y: sourceItem.anchorPointY z: QGroundControl.zOrderMapItems coordinate: _missionItem.exitCoordinate visible: _missionItem.exitCoordinate.isValid sourceItem: MissionItemIndexLabel { index: _missionItem.lastSequenceNumber label: "Exit" checked: _missionItem.isCurrentItem onClicked: _root.clicked(_missionItem.sequenceNumber) } } } // GeoAreas Repeater { model: _missionItem.areaData.areaList delegate: GeoAreaVisualLoader { map: _root.map geoArea: object } } // Generator visuals function _addGeneratorVisuals(){ if (_generator.mapVisualQml && !_generatorVisuals) { var component = Qt.createComponent(_generator.mapVisualQml) if (component.status === Component.Error) { console.log("Error loading Qml: ", _generator.mapVisualQml, component.errorString()) } else { _generatorVisuals = component.createObject(_root, { "map": _root.map, "generator": _root._generator, "checked": Qt.binding( function(){ return _root._isCurrentItem }) }) _generatorVisuals.clicked.connect( function(){_root.clicked(_missionItem.sequenceNumber)}) } } } function _destroyGeneratorVisuals(){ if(_generatorVisuals){ _generatorVisuals.destroy() _generatorVisuals = undefined } } function _addTransectsComponent(){ if (!_transectsComponent){ _transectsComponent = visualTransectsComponent.createObject(_root) map.addMapItem(_transectsComponent) } } function _addExitCoordinate(){ if (!_exitCoordinate){ _exitCoordinate = exitPointComponent.createObject(_root) map.addMapItem(_exitCoordinate) } } function _addEntryCoordinate(){ if (!_entryCoordinate){ _entryCoordinate = entryPointComponent.createObject(_root) map.addMapItem(_entryCoordinate) } } function _destroyEntryCoordinate(){ if (_entryCoordinate){ map.removeMapItem(_entryCoordinate) _entryCoordinate.destroy() _entryCoordinate = undefined } } function _destroyExitCoordinate(){ if (_exitCoordinate){ map.removeMapItem(_exitCoordinate) _exitCoordinate.destroy() _exitCoordinate = undefined } } function _destroyTransectsComponent(){ if (_transectsComponent){ map.removeMapItem(_transectsComponent) _transectsComponent.destroy() _transectsComponent = undefined } } function boundingBox() { // Initial polygon is inset to take 2/3rds space var rect = Qt.rect(map.centerViewport.x, map.centerViewport.y, map.centerViewport.width, map.centerViewport.height) rect.x += (rect.width * 0.25) / 2 rect.y += (rect.height * 0.25) / 2 rect.width *= 0.75 rect.height *= 0.75 var centerCoord = map.toCoordinate(Qt.point(rect.x + (rect.width / 2), rect.y + (rect.height / 2)), false /* clipToViewPort */) var topRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y), false /* clipToViewPort */) var bottomLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y + rect.height), false /* clipToViewPort */) var topLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */) var bottomRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */) // Initial polygon has max width and height of 3000 meters var halfWidthMeters = Math.min(topLeftCoord.distanceTo(topRightCoord), 3000) / 2 var halfHeightMeters = Math.min(topLeftCoord.distanceTo(bottomLeftCoord), 3000) / 2 topRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 0) bottomLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 180) return [ bottomLeftCoord, topRightCoord ] } }