|
|
|
@ -137,11 +137,11 @@ Map {
@@ -137,11 +137,11 @@ Map {
|
|
|
|
|
// Connections { |
|
|
|
|
// target: map.polygonDraw |
|
|
|
|
// |
|
|
|
|
// onPolygonStarted: { |
|
|
|
|
// onPolygonCaptureStarted: { |
|
|
|
|
// // Polygon creation has started |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// onPolygonFinished: { |
|
|
|
|
// onPolygonCaptureFinished: { |
|
|
|
|
// // Polygon capture complete, coordinates signal variable contains the polygon points |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
@ -161,6 +161,30 @@ Map {
@@ -161,6 +161,30 @@ Map {
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter |
|
|
|
|
text: qsTr("Click to add point %1").arg(ScreenTools.isMobile || !polygonDrawer.polygonReady ? "" : qsTr("- Right Click to end polygon")) |
|
|
|
|
visible: polygonDrawer.drawingPolygon |
|
|
|
|
|
|
|
|
|
Connections { |
|
|
|
|
target: polygonDrawer |
|
|
|
|
|
|
|
|
|
onDrawingPolygonChanged: { |
|
|
|
|
if (polygonDrawer.drawingPolygon) { |
|
|
|
|
polygonHelp.text = qsTr("Click to add point") |
|
|
|
|
} |
|
|
|
|
polygonHelp.visible = polygonDrawer.drawingPolygon |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onPolygonReadyChanged: { |
|
|
|
|
if (polygonDrawer.polygonReady && !ScreenTools.isMobile) { |
|
|
|
|
polygonHelp.text = qsTr("Click to add point - Right Click to end polygon") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onAdjustingPolygonChanged: { |
|
|
|
|
if (polygonDrawer.adjustingPolygon) { |
|
|
|
|
polygonHelp.text = qsTr("Adjust polygon by dragging corners") |
|
|
|
|
} |
|
|
|
|
polygonHelp.visible = polygonDrawer.adjustingPolygon |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MouseArea { |
|
|
|
@ -170,28 +194,40 @@ Map {
@@ -170,28 +194,40 @@ Map {
|
|
|
|
|
visible: drawingPolygon |
|
|
|
|
z: 1000 // Hack to fix MouseArea layering for now |
|
|
|
|
|
|
|
|
|
property alias drawingPolygon: polygonDrawer.hoverEnabled |
|
|
|
|
property bool polygonReady: polygonDrawerPolygon.path.length > 3 ///< true: enough points have been captured to create a closed polygon |
|
|
|
|
property alias drawingPolygon: polygonDrawer.hoverEnabled |
|
|
|
|
property bool adjustingPolygon: false |
|
|
|
|
property bool polygonReady: polygonDrawerPolygon.path.length > 3 ///< true: enough points have been captured to create a closed polygon |
|
|
|
|
|
|
|
|
|
/// New polygon capture has started |
|
|
|
|
signal polygonStarted |
|
|
|
|
signal polygonCaptureStarted |
|
|
|
|
|
|
|
|
|
/// Polygon capture is complete |
|
|
|
|
/// @param coordinates Map coordinates for the polygon points |
|
|
|
|
signal polygonFinished(var coordinates) |
|
|
|
|
signal polygonCaptureFinished(var coordinates) |
|
|
|
|
|
|
|
|
|
/// Polygon adjustment has begun |
|
|
|
|
signal polygonAdjustStarted |
|
|
|
|
|
|
|
|
|
/// Polygon Vertex coordinate has been adjusted |
|
|
|
|
signal polygonAdjustVertex(int vertexIndex, var vertexCoordinate) |
|
|
|
|
|
|
|
|
|
/// Polygon adjustment finished |
|
|
|
|
signal polygonAdjustFinished |
|
|
|
|
|
|
|
|
|
property var _vertexDragList: [] |
|
|
|
|
|
|
|
|
|
/// Begin capturing a new polygon |
|
|
|
|
/// polygonStarted will be signalled |
|
|
|
|
function startPolygon() { |
|
|
|
|
/// polygonCaptureStarted will be signalled |
|
|
|
|
function startCapturePolygon() { |
|
|
|
|
polygonDrawer.drawingPolygon = true |
|
|
|
|
polygonDrawer._clearPolygon() |
|
|
|
|
polygonDrawer.polygonStarted() |
|
|
|
|
polygonDrawer.polygonCaptureStarted() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Finish capturing the polygon |
|
|
|
|
/// polygonFinished will be signalled |
|
|
|
|
/// polygonCaptureFinished will be signalled |
|
|
|
|
/// @return true: polygon completed, false: not enough points to complete polygon |
|
|
|
|
function finishPolygon() { |
|
|
|
|
function finishCapturePolygon() { |
|
|
|
|
if (!polygonDrawer.polygonReady) { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
@ -200,10 +236,82 @@ Map {
@@ -200,10 +236,82 @@ Map {
|
|
|
|
|
polygonPath.pop() // get rid of drag coordinate |
|
|
|
|
polygonDrawer._clearPolygon() |
|
|
|
|
polygonDrawer.drawingPolygon = false |
|
|
|
|
polygonDrawer.polygonFinished(polygonPath) |
|
|
|
|
polygonDrawer.polygonCaptureFinished(polygonPath) |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function startAdjustPolygon(vertexCoordinates) { |
|
|
|
|
polygonDrawer.adjustingPolygon = true |
|
|
|
|
for (var i=0; i<vertexCoordinates.length; i++) { |
|
|
|
|
var mapItem = Qt.createQmlObject( |
|
|
|
|
"import QtQuick 2.5; " + |
|
|
|
|
"import QtLocation 5.3; " + |
|
|
|
|
"import QGroundControl.ScreenTools 1.0; " + |
|
|
|
|
"Rectangle {" + |
|
|
|
|
" id: vertexDrag; " + |
|
|
|
|
" width: _sideLength; " + |
|
|
|
|
" height: _sideLength; " + |
|
|
|
|
" color: 'red'; " + |
|
|
|
|
"" + |
|
|
|
|
" property var coordinate; " + |
|
|
|
|
" property int index; " + |
|
|
|
|
"" + |
|
|
|
|
" readonly property real _sideLength: ScreenTools.defaultFontPixelWidth * 2; " + |
|
|
|
|
" readonly property real _halfSideLength: _sideLength / 2; " + |
|
|
|
|
"" + |
|
|
|
|
" Drag.active: dragMouseArea.drag.active; " + |
|
|
|
|
" Drag.hotSpot.x: _halfSideLength; " + |
|
|
|
|
" Drag.hotSpot.y: _halfSideLength; " + |
|
|
|
|
"" + |
|
|
|
|
" onXChanged: updateCoordinate(); " + |
|
|
|
|
" onYChanged: updateCoordinate(); " + |
|
|
|
|
"" + |
|
|
|
|
" function updateCoordinate() { " + |
|
|
|
|
" vertexDrag.coordinate = _map.toCoordinate(Qt.point(vertexDrag.x + _halfSideLength, vertexDrag.y + _halfSideLength), false); " + |
|
|
|
|
" polygonDrawer.polygonAdjustVertex(vertexDrag.index, vertexDrag.coordinate); " + |
|
|
|
|
" } " + |
|
|
|
|
"" + |
|
|
|
|
" function updatePosition() { " + |
|
|
|
|
" var vertexPoint = _map.fromCoordinate(coordinate, false); " + |
|
|
|
|
" vertexDrag.x = vertexPoint.x - _halfSideLength; " + |
|
|
|
|
" vertexDrag.y = vertexPoint.y - _halfSideLength; " + |
|
|
|
|
" } " + |
|
|
|
|
"" + |
|
|
|
|
" Connections { " + |
|
|
|
|
" target: _map; " + |
|
|
|
|
" onCenterChanged: updatePosition(); " + |
|
|
|
|
" onZoomLevelChanged: updatePosition(); " + |
|
|
|
|
" } " + |
|
|
|
|
"" + |
|
|
|
|
" MouseArea { " + |
|
|
|
|
" id: dragMouseArea; " + |
|
|
|
|
" anchors.fill: parent; " + |
|
|
|
|
" drag.target: parent; " + |
|
|
|
|
" drag.minimumX: 0; " + |
|
|
|
|
" drag.minimumY: 0; " + |
|
|
|
|
" drag.maximumX: _map.width - parent.width; " + |
|
|
|
|
" drag.maximumY: _map.height - parent.height; " + |
|
|
|
|
" } " + |
|
|
|
|
"} ", |
|
|
|
|
_map) |
|
|
|
|
mapItem.z = QGroundControl.zOrderMapItems + 1 |
|
|
|
|
mapItem.coordinate = vertexCoordinates[i] |
|
|
|
|
mapItem.index = i |
|
|
|
|
mapItem.updatePosition() |
|
|
|
|
polygonDrawer._vertexDragList.push(mapItem) |
|
|
|
|
polygonDrawer.polygonAdjustStarted() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function finishAdjustPolygon() { |
|
|
|
|
polygonDrawer.adjustingPolygon = false |
|
|
|
|
for (var i=0; i<polygonDrawer._vertexDragList.length; i++) { |
|
|
|
|
polygonDrawer._vertexDragList[i].destroy() |
|
|
|
|
} |
|
|
|
|
polygonDrawer._vertexDragList = [] |
|
|
|
|
polygonDrawer.polygonAdjustFinished() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function _clearPolygon() { |
|
|
|
|
// Simpler methods to clear the path simply don't work due to bugs. This craziness does. |
|
|
|
|
var bogusCoord = _map.toCoordinate(Qt.point(height/2, width/2)) |
|
|
|
@ -242,7 +350,7 @@ Map {
@@ -242,7 +350,7 @@ Map {
|
|
|
|
|
polygonPath.push(clickCoordinate) |
|
|
|
|
polygonDrawerPolygon.path = polygonPath |
|
|
|
|
} else if (polygonDrawer.polygonReady) { |
|
|
|
|
finishPolygon() |
|
|
|
|
finishCapturePolygon() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -261,6 +369,7 @@ Map {
@@ -261,6 +369,7 @@ Map {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Polygon being drawn |
|
|
|
|
MapPolygon { |
|
|
|
|
id: polygonDrawerPolygon |
|
|
|
|
color: "blue" |
|
|
|
@ -268,6 +377,7 @@ Map {
@@ -268,6 +377,7 @@ Map {
|
|
|
|
|
visible: polygonDrawer.drawingPolygon |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Next line for polygon |
|
|
|
|
MapPolyline { |
|
|
|
|
id: polygonDrawerNextPoint |
|
|
|
|
line.color: "green" |
|
|
|
|