Skip to content

Commit

Permalink
[quick] do not start moving canvas if the drag distance is too small
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wonder-sk committed Feb 22, 2019
1 parent 130f3ed commit 0a0d2e9
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/quickgui/plugin/qgsquickmapcanvas.qml
Expand Up @@ -47,6 +47,11 @@ Item {
*/
property alias incrementalRendering: mapCanvasWrapper.incrementalRendering

/**
* What is the minimum distance (in pixels) in order to start dragging map
*/
property real minimumStartDragDistance: 5 * QgsQuick.Utils.dp

signal clicked(var mouse)

/**
Expand Down Expand Up @@ -107,6 +112,7 @@ Item {

property point __initialPosition
property point __lastPosition
property bool __dragging: false

anchors.fill: parent

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

if (distance < 5 * QgsQuick.Utils.dp)
if (distance < minimumStartDragDistance)
mapArea.clicked(mouse)
}
}

onPressed: {
__lastPosition = Qt.point(mouse.x, mouse.y)
__initialPosition = __lastPosition
__dragging = false
freeze('pan')
}

Expand All @@ -139,9 +146,17 @@ Item {
}

onPositionChanged: {
var currentPosition = Qt.point(mouse.x, mouse.y)
mapCanvasWrapper.pan(currentPosition, __lastPosition)
__lastPosition = currentPosition
// are we far enough to start dragging map? (we want to avoid tiny map moves)
var distance = Math.abs(mouse.x - __initialPosition.x) + Math.abs(mouse.y - __initialPosition.y)
if (distance >= minimumStartDragDistance)
__dragging = true

if (__dragging)
{
var currentPosition = Qt.point(mouse.x, mouse.y)
mapCanvasWrapper.pan(currentPosition, __lastPosition)
__lastPosition = currentPosition
}
}

onCanceled: {
Expand Down

0 comments on commit 0a0d2e9

Please sign in to comment.