From 2740792df3144e205dc84f71dd0db1b04479ead3 Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Sun, 20 Mar 2016 10:04:23 -0400 Subject: [PATCH 1/2] Fix flick gesture with rotation. Fix #869 --- src/viewer.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index d96f81c0..2154a094 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2546,11 +2546,16 @@ function onCanvasDragEnd( event ) { if ( !event.preventDefaultAction && this.viewport ) { gestureSettings = this.gestureSettingsByDeviceType( event.pointerType ); - if ( gestureSettings.flickEnabled && event.speed >= gestureSettings.flickMinSpeed ) { - var amplitudeX = gestureSettings.flickMomentum * ( event.speed * Math.cos( event.direction - (Math.PI / 180 * this.viewport.degrees) ) ), - amplitudeY = gestureSettings.flickMomentum * ( event.speed * Math.sin( event.direction - (Math.PI / 180 * this.viewport.degrees) ) ), - center = this.viewport.pixelFromPoint( this.viewport.getCenter( true ) ), - target = this.viewport.pointFromPixel( new $.Point( center.x - amplitudeX, center.y - amplitudeY ) ); + if (gestureSettings.flickEnabled && + event.speed >= gestureSettings.flickMinSpeed) { + var amplitudeX = gestureSettings.flickMomentum * event.speed * + Math.cos(event.direction); + var amplitudeY = gestureSettings.flickMomentum * event.speed * + Math.sin(event.direction); + var center = this.viewport.pixelFromPoint( + this.viewport.getCenter(true)); + var target = this.viewport.pointFromPixel( + new $.Point(center.x - amplitudeX, center.y - amplitudeY)); if( !this.panHorizontal ) { target.x = center.x; } From 2386900e29d315ef7ee7b350d1b69a23ecf2a8f3 Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Sun, 20 Mar 2016 11:01:26 -0400 Subject: [PATCH 2/2] Fix drag with panHorizontal/panVertical set to false. --- src/viewer.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 2154a094..a74292c0 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2542,27 +2542,25 @@ function onCanvasDrag( event ) { } function onCanvasDragEnd( event ) { - var gestureSettings; - - if ( !event.preventDefaultAction && this.viewport ) { - gestureSettings = this.gestureSettingsByDeviceType( event.pointerType ); + if (!event.preventDefaultAction && this.viewport) { + var gestureSettings = this.gestureSettingsByDeviceType(event.pointerType); if (gestureSettings.flickEnabled && event.speed >= gestureSettings.flickMinSpeed) { - var amplitudeX = gestureSettings.flickMomentum * event.speed * - Math.cos(event.direction); - var amplitudeY = gestureSettings.flickMomentum * event.speed * - Math.sin(event.direction); + var amplitudeX = 0; + if (this.panHorizontal) { + amplitudeX = gestureSettings.flickMomentum * event.speed * + Math.cos(event.direction); + } + var amplitudeY = 0; + if (this.panVertical) { + amplitudeY = gestureSettings.flickMomentum * event.speed * + Math.sin(event.direction); + } var center = this.viewport.pixelFromPoint( this.viewport.getCenter(true)); var target = this.viewport.pointFromPixel( new $.Point(center.x - amplitudeX, center.y - amplitudeY)); - if( !this.panHorizontal ) { - target.x = center.x; - } - if( !this.panVertical ) { - target.y = center.y; - } - this.viewport.panTo( target, false ); + this.viewport.panTo(target, false); } this.viewport.applyConstraints(); } @@ -2581,7 +2579,7 @@ function onCanvasDragEnd( event ) { * @property {Object} originalEvent - The original DOM event. * @property {?Object} userData - Arbitrary subscriber-defined object. */ - this.raiseEvent( 'canvas-drag-end', { + this.raiseEvent('canvas-drag-end', { tracker: event.eventSource, position: event.position, speed: event.speed,