From 6652312bc02b11303901b61a19a86e33f744c222 Mon Sep 17 00:00:00 2001 From: Xen0Xys Date: Thu, 25 Apr 2024 12:11:03 +0200 Subject: [PATCH] :construction: Start implementing add_hips function on python and js side --- js/widget.js | 11 ++++++++--- src/ipyaladin/__init__.py | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/js/widget.js b/js/widget.js index 8be72e91..5b71fdff 100644 --- a/js/widget.js +++ b/js/widget.js @@ -222,6 +222,11 @@ function render({ model, el }) { aladin.addOverlay(overlay); overlay.addFootprints(A.footprintsFromSTCS(msg["stc_string"])); break; + case "add_hips": + const id = msg["url"] + " | " + JSON.stringify(msg["options"]); + const hips = A.imageHiPS(id, msg["url"], msg["options"]); + aladin.addNewImageLayer(hips); + break; case "change_colormap": aladin.getBaseImageLayer().setColormap(msg["colormap"]); break; @@ -235,16 +240,16 @@ function render({ model, el }) { let table_bytes = model.get("_table"); let decoder = new TextDecoder("utf-8"); let blob = new Blob([decoder.decode(table_bytes)]); - let url = URL.createObjectURL(blob); + let tableUrl = URL.createObjectURL(blob); A.catalogFromURL( - url, + tableUrl, Object.assign(msg.options, { onClick: "showTable" }), (catalog) => { aladin.addCatalog(catalog); }, false, ); - URL.revokeObjectURL(url); + URL.revokeObjectURL(tableUrl); break; } }); diff --git a/src/ipyaladin/__init__.py b/src/ipyaladin/__init__.py index 6c9fbe99..244417f3 100644 --- a/src/ipyaladin/__init__.py +++ b/src/ipyaladin/__init__.py @@ -265,6 +265,26 @@ def add_moc_from_dict(self, moc_dict, moc_options=None): moc_options = {} self.add_moc(moc_dict, **moc_options) + def add_hips(self, url, **options): + """Add a HiPS survey to the Aladin Lite widget. + + Parameters + ---------- + url : str + Can be an `url` that refers to a HiPS. Or it + can be a "CDS ID" pointing towards a HiPS + options : dict + Options describing the survey + + """ + self.send( + { + "event_name": "add_hips", + "url": url, + "options": options, + } + ) + def add_table(self, table, **table_options): """Load a table into the widget.