Skip to content

Commit

Permalink
trigger positionChanged with dragging false when releasing the mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Sep 13, 2024
1 parent 4fe70f0 commit bf72608
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
13 changes: 13 additions & 0 deletions examples/al-init-custom-options.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
}
);

aladin.on("positionChanged", ({ra, dec, dragging}) => {
console.log('position changed dragging: ', dragging)
});

let id;
aladin.on("zoomChanged", () => {
if (id)
clearTimeout(id);
id = setTimeout(() => {
console.log("wheel stopped, new cone search here")
}, 500);
})

//aladin.removeHiPSFromFavorites('CDS/P/allWISE/color')
});
</script>
Expand Down
19 changes: 8 additions & 11 deletions src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export let View = (function () {
this.aladinDiv.ondragover = Utils.dragOverHandler;

this.throttledPositionChanged = Utils.throttle(
() => {
(dragging) => {
var posChangedFn = this.aladin.callbacksByEventName && this.aladin.callbacksByEventName['positionChanged'];
if (typeof posChangedFn === 'function') {
var pos = this.aladin.pix2world(this.width / 2, this.height / 2, 'icrs');
Expand All @@ -135,7 +135,7 @@ export let View = (function () {
posChangedFn({
ra: pos[0],
dec: pos[1],
dragging: true
dragging: dragging
});
} catch(e) {
console.error(e)
Expand Down Expand Up @@ -841,6 +841,9 @@ export let View = (function () {

if (wasDragging) {
view.realDragging = false;

// call the positionChanged once more with a dragging = false
view.throttledPositionChanged(false);
}
} // end of "if (view.dragging) ... "

Expand Down Expand Up @@ -1009,11 +1012,6 @@ export let View = (function () {
view.updateObjectsLookup();
}

/*if (!view.dragging || Utils.hasTouchScreen()) {
// update location box
view.updateLocation({mouseX: xymouse.x, mouseY: xymouse.y});
}*/

if (!view.dragging && !view.moving && view.mode === View.PAN) {
// call listener of 'mouseMove' event
var onMouseMoveFunction = view.aladin.callbacksByEventName['mouseMove'];
Expand Down Expand Up @@ -1127,7 +1125,7 @@ export let View = (function () {
ALEvent.POSITION_CHANGED.dispatchedTo(view.aladin.aladinDiv, view.viewCenter);

// Apply position changed callback after the move
view.throttledPositionChanged();
view.throttledPositionChanged(true);
}
}); //// endof mousemove ////

Expand All @@ -1150,7 +1148,6 @@ export let View = (function () {
view.zoom.stopAnimation();
}, 100);


const xymouse = Utils.relMouseCoords(e);
view.xy = xymouse
ALEvent.CANVAS_EVENT.dispatchedTo(view.aladinDiv, {
Expand Down Expand Up @@ -1307,7 +1304,7 @@ export let View = (function () {
// inertia run throttled position
if (this.moving && this.aladin.callbacksByEventName && this.aladin.callbacksByEventName['positionChanged'] && this.wasm.isInerting()) {
// run the trottled position
this.throttledPositionChanged();
this.throttledPositionChanged(false);
}

////// 2. Draw catalogues////////
Expand Down Expand Up @@ -2020,7 +2017,7 @@ export let View = (function () {
var self = this;
setTimeout(function () { self.refreshProgressiveCats(); }, 1000);
// Apply position changed callback after the move
self.throttledPositionChanged();
self.throttledPositionChanged(false);

// hide the popup if it is open
this.aladin.hidePopup();
Expand Down

0 comments on commit bf72608

Please sign in to comment.