Skip to content

Commit

Permalink
add zoom heuristic for mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Apr 12, 2024
1 parent 53d44de commit 56cb5c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/js/Aladin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ export let Aladin = (function () {
y2 = (k == 1 || k == 2) ? this.view.height - 1 : 0;

for (var step = 0; step < nbSteps; step++) {
let radec = this.wasm.screenToWorld(x1 + step / nbSteps * (x2 - x1), y1 + step / nbSteps * (y2 - y1));
let radec = this.pix2world(x1 + step / nbSteps * (x2 - x1), y1 + step / nbSteps * (y2 - y1));
points.push(radec);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,9 @@ export let View = (function () {
}

// touch pad defined
view.delta = e.deltaY || e.detail || (-e.wheelDelta);

if (isTouchPad) {
view.delta = e.deltaY || e.detail || (-e.wheelDelta);

if (!view.throttledTouchPadZoom) {
let radec;
view.throttledTouchPadZoom = Utils.throttle(() => {
Expand Down Expand Up @@ -1175,8 +1174,11 @@ export let View = (function () {
} else {
if (!view.throttledMouseScrollZoom) {
view.throttledMouseScrollZoom = Utils.throttle(() => {
let newFov = view.delta > 0 ? view.fov * 1.15 : view.fov / 1.15;
const factor = 5
let newFov = view.delta > 0 ? view.fov * factor : view.fov / factor;
// standard mouse wheel zooming

newFov = Math.max(Math.min(newFov, Zoom.MAX), Zoom.MIN)

view.zoom.apply({
stop: newFov,
Expand Down
13 changes: 3 additions & 10 deletions src/js/Zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ import { requestAnimFrame } from "./libs/RequestAnimationFrame.js";
//stepSize = (desiredZoom - currentZoom) / totalFrames;
interpolatedZoom = Zoom.hermiteCubic.f(self.x, self.x1, self.x2, self.y1, self.y2, self.m1, self.m2);
// Clamp the interpolation in case it is < 0 for a time
if (interpolatedZoom < Zoom.min()) {
interpolatedZoom = Zoom.min();
}
interpolatedZoom = Math.max(Zoom.MIN, interpolatedZoom);

// Apply zoom level to map or perform any necessary rendering
self.view.setZoom(interpolatedZoom);
Expand All @@ -142,13 +140,8 @@ import { requestAnimFrame } from "./libs/RequestAnimationFrame.js";
requestAnimFrame(interpolateFrame);
}

Zoom.max = function() {
return Zoom.LEVELS[0];
}

Zoom.min = function() {
return Zoom.LEVELS[Zoom.LEVELS.length - 1];
}
Zoom.MAX = Zoom.LEVELS[0];
Zoom.MIN = Zoom.LEVELS[Zoom.LEVELS.length - 1];

Zoom.hermiteCubic = {
f: function(x, x1, x2, y1, y2, m1, m2) {
Expand Down

0 comments on commit 56cb5c0

Please sign in to comment.