@ -197,7 +197,8 @@ Map {
@@ -197,7 +197,8 @@ Map {
property alias drawingPolygon: polygonDrawer . hoverEnabled
property bool adjustingPolygon: false
property bool polygonReady: polygonDrawerPolygon . path . length > 3 / / / < t r u e : e n o u g h p o i n t s h a v e b e e n c a p t u r e d t o c r e a t e a c l o s e d p o l y g o n
property bool polygonReady: polygonDrawerPolygonSet . path . length > 2 / / / < t r u e : e n o u g h p o i n t s h a v e b e e n c a p t u r e d t o c r e a t e a c l o s e d p o l y g o n
property bool justClicked: false
property var _callbackObject
@ -220,8 +221,7 @@ Map {
@@ -220,8 +221,7 @@ Map {
return false
}
var polygonPath = polygonDrawerPolygon . path
polygonPath . pop ( ) / / g e t r i d o f d r a g c o o r d i n a t e
var polygonPath = polygonDrawerPolygonSet . path
_cancelCapturePolygon ( )
polygonDrawer . _callbackObject . polygonCaptureFinished ( polygonPath )
return true
@ -322,10 +322,13 @@ Map {
@@ -322,10 +322,13 @@ Map {
polygonDrawerNextPoint . path = [ bogusCoord , bogusCoord ]
polygonDrawerPolygon . path = [ ]
polygonDrawerNextPoint . path = [ ]
polygonDrawerPolygonSet . path = [ bogusCoord , bogusCoord ]
polygonDrawerPolygonSet . path = [ ]
}
onClicked: {
if ( mouse . button == Qt . LeftButton ) {
polygonDrawer . justClicked = true
if ( polygonDrawerPolygon . path . length > 2 ) {
/ / M a k e s u r e t h e n e w l i n e d o e s n ' t i n t e r s e c t t h e e x i s t i n g p o l y g o n
var lastSegment = polygonDrawerPolygon . path . length - 2
@ -342,15 +345,14 @@ Map {
@@ -342,15 +345,14 @@ Map {
var clickCoordinate = _map . toCoordinate ( Qt . point ( mouse . x , mouse . y ) )
var polygonPath = polygonDrawerPolygon . path
if ( polygonPath . length == 0 ) {
if ( polygonPath . length == 0 ) {
/ / A d d f i r s t c o o r d i n a t e
polygonPath . push ( clickCoordinate )
} else {
/ / U p d a t e f i n a l i z e d c o o r d i n a t e
polygonPath [ polygonDrawerPolygon . path . length - 1 ] = clickCoordinate
}
/ / A d d n e x t d r a g c o o r d i n a t e
polygonPath . push ( clickCoordinate )
polygonDrawerPolygonSet . path = polygonPath
polygonDrawerPolygon . path = polygonPath
} else if ( polygonDrawer . polygonReady ) {
finishCapturePolygon ( )
@ -360,16 +362,20 @@ Map {
@@ -360,16 +362,20 @@ Map {
onPositionChanged: {
if ( polygonDrawerPolygon . path . length ) {
var dragCoordinate = _map . toCoordinate ( Qt . point ( mouse . x , mouse . y ) )
var polygonPath = polygonDrawerPolygon . path
if ( polygonDrawer . justClicked ) {
polygonPath . push ( dragCoordinate )
polygonDrawer . justClicked = false
}
/ / U p d a t e d r a g l i n e
polygonDrawerNextPoint . path = [ polygonDrawerPolygon . path [ polygonDrawerPolygon . path . length - 2 ] , dragCoordinate ]
/ / U p d a t e d r a g c o o r d i n a t e
var polygonPath = polygonDrawerPolygon . path
polygonPath [ polygonDrawerPolygon . path . length - 1 ] = dragCoordinate
if ( polygonDrawerPolygon . path . length > 2 ) {
polygonDrawerPolygon . path = polygonPath
}
polygonDrawerPolygon . path = polygonPath
}
}
}
@ -379,14 +385,20 @@ Map {
@@ -379,14 +385,20 @@ Map {
id: polygonDrawerPolygon
color: "blue"
opacity: 0.5
visible: polygonDrawer . drawingPolygon
visible: polygonDrawerPolygon . path . length > 2
}
MapPolygon {
id: polygonDrawerPolygonSet
color: 'green'
opacity: 0.5
visible: polygonDrawer . polygonReady
}
/ / / N e x t l i n e f o r p o l y g o n
MapPolyline {
id: polygonDrawerNextPoint
line.color: "green"
line.width: 5
line.width: 3
visible: polygonDrawer . drawingPolygon
}