Skip to content
Permalink
Browse files

[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.
  • Loading branch information
wonder-sk committed Feb 22, 2019
1 parent 130f3ed commit 0a0d2e995f8748d6d7c1c734b228a31dd1259eff
Showing with 19 additions and 4 deletions.
  1. +19 −4 src/quickgui/plugin/qgsquickmapcanvas.qml
@@ -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)

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

property point __initialPosition
property point __lastPosition
property bool __dragging: false

anchors.fill: parent

@@ -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')
}

@@ -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: {

0 comments on commit 0a0d2e9

Please sign in to comment.
You can’t perform that action at this time.