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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Item {
*/ */
property alias incrementalRendering: mapCanvasWrapper.incrementalRendering 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) signal clicked(var mouse)


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


property point __initialPosition property point __initialPosition
property point __lastPosition property point __lastPosition
property bool __dragging: false


anchors.fill: parent anchors.fill: parent


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


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


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


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


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

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


onCanceled: { onCanceled: {
Expand Down

0 comments on commit 0a0d2e9

Please sign in to comment.