From 56cb5c0dba7ebb5fabdf35940e406582b2e35dd2 Mon Sep 17 00:00:00 2001 From: Matthieu Baumann Date: Fri, 12 Apr 2024 19:12:55 +0200 Subject: [PATCH] add zoom heuristic for mouse --- src/js/Aladin.js | 2 +- src/js/View.js | 8 +++++--- src/js/Zoom.js | 13 +++---------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/js/Aladin.js b/src/js/Aladin.js index 95776900..721660e8 100644 --- a/src/js/Aladin.js +++ b/src/js/Aladin.js @@ -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); } } diff --git a/src/js/View.js b/src/js/View.js index b2da679d..ae579263 100644 --- a/src/js/View.js +++ b/src/js/View.js @@ -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(() => { @@ -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, diff --git a/src/js/Zoom.js b/src/js/Zoom.js index 1222c8e0..b5abaf79 100644 --- a/src/js/Zoom.js +++ b/src/js/Zoom.js @@ -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); @@ -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) {