Skip to content

Commit

Permalink
✨ Implement SkyCoord support for js side
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Apr 17, 2024
1 parent 731bf99 commit bc50a28
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,11 @@ function render({ model, el }) {
// the gotoObject call should only happen once. The two booleans prevent the two
// listeners from triggering each other and creating a buggy loop. The same trick
// is also necessary for the field of view.
let target_js = false;
let target_py = false;

aladin.on("positionChanged", (position) => {
if (!target_py) {
target_js = true;
model.set("target", `${position.ra} ${position.dec}`);
model.save_changes();
} else {
target_py = false;
}
});

model.on("change:target", () => {
if (!target_js) {
target_py = true;
let target = model.get("target");
aladin.gotoObject(target);
} else {
target_js = false;
}
const ra_dec = aladin.getRaDec();
model.set("_target", `${ra_dec[0]} ${ra_dec[1]}`);
model.save_changes();
});

/* Field of View control */
Expand Down Expand Up @@ -182,6 +166,15 @@ function render({ model, el }) {
model.on("msg:custom", (msg) => {
let options = {};
switch (msg["event_name"]) {
case "goto_object":
const object = msg["object"];
aladin.gotoObject(object);
break;
case "goto_ra_dec":
const ra = msg["ra"];
const dec = msg["dec"];
aladin.gotoRaDec(ra, dec);
break;
case "add_catalog_from_URL":
aladin.addCatalog(A.catalogFromURL(msg["votable_URL"], msg["options"]));
break;
Expand Down Expand Up @@ -235,7 +228,6 @@ function render({ model, el }) {

return () => {
// need to unsubscribe the listeners
model.off("change:target");
model.off("change:fov");
model.off("change:height");
model.off("change:coo_frame");
Expand Down

0 comments on commit bc50a28

Please sign in to comment.