From 8c1fc8aaa32e650eb3c6abb4e915aa7b76b17364 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 21 Mar 2017 14:52:16 -0400 Subject: [PATCH 1/2] Update gl3d camera --- src/plots/gl3d/camera.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/plots/gl3d/camera.js b/src/plots/gl3d/camera.js index e97fc8b213a..93d92e5ba08 100644 --- a/src/plots/gl3d/camera.js +++ b/src/plots/gl3d/camera.js @@ -14,6 +14,7 @@ var now = require('right-now'); var createView = require('3d-view'); var mouseChange = require('mouse-change'); var mouseWheel = require('mouse-wheel'); +var mouseOffset = require('mouse-event-offset'); function createCamera(element, options) { element = element || document.body; @@ -179,8 +180,24 @@ function createCamera(element, options) { return false; }); - var lastX = 0, lastY = 0; - mouseChange(element, function(buttons, x, y, mods) { + var lastX = 0, lastY = 0, lastMods = {shift: false, control: false, alt: false, meta: false}; + mouseChange(element, handleInteraction); + + // enable simple touch interactions + element.addEventListener('touchstart', function(ev) { + var xy = mouseOffset(ev.changedTouches[0], element); + handleInteraction(0, xy[0], xy[1], lastMods); + handleInteraction(1, xy[0], xy[1], lastMods); + }); + element.addEventListener('touchmove', function(ev) { + var xy = mouseOffset(ev.changedTouches[0], element); + handleInteraction(1, xy[0], xy[1], lastMods); + }); + element.addEventListener('touchend', function() { + handleInteraction(0, lastX, lastY, lastMods); + }); + + function handleInteraction(buttons, x, y, mods) { var keyBindingMode = camera.keyBindingMode; if(keyBindingMode === false) return; @@ -225,9 +242,10 @@ function createCamera(element, options) { lastX = x; lastY = y; + lastMods = mods; return true; - }); + } mouseWheel(element, function(dx, dy) { if(camera.keyBindingMode === false) return; From 75d313b263bd925f72015a65f10c6019fee69356 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 21 Mar 2017 14:58:54 -0400 Subject: [PATCH 2/2] Add dep --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index deac9910aba..a37fd761f20 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "gl-surface3d": "^1.3.0", "mapbox-gl": "^0.22.0", "mouse-change": "^1.4.0", + "mouse-event-offset": "^3.0.2", "mouse-wheel": "^1.0.2", "ndarray": "^1.0.18", "ndarray-fill": "^1.0.2",