From 2fe554be22a936f671e21b010996da772c4b8b16 Mon Sep 17 00:00:00 2001 From: Matthieu Baumann Date: Wed, 28 Feb 2024 16:05:31 +0100 Subject: [PATCH] simbad cone search requesting https://simbad.cds.unistra.fr/cone --- examples/al-displayJPG.html | 4 ++- examples/al-easy-access-simbad-ned.html | 4 ++- src/js/A.js | 41 +++++++++++++++++++++++-- src/js/URLBuilder.js | 19 +++++++----- src/js/gui/Box/CatalogQueryBox.js | 12 ++++++++ 5 files changed, 69 insertions(+), 11 deletions(-) diff --git a/examples/al-displayJPG.html b/examples/al-displayJPG.html index 5687ac13..265c5dc7 100644 --- a/examples/al-displayJPG.html +++ b/examples/al-displayJPG.html @@ -23,7 +23,9 @@ Image Opacity:
{ + aladin.addCatalog(cat) + }); // we must return true, so that the default action (set view to center of image) is performed return true; } diff --git a/examples/al-easy-access-simbad-ned.html b/examples/al-easy-access-simbad-ned.html index 58763704..64340aa2 100644 --- a/examples/al-easy-access-simbad-ned.html +++ b/examples/al-easy-access-simbad-ned.html @@ -29,7 +29,9 @@ samp: true, }); - aladin.addCatalog(A.catalogFromSimbad('09 55 52.4 +69 40 47', 0.1, {onClick: 'showTable', limit: 1000})); + A.catalogFromSimbad('09 55 52.4 +69 40 47', 0.1, {onClick: 'showTable', limit: 1000}, (cat) => { + aladin.addCatalog(cat) + }); aladin.addCatalog(A.catalogFromNED('09 55 52.4 +69 40 47', 0.1, {onClick: 'showPopup', shape: 'plus'})); }); diff --git a/src/js/A.js b/src/js/A.js index 57aaaf3c..43fbf71d 100644 --- a/src/js/A.js +++ b/src/js/A.js @@ -368,8 +368,45 @@ A.catalogFromSimbad = function (target, radius, options, successCallback, errorC if (!('name' in options)) { options['name'] = 'Simbad'; } - var url = URLBuilder.buildSimbadCSURL(target, radius); - return A.catalogFromURL(url, options, successCallback, errorCallback, false); + + return new Promise((resolve, reject) => { + let coo; + if (target && (typeof target === "object")) { + if ('ra' in target && 'dec' in target) { + coo = new Coo(target.ra, target.dec, 7); + resolve(coo) + } + } else { + var isObjectName = /[a-zA-Z]/.test(target); + + // Try to parse as a position + if (!isObjectName) { + coo = new Coo(); + coo.parse(target); + resolve(coo); + } else { + // object name, use sesame + Sesame.resolve(target, + function (data) { // success callback + // Location given in icrs at J2000 + coo = new Coo(data.coo.jradeg, data.coo.jdedeg); + resolve(coo) + }, + function (data) { // errror callback + if (console) { + console.log("Could not resolve object name " + target); + console.log(data); + } + + reject(data) + } + ); + } + } + }).then((coo) => { + const url = URLBuilder.buildSimbadCSURL(coo.lon, coo.lat, radius, options) + return A.catalogFromURL(url, options, successCallback, errorCallback, false); + }) }; // API diff --git a/src/js/URLBuilder.js b/src/js/URLBuilder.js index abbd4172..15ecb4b5 100644 --- a/src/js/URLBuilder.js +++ b/src/js/URLBuilder.js @@ -29,17 +29,22 @@ *****************************************************************************/ import { Coo } from './libs/astro/coo.js'; import { Utils } from './Utils'; +import { Sesame } from './Sesame.js'; + export let URLBuilder = (function() { let URLBuilder = { - buildSimbadCSURL: function(target, radiusDegrees) { - if (target && (typeof target === "object")) { - if ('ra' in target && 'dec' in target) { - var coo = new Coo(target.ra, target.dec, 7); - target = coo.format('s'); - } + buildSimbadCSURL: function(ra, dec, radiusDegrees, options) { + let url = 'https://simbad.cds.unistra.fr/cone?RA=' + ra + '&DEC=' + dec + '&SR=' + radiusDegrees + '&RESPONSEFORMAT=votable'; + + if (options && options.limit) { + url += '&MAXREC=' + options.limit; } - return 'https://alasky.unistra.fr/cgi/simbad-flat/simbad-cs.py?target=' + encodeURIComponent(target) + '&SR=' + radiusDegrees + '&format=votable&SRUNIT=deg&SORTBY=nbref'; + + const orderBy = options && options.orderBy || 'nb_ref'; + url += '&ORDER_BY=' + orderBy; + + return url; }, buildNEDPositionCSURL: function(ra, dec, radiusDegrees) { diff --git a/src/js/gui/Box/CatalogQueryBox.js b/src/js/gui/Box/CatalogQueryBox.js index 9256106e..e3a62a14 100644 --- a/src/js/gui/Box/CatalogQueryBox.js +++ b/src/js/gui/Box/CatalogQueryBox.js @@ -65,7 +65,19 @@ import { CtxMenuActionButtonOpener } from "../Button/CtxMenuOpener.js"; errorCallback ); } + else if (params.baseURL.includes('/simbad.')) { + A.catalogFromSimbad( + params.ra + ' ' + params.dec, + params.radiusDeg, + {limit: params.limit, onClick: 'showTable'}, + (catalog) => { + aladin.addCatalog(catalog) + }, + errorCallback + ); + } else { + console.log('cone search', params.baseURL) let url = params.baseURL; if (! url.endsWith('?')) { url += '?';