From 13d8417c32e40d5f6774a037d053900e38509b2d Mon Sep 17 00:00:00 2001 From: Xen0Xys Date: Fri, 3 May 2024 16:00:44 +0200 Subject: [PATCH] Maybe some WIP again --- js/models/event_handler.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/js/models/event_handler.js b/js/models/event_handler.js index 59725839..8b21d0ff 100644 --- a/js/models/event_handler.js +++ b/js/models/event_handler.js @@ -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 */