From 404786278fbc6174d8426d620e800c7c2d594a52 Mon Sep 17 00:00:00 2001 From: mehtaouti Date: Tue, 6 Apr 2021 10:17:38 +0200 Subject: [PATCH 1/2] Enabling pinch with any number of fingers --- src/controls/Drag.js | 4 ++-- src/controls/HammerGestures.js | 12 ++++++++---- src/controls/registerDefaultControls.js | 8 ++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/controls/Drag.js b/src/controls/Drag.js index bbd2b5e50..c6fb15379 100644 --- a/src/controls/Drag.js +++ b/src/controls/Drag.js @@ -60,11 +60,11 @@ function DragControlMethod(element, pointerType, opts) { y: new Dynamics() }; - this._hammer = HammerGestures.get(element, pointerType); + this._hammer = HammerGestures.get(element, pointerType, this._opts.hammerEvent); this._hammer.on("hammer.input", this._handleHammerEvent.bind(this)); - if (this._opts.hammerEvent != 'pan' && this._opts.hammerEvent != 'pinch') { + if (this._opts.hammerEvent != 'pan' && this._opts.hammerEvent != 'pinch' && this._opts.hammerEvent != 'multipinch') { throw new Error(this._opts.hammerEvent + ' is not a hammerEvent managed in DragControlMethod'); } diff --git a/src/controls/HammerGestures.js b/src/controls/HammerGestures.js index 831d82b9e..37b631f65 100644 --- a/src/controls/HammerGestures.js +++ b/src/controls/HammerGestures.js @@ -40,10 +40,10 @@ function HammerGestures() { } -HammerGestures.prototype.get = function(element, type) { +HammerGestures.prototype.get = function(element, type, hammerEvent) { var key = getKeyForElementAndType(element, type); if (!this._managers[key]) { - this._managers[key] = this._createManager(element, type); + this._managers[key] = this._createManager(element, type, hammerEvent); this._refCount[key] = 0; } this._refCount[key]++; @@ -51,7 +51,7 @@ HammerGestures.prototype.get = function(element, type) { }; -HammerGestures.prototype._createManager = function(element, type) { +HammerGestures.prototype._createManager = function(element, type, hammerEvent) { var manager = new Hammer.Manager(element); // Managers are created with different parameters for different pointer @@ -63,7 +63,11 @@ HammerGestures.prototype._createManager = function(element, type) { // On touch one wants to have both panning and pinching. The panning // recognizer needs a threshold to allow the pinch to be recognized. manager.add(new Hammer.Pan({ direction: Hammer.DIRECTION_ALL, threshold: 20, pointers: 1 })); - manager.add(new Hammer.Pinch()); + if (hammerEvent == 'multipinch') { + manager.add(new Hammer.Pinch({event: 'multipinch', pointers: 0, threshold: 0})); + } else { + manager.add(new Hammer.Pinch()); + } } return manager; diff --git a/src/controls/registerDefaultControls.js b/src/controls/registerDefaultControls.js index 9f76a0c11..df9bdd249 100644 --- a/src/controls/registerDefaultControls.js +++ b/src/controls/registerDefaultControls.js @@ -68,7 +68,7 @@ function registerDefaultControls(controls, element, opts) { eKey: new KeyControlMethod(69, 'roll', -0.7, 3) }; - var enabledControls = ['scrollZoom', 'touchView', 'pinch' ]; + var enabledControls = ['scrollZoom', 'touchView', 'pinch', 'rotate' ]; if (opts.scrollZoom !== false) { controlMethods.scrollZoom = new ScrollZoomControlMethod(element); //{ frictionTime: 0 } @@ -83,8 +83,12 @@ function registerDefaultControls(controls, element, opts) { switch (opts.dragMode) { + case 'multipinch': + controlMethods.pinch = new DragControlMethod(element, 'touch', { hammerEvent: 'multipinch' }); + controlMethods.touchView = new DragControlMethod(element, 'touch'); + break; case 'pinch': - controlMethods.pinch = new DragControlMethod(element, 'touch', { hammerEvent: 'pinch' }); + controlMethods.pinch = new DragControlMethod(element, 'touch', { hammerEvent: 'pinch' }); break; case 'pan': controlMethods.touchView = new DragControlMethod(element, 'touch'); From c585ee6bdc058997206da696981569c1bd6920fb Mon Sep 17 00:00:00 2001 From: mehtaouti Date: Tue, 4 May 2021 14:29:56 +0200 Subject: [PATCH 2/2] Forcing code change 4 my fork --- src/controls/Drag.js | 2 +- src/controls/HammerGestures.js | 8 ++++---- src/controls/registerDefaultControls.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/controls/Drag.js b/src/controls/Drag.js index c6fb15379..750b4a73c 100644 --- a/src/controls/Drag.js +++ b/src/controls/Drag.js @@ -64,7 +64,7 @@ function DragControlMethod(element, pointerType, opts) { this._hammer.on("hammer.input", this._handleHammerEvent.bind(this)); - if (this._opts.hammerEvent != 'pan' && this._opts.hammerEvent != 'pinch' && this._opts.hammerEvent != 'multipinch') { + if (this._opts.hammerEvent != 'pan' && this._opts.hammerEvent != 'pinch' && this._opts.hammerEvent != 'multipinch') { throw new Error(this._opts.hammerEvent + ' is not a hammerEvent managed in DragControlMethod'); } diff --git a/src/controls/HammerGestures.js b/src/controls/HammerGestures.js index 37b631f65..a90c868d9 100644 --- a/src/controls/HammerGestures.js +++ b/src/controls/HammerGestures.js @@ -40,10 +40,10 @@ function HammerGestures() { } -HammerGestures.prototype.get = function(element, type, hammerEvent) { +HammerGestures.prototype.get = function(element, type, hammerEvent) { var key = getKeyForElementAndType(element, type); if (!this._managers[key]) { - this._managers[key] = this._createManager(element, type, hammerEvent); + this._managers[key] = this._createManager(element, type, hammerEvent); this._refCount[key] = 0; } this._refCount[key]++; @@ -51,7 +51,7 @@ HammerGestures.prototype.get = function(element, type, hammerEvent) { }; -HammerGestures.prototype._createManager = function(element, type, hammerEvent) { +HammerGestures.prototype._createManager = function(element, type, hammerEvent) { var manager = new Hammer.Manager(element); // Managers are created with different parameters for different pointer @@ -67,7 +67,7 @@ HammerGestures.prototype._createManager = function(element, type, hammerEvent) { manager.add(new Hammer.Pinch({event: 'multipinch', pointers: 0, threshold: 0})); } else { manager.add(new Hammer.Pinch()); - } + } } return manager; diff --git a/src/controls/registerDefaultControls.js b/src/controls/registerDefaultControls.js index df9bdd249..5634afcf4 100644 --- a/src/controls/registerDefaultControls.js +++ b/src/controls/registerDefaultControls.js @@ -68,7 +68,7 @@ function registerDefaultControls(controls, element, opts) { eKey: new KeyControlMethod(69, 'roll', -0.7, 3) }; - var enabledControls = ['scrollZoom', 'touchView', 'pinch', 'rotate' ]; + var enabledControls = ['scrollZoom', 'touchView', 'pinch', 'rotate' ]; if (opts.scrollZoom !== false) { controlMethods.scrollZoom = new ScrollZoomControlMethod(element); //{ frictionTime: 0 } @@ -82,7 +82,7 @@ function registerDefaultControls(controls, element, opts) { }; - switch (opts.dragMode) { + switch (opts.dragMode) { case 'multipinch': controlMethods.pinch = new DragControlMethod(element, 'touch', { hammerEvent: 'multipinch' }); controlMethods.touchView = new DragControlMethod(element, 'touch');