Skip to content

Commit

Permalink
wip have a default hips url on allsky for the default hips list to be…
Browse files Browse the repository at this point in the history
…gin to query while waiting for the mocserver response
  • Loading branch information
bmatthieu3 committed Sep 10, 2024
1 parent 6dd8ee2 commit 5fd6bed
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 89 deletions.
1 change: 1 addition & 0 deletions examples/al-init-custom-options.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
showSettingsControl:true,
showCooGrid: true,
fullScreen: true,
samp: true,
}
);

Expand Down
100 changes: 44 additions & 56 deletions src/js/Aladin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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);
};

Expand Down
2 changes: 2 additions & 0 deletions src/js/DefaultHiPSList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
72 changes: 39 additions & 33 deletions src/js/ImageHiPS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 &&
Expand All @@ -217,7 +218,7 @@ export let ImageHiPS = (function () {
this.numBitsPerPixel
);
} else {
isMOCServerToBeQueried = !(
isIncompleteOptions = !(
this.maxOrder &&
this.url &&
this.imgFormat &&
Expand All @@ -227,44 +228,19 @@ 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";
}

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(
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 5fd6bed

Please sign in to comment.