Skip to content

Commit 97e764d

Browse files
committed
Add kinetic zoom when using the double tap zoom gesture
1 parent 9d9d53f commit 97e764d

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/qml/MapCanvas.qml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ Item {
305305
dragThreshold: 5
306306

307307
property var oldPos
308-
property real oldTranslationY
308+
property real oldTranslationY: 0
309+
property real activeScale: 1.0
309310

310311
property bool isZooming: false
311312
property bool isPanning: false
@@ -316,8 +317,11 @@ Item {
316317
kineticHandler.stopAll();
317318
if (mainTapHandler.doublePressed) {
318319
oldTranslationY = 0;
320+
activeScale = 1.0;
319321
zoomCenter = centroid.position;
320322
isZooming = true;
323+
kineticHandler.resetZoomSamples();
324+
kineticHandler.addZoomSample(1.0);
321325
freeze('zoom');
322326
} else {
323327
oldPos = centroid.position;
@@ -329,9 +333,10 @@ Item {
329333
} else {
330334
if (isPanning) {
331335
kineticHandler.startPanInertia();
332-
}
333-
if (isZooming || isPanning) {
334-
unfreeze(isZooming ? 'zoom' : 'pan');
336+
unfreeze('pan');
337+
} else if (isZooming) {
338+
kineticHandler.startZoomInertia(centroid.position);
339+
unfreeze('zoom');
335340
}
336341
isZooming = false;
337342
isPanning = false;
@@ -341,6 +346,8 @@ Item {
341346
onCentroidChanged: {
342347
if (active) {
343348
if (isZooming) {
349+
activeScale += (1 - Math.pow(0.8, (translation.y - oldTranslationY) / 60));
350+
kineticHandler.addZoomSample(activeScale);
344351
mapCanvasWrapper.zoomByFactor(zoomCenter, Math.pow(0.8, (translation.y - oldTranslationY) / 60));
345352
oldTranslationY = translation.y;
346353
} else if (isPanning) {
@@ -425,7 +432,8 @@ Item {
425432
dragThreshold: 5
426433

427434
property var oldPos
428-
property real oldTranslationY
435+
property real oldTranslationY: 0.0
436+
property real activeScale: 1.0
429437

430438
property bool isZooming: false
431439
property bool isPanning: false
@@ -438,8 +446,11 @@ Item {
438446
}
439447
if (mainTapHandler.doublePressed) {
440448
oldTranslationY = 0;
449+
activeScale = 1.0;
441450
zoomCenter = centroid.position;
442451
isZooming = true;
452+
kineticHandler.resetZoomSamples();
453+
kineticHandler.addZoomSample(1.0);
443454
freeze('zoom');
444455
} else {
445456
oldPos = centroid.position;
@@ -451,9 +462,10 @@ Item {
451462
} else {
452463
if (isPanning) {
453464
kineticHandler.startPanInertia();
454-
}
455-
if (isZooming || isPanning) {
456-
unfreeze(isZooming ? 'zoom' : 'pan');
465+
unfreeze('pan');
466+
} else if (isZooming) {
467+
kineticHandler.startZoomInertia(centroid.position);
468+
unfreeze('zoom');
457469
}
458470
isZooming = false;
459471
isPanning = false;
@@ -463,6 +475,8 @@ Item {
463475
onCentroidChanged: {
464476
if (active) {
465477
if (isZooming) {
478+
activeScale += (1 - Math.pow(0.8, (translation.y - oldTranslationY) / 60));
479+
kineticHandler.addZoomSample(activeScale);
466480
mapCanvasWrapper.zoomByFactor(zoomCenter, Math.pow(0.8, (translation.y - oldTranslationY) / 60));
467481
oldTranslationY = translation.y;
468482
} else if (isPanning) {

0 commit comments

Comments
 (0)