/**************************************************************************** * * (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.4 import QtLocation 5.3 import QGroundControl 1.0 import QGroundControl.ScreenTools 1.0 import QGroundControl.Controls 1.0 /// Polygon drawing item. Add to your control and call methods to get support for polygon drawing and adjustment. Item { id: _root // These properties must be provided by the consumer property var map ///< Map control property var callbackObject ///< Callback item // These properties can be queried by the consumer property bool drawingPolygon: false property bool adjustingPolygon: false property bool polygonReady: _currentPolygon ? _currentPolygon.path.length > 2 : false ///< true: enough points have been captured to create a closed polygon property var _helpLabel ///< Dynamically added help label component property var _newPolygon ///< Dynamically added polygon which represents all polygon points including the one currently being drawn property var _currentPolygon ///< Dynamically added polygon which represents the currently completed polygon property var _nextPointLine ///< Dynamically added line which goes from last polygon point to the new one being drawn property var _mouseArea ///< Dynamically added MouseArea which handles all clicking and mouse movement property var _vertexDragList: [ ] ///< Dynamically added vertex drag points /// Begin capturing a new polygon /// polygonCaptureStarted will be signalled through callbackObject function startCapturePolygon() { _helpLabel = helpLabelComponent.createObject (map) _newPolygon = newPolygonComponent.createObject (map) _currentPolygon = currentPolygonComponent.createObject(map) _nextPointLine = nextPointComponent.createObject (map) _mouseArea = mouseAreaComponent.createObject (map) map.addMapItem(_newPolygon) map.addMapItem(_currentPolygon) map.addMapItem(_nextPointLine) drawingPolygon = true callbackObject.polygonCaptureStarted() } /// Finish capturing the polygon /// polygonCaptureFinished will be signalled through callbackObject /// @return true: polygon completed, false: not enough points to complete polygon function finishCapturePolygon() { if (!polygonReady) { return false } var polygonPath = _currentPolygon.path _cancelCapturePolygon() callbackObject.polygonCaptureFinished(polygonPath) return true } function startAdjustPolygon(vertexCoordinates) { adjustingPolygon = true for (var i=0; i 2) { // Make sure the new line doesn't intersect the existing polygon var lastSegment = _newPolygon.path.length - 2 var newLineA = map.fromCoordinate(_newPolygon.path[lastSegment], false /* clipToViewPort */) var newLineB = map.fromCoordinate(_newPolygon.path[lastSegment+1], false /* clipToViewPort */) for (var i=0; i 2 } } /// Current complete polygon Component { id: currentPolygonComponent MapPolygon { color: 'green' opacity: 0.5 visible: polygonReady } } /// Next line for polygon Component { id: nextPointComponent MapPolyline { line.color: "green" line.width: 3 } } }