From 5fd6bedeb97b93e0399643c6c95f8e53919cbc36 Mon Sep 17 00:00:00 2001 From: Matthieu Baumann Date: Tue, 13 Aug 2024 19:27:27 +0200 Subject: [PATCH] wip have a default hips url on allsky for the default hips list to begin to query while waiting for the mocserver response --- examples/al-init-custom-options.html | 1 + src/js/Aladin.js | 100 ++++++++++++--------------- src/js/DefaultHiPSList.js | 2 + src/js/ImageHiPS.js | 72 ++++++++++--------- 4 files changed, 86 insertions(+), 89 deletions(-) diff --git a/examples/al-init-custom-options.html b/examples/al-init-custom-options.html index 15c0f9ce..c298cc34 100644 --- a/examples/al-init-custom-options.html +++ b/examples/al-init-custom-options.html @@ -26,6 +26,7 @@ showSettingsControl:true, showCooGrid: true, fullScreen: true, + samp: true, } ); diff --git a/src/js/Aladin.js b/src/js/Aladin.js index 262b263d..aa83a9e9 100644 --- a/src/js/Aladin.js +++ b/src/js/Aladin.js @@ -379,46 +379,6 @@ export let Aladin = (function () { } } - if (options.survey) { - if (Array.isArray(options.survey)) { - let i = 0; - options.survey.forEach((rootURLOrId) => { - if (i == 0) { - this.setBaseImageLayer(rootURLOrId); - } else { - this.setOverlayImageLayer(rootURLOrId, Utils.uuidv4()); - } - i++; - }); - } else if (options.survey === ImageHiPS.DEFAULT_SURVEY_ID) { - // DSS is cached inside ImageHiPS class, no need to provide any further information - const survey = this.createImageSurvey( - ImageHiPS.DEFAULT_SURVEY_ID - ); - - this.setBaseImageLayer(survey); - } else { - this.setBaseImageLayer(options.survey); - } - } else { - // Add the image layers - // For that we check the survey key of options - // It can be given as a single string or an array of strings - // for multiple blending surveys - // take in priority the surveyUrl parameter - let url; - if (Array.isArray(options.surveyUrl)) { - // mirrors given, take randomly one - let numMirrors = options.surveyUrl.length; - let id = Math.floor(Math.random() * numMirrors); - url = options.surveyUrl[id]; - } else { - url = options.surveyUrl; - } - - this.setBaseImageLayer(url); - } - let hipsList = [].concat(options.hipsList); const fillHiPSCache = () => { @@ -444,15 +404,6 @@ export let Aladin = (function () { name = survey.name || survey.id || survey.url; - if (id && url) { - console.warn( - 'Both "CDS ID" and url are given for ', - survey, - ". ID is chosen." - ); - url = null; - } - cachedSurvey = { ...cachedSurvey, ...survey }; } else { console.warn( @@ -477,19 +428,53 @@ export let Aladin = (function () { // Merge what is already in the cache for that HiPS with new properties // coming from the MOCServer - - /*HiPSCache.append(key, { - ...HiPSCache.get(key), - ...cachedSurvey, - });*/ let hips = new ImageHiPS(key, cachedSurvey.url, cachedSurvey) self.hipsCache.append(key, hips); } }; - fillHiPSCache(); + if (options.survey) { + if (Array.isArray(options.survey)) { + let i = 0; + options.survey.forEach((rootURLOrId) => { + if (i == 0) { + this.setBaseImageLayer(rootURLOrId); + } else { + this.setOverlayImageLayer(rootURLOrId, Utils.uuidv4()); + } + i++; + }); + } else if (options.survey === ImageHiPS.DEFAULT_SURVEY_ID) { + // DSS is cached inside ImageHiPS class, no need to provide any further information + const survey = this.createImageSurvey( + ImageHiPS.DEFAULT_SURVEY_ID + ); + + this.setBaseImageLayer(survey); + } else { + this.setBaseImageLayer(options.survey); + } + } else { + // Add the image layers + // For that we check the survey key of options + // It can be given as a single string or an array of strings + // for multiple blending surveys + // take in priority the surveyUrl parameter + let url; + if (Array.isArray(options.surveyUrl)) { + // mirrors given, take randomly one + let numMirrors = options.surveyUrl.length; + let id = Math.floor(Math.random() * numMirrors); + url = options.surveyUrl[id]; + } else { + url = options.surveyUrl; + } + + this.setBaseImageLayer(url); + } + this.view.showCatalog(options.showCatalog); // FullScreen toolbar icon @@ -1831,7 +1816,6 @@ export let Aladin = (function () { const idOrUrl = urlOrHiPSOrFITS; imageLayer = A.imageHiPS(idOrUrl); - // 2. User gives a non resolved promise } else { imageLayer = urlOrHiPSOrFITS; @@ -1844,8 +1828,12 @@ export let Aladin = (function () { imageLayer = cachedLayer } else { this.hipsCache.append(imageLayer.id, imageLayer); + } + //console.log("cached layer", hipsCache) + + return this.view.setOverlayImageLayer(imageLayer, layer); }; diff --git a/src/js/DefaultHiPSList.js b/src/js/DefaultHiPSList.js index 85f0d2ed..a5237f84 100644 --- a/src/js/DefaultHiPSList.js +++ b/src/js/DefaultHiPSList.js @@ -10,6 +10,7 @@ export let HiPSList = (function () { tileSize: 512, imgFormat: "jpeg", cooFrame: "ICRS", + startingUrl: "https://alasky.cds.unistra.fr/DSS/DSSColor/", }, { creatorDid: "ivo://CDS/P/2MASS/color", @@ -145,6 +146,7 @@ export let HiPSList = (function () { tileSize: 512, imgFormat: "jpeg", cooFrame: "equatorial", + startingUrl: "https://alasky.cds.unistra.fr/DSS/DSSColor/" }, { creatorDid: "ivo://CDS/P/SDSS9/g", diff --git a/src/js/ImageHiPS.js b/src/js/ImageHiPS.js index 8a297bd3..e01c9706 100644 --- a/src/js/ImageHiPS.js +++ b/src/js/ImageHiPS.js @@ -178,6 +178,7 @@ export let ImageHiPS = (function () { this.cooFrame = options.cooFrame; this.tileSize = options.tileSize; this.skyFraction = options.skyFraction; + this.startingUrl = options.startingUrl; this.longitudeReversed = options.longitudeReversed === undefined ? false @@ -205,10 +206,10 @@ export let ImageHiPS = (function () { } this.view = view; - let isMOCServerToBeQueried = true; + let isIncompleteOptions = true; if (this.imgFormat === "fits") { // a fits is given - isMOCServerToBeQueried = !( + isIncompleteOptions = !( this.maxOrder && this.url && this.imgFormat && @@ -217,7 +218,7 @@ export let ImageHiPS = (function () { this.numBitsPerPixel ); } else { - isMOCServerToBeQueried = !( + isIncompleteOptions = !( this.maxOrder && this.url && this.imgFormat && @@ -227,36 +228,11 @@ export let ImageHiPS = (function () { } self.query = (async () => { - if (isMOCServerToBeQueried) { + if (isIncompleteOptions) { let isCDSId = false; - let properties = await HiPSProperties.fetchFromUrl(self.url) - /*.catch((e) => { - // try with the proxy - url = Utils.handleCORSNotSameOrigin(url).href; - - return HiPSProperties.fetchFromUrl(url); - })*/ - .catch(async (e) => { - // url not valid so we try with the id - try { - isCDSId = true; - // the url stores a "CDS ID" we take it prioritaly - // if the url is null, take the id, this is for some tests - // to pass because some users might just give null as url param and a "CDS ID" as id param - let id = self.url || self.id; - return await HiPSProperties.fetchFromID(id); - } catch (e) { - throw e; - } - }); - - //obsTitle = properties.obs_title; - self.creatorDid = properties.creator_did || self.creatorDid; - // url - - if (isCDSId) { - self.url = properties.hips_service_url; + let fetchBestUrl = (p) => { + self.url = p.hips_service_url; if (!self.url) { throw "no valid service URL for retrieving the tiles"; } @@ -264,7 +240,7 @@ export let ImageHiPS = (function () { self.url = Utils.fixURLForHTTPS(self.url); // Request all the properties to see which mirror is the fastest - HiPSProperties.getFasterMirrorUrl(properties, self.url) + HiPSProperties.getFasterMirrorUrl(p, self.url) .then((url) => { if (self.url !== url) { console.info( @@ -294,7 +270,37 @@ export let ImageHiPS = (function () { console.error(self); console.error(e); }); - } + }; + + let properties = await HiPSProperties.fetchFromUrl(self.url) + /*.catch((e) => { + // special case for glimpse if I remember right + // try with the proxy + url = Utils.handleCORSNotSameOrigin(url).href; + + return HiPSProperties.fetchFromUrl(url); + })*/ + .catch(async (e) => { + // url not valid so we try with the id + try { + isCDSId = true; + // the url stores a "CDS ID" we take it prioritaly + // if the url is null, take the id, this is for some tests + // to pass because some users might just give null as url param and a "CDS ID" as id param + let id = self.url || self.id; + // a starting url stored into the default hips list so that we do not wait + // the query to the mocserver + //console.log("cds id") + return await HiPSProperties.fetchFromID(id) + } catch (e) { + throw e; + } + }); + + fetchBestUrl(properties); + + self.creatorDid = properties.creator_did || self.creatorDid; + // url // Max order self.maxOrder =