Skip to content

Commit 0a0d2e9

Browse files
committed
[quick] do not start moving canvas if the drag distance is too small
Often when users want to click (tap) the map, they still move the cursor position a bit. This would trigger unwanted map pan and map refresh afterwards. A configurable minimum drag distance is introduced in order to prevent that.
1 parent 130f3ed commit 0a0d2e9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/quickgui/plugin/qgsquickmapcanvas.qml

+19-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Item {
4747
*/
4848
property alias incrementalRendering: mapCanvasWrapper.incrementalRendering
4949

50+
/**
51+
* What is the minimum distance (in pixels) in order to start dragging map
52+
*/
53+
property real minimumStartDragDistance: 5 * QgsQuick.Utils.dp
54+
5055
signal clicked(var mouse)
5156

5257
/**
@@ -107,6 +112,7 @@ Item {
107112

108113
property point __initialPosition
109114
property point __lastPosition
115+
property bool __dragging: false
110116

111117
anchors.fill: parent
112118

@@ -123,14 +129,15 @@ Item {
123129
var distance = Math.abs(mouse.x - __initialPosition.x) + Math.abs(
124130
mouse.y - __initialPosition.y)
125131

126-
if (distance < 5 * QgsQuick.Utils.dp)
132+
if (distance < minimumStartDragDistance)
127133
mapArea.clicked(mouse)
128134
}
129135
}
130136

131137
onPressed: {
132138
__lastPosition = Qt.point(mouse.x, mouse.y)
133139
__initialPosition = __lastPosition
140+
__dragging = false
134141
freeze('pan')
135142
}
136143

@@ -139,9 +146,17 @@ Item {
139146
}
140147

141148
onPositionChanged: {
142-
var currentPosition = Qt.point(mouse.x, mouse.y)
143-
mapCanvasWrapper.pan(currentPosition, __lastPosition)
144-
__lastPosition = currentPosition
149+
// are we far enough to start dragging map? (we want to avoid tiny map moves)
150+
var distance = Math.abs(mouse.x - __initialPosition.x) + Math.abs(mouse.y - __initialPosition.y)
151+
if (distance >= minimumStartDragDistance)
152+
__dragging = true
153+
154+
if (__dragging)
155+
{
156+
var currentPosition = Qt.point(mouse.x, mouse.y)
157+
mapCanvasWrapper.pan(currentPosition, __lastPosition)
158+
__lastPosition = currentPosition
159+
}
145160
}
146161

147162
onCanceled: {

0 commit comments

Comments
 (0)