Commit 81564629 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #4153 from nanthony21/Multicolored_polygon

Multicolored polygon
parents aa956db7 eb751017
...@@ -197,7 +197,8 @@ Map { ...@@ -197,7 +197,8 @@ Map {
property alias drawingPolygon: polygonDrawer.hoverEnabled property alias drawingPolygon: polygonDrawer.hoverEnabled
property bool adjustingPolygon: false property bool adjustingPolygon: false
property bool polygonReady: polygonDrawerPolygon.path.length > 3 ///< true: enough points have been captured to create a closed polygon property bool polygonReady: polygonDrawerPolygonSet.path.length > 2 ///< true: enough points have been captured to create a closed polygon
property bool justClicked: false
property var _callbackObject property var _callbackObject
...@@ -220,8 +221,7 @@ Map { ...@@ -220,8 +221,7 @@ Map {
return false return false
} }
var polygonPath = polygonDrawerPolygon.path var polygonPath = polygonDrawerPolygonSet.path
polygonPath.pop() // get rid of drag coordinate
_cancelCapturePolygon() _cancelCapturePolygon()
polygonDrawer._callbackObject.polygonCaptureFinished(polygonPath) polygonDrawer._callbackObject.polygonCaptureFinished(polygonPath)
return true return true
...@@ -322,10 +322,13 @@ Map { ...@@ -322,10 +322,13 @@ Map {
polygonDrawerNextPoint.path = [ bogusCoord, bogusCoord ] polygonDrawerNextPoint.path = [ bogusCoord, bogusCoord ]
polygonDrawerPolygon.path = [ ] polygonDrawerPolygon.path = [ ]
polygonDrawerNextPoint.path = [ ] polygonDrawerNextPoint.path = [ ]
polygonDrawerPolygonSet.path = [ bogusCoord, bogusCoord ]
polygonDrawerPolygonSet.path = [ ]
} }
onClicked: { onClicked: {
if (mouse.button == Qt.LeftButton) { if (mouse.button == Qt.LeftButton) {
polygonDrawer.justClicked = true
if (polygonDrawerPolygon.path.length > 2) { if (polygonDrawerPolygon.path.length > 2) {
// Make sure the new line doesn't intersect the existing polygon // Make sure the new line doesn't intersect the existing polygon
var lastSegment = polygonDrawerPolygon.path.length - 2 var lastSegment = polygonDrawerPolygon.path.length - 2
...@@ -349,8 +352,7 @@ Map { ...@@ -349,8 +352,7 @@ Map {
// Update finalized coordinate // Update finalized coordinate
polygonPath[polygonDrawerPolygon.path.length - 1] = clickCoordinate polygonPath[polygonDrawerPolygon.path.length - 1] = clickCoordinate
} }
// Add next drag coordinate polygonDrawerPolygonSet.path = polygonPath
polygonPath.push(clickCoordinate)
polygonDrawerPolygon.path = polygonPath polygonDrawerPolygon.path = polygonPath
} else if (polygonDrawer.polygonReady) { } else if (polygonDrawer.polygonReady) {
finishCapturePolygon() finishCapturePolygon()
...@@ -360,14 +362,18 @@ Map { ...@@ -360,14 +362,18 @@ Map {
onPositionChanged: { onPositionChanged: {
if (polygonDrawerPolygon.path.length) { if (polygonDrawerPolygon.path.length) {
var dragCoordinate = _map.toCoordinate(Qt.point(mouse.x, mouse.y)) var dragCoordinate = _map.toCoordinate(Qt.point(mouse.x, mouse.y))
var polygonPath = polygonDrawerPolygon.path
if (polygonDrawer.justClicked){
polygonPath.push(dragCoordinate)
polygonDrawer.justClicked = false
}
// Update drag line // Update drag line
polygonDrawerNextPoint.path = [ polygonDrawerPolygon.path[polygonDrawerPolygon.path.length - 2], dragCoordinate ] polygonDrawerNextPoint.path = [ polygonDrawerPolygon.path[polygonDrawerPolygon.path.length - 2], dragCoordinate ]
// Update drag coordinate
var polygonPath = polygonDrawerPolygon.path
polygonPath[polygonDrawerPolygon.path.length - 1] = dragCoordinate polygonPath[polygonDrawerPolygon.path.length - 1] = dragCoordinate
polygonDrawerPolygon.path = polygonPath polygonDrawerPolygon.path = polygonPath
} }
} }
} }
...@@ -377,14 +383,20 @@ Map { ...@@ -377,14 +383,20 @@ Map {
id: polygonDrawerPolygon id: polygonDrawerPolygon
color: "blue" color: "blue"
opacity: 0.5 opacity: 0.5
visible: polygonDrawer.drawingPolygon visible: polygonDrawerPolygon.path.length > 2
}
MapPolygon {
id: polygonDrawerPolygonSet
color: 'green'
opacity: 0.5
visible: polygonDrawer.polygonReady
} }
/// Next line for polygon /// Next line for polygon
MapPolyline { MapPolyline {
id: polygonDrawerNextPoint id: polygonDrawerNextPoint
line.color: "green" line.color: "green"
line.width: 5 line.width: 3
visible: polygonDrawer.drawingPolygon visible: polygonDrawer.drawingPolygon
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment