Skip to content

Update gl3d camera #1507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 21 additions & 3 deletions src/plots/gl3d/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down