Skip to content

Commit

Permalink
Maybe some WIP again
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed May 3, 2024
1 parent 711b6fc commit 13d8417
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions js/models/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,30 @@ export default class EventHandler {
// is also necessary for the field of view.

/* Target control */
const lock = new Lock();
let preventUpdate = false;
const f1Lock = new Lock();
const f2Lock = new Lock();

// Event triggered when the user moves the map in Aladin Lite
this.aladin.on("positionChanged", () => {
lock.lock();
const raDec = this.aladin.getRaDec();
this.clog(preventUpdate, "positionChanged", `${raDec[0]} ${raDec[1]}`);
this.aladin.on("positionChanged", (position) => {
if (f1Lock.locked) return;
// const raDec = this.aladin.getRaDec();
const raDec = [position.ra, position.dec];
this.clog("positionChanged", `${raDec[0]} ${raDec[1]}`);
this.model.set("_target", `${raDec[0]} ${raDec[1]}`);
if (!preventUpdate) {
this.model.set("shared_target", `${raDec[0]} ${raDec[1]}`);
}
this.model.set("shared_target", `${raDec[0]} ${raDec[1]}`);
this.model.save_changes();
f2Lock.unlock();
});

// Event triggered when the target is changed from the Python side using jslink
this.model.on("change:shared_target", () => {
if (lock.locked) {
lock.unlock();
preventUpdate = false;
this.clog("Unlock change:shared_target");
return;
}
preventUpdate = true;
if (f1Lock.locked) return;
f2Lock.lock();
const target = this.model.get("shared_target");
const [ra, dec] = target.split(" ");
this.clog("change:shared_target", target);
this.aladin.gotoRaDec(ra, dec);
f1Lock.unlock();
});

/* Field of View control */
Expand Down

0 comments on commit 13d8417

Please sign in to comment.