This commit is contained in:
Matthieu Baumann
2025-02-13 00:47:57 +01:00
parent f75211902b
commit 5d3d0b2cfc
5 changed files with 88 additions and 74 deletions

View File

@@ -5,7 +5,8 @@
<body>
<div id="aladin-lite-div" style="width: 1024px; height: 768px"></div>
<script type="module">
import A from '../src/js/A.js';
import A from '../src/js/A.js';
A.init.then(() => {
let aladin = A.aladin('#aladin-lite-div', {projection: "TAN", survey: "P/HSC/DR2/deep/g", target: '02 21 36.529 -05 31 20.16', fov: 0.1});
@@ -16,6 +17,7 @@ A.init.then(() => {
const HSCRedSurvey = aladin.newImageSurvey('P/HSC/DR2/deep/r', {imgFormat: 'fits', colormap: "red", minCut: 0.34228, maxCut: 2.75785, additive: true, stretch: "asinh"});
const HSCBlueSurvey = aladin.newImageSurvey('P/HSC/DR2/deep/z', {imgFormat: 'fits', colormap: "blue", minCut: -0.01218, maxCut: 2.27397, additive: true, stretch: "asinh"});
HSCRedSurvey.setColormap('red', {stretch: 'linear'});
aladin.setOverlayImageLayer('P/HSC/DR2/deep/r', 'hsc red layer');
aladin.setOverlayImageLayer('P/HSC/DR2/deep/z', 'hsc blue layer');

View File

@@ -13,10 +13,9 @@
aladin = A.aladin('#aladin-lite-div', {projection: 'AIT', cooFrame: 'galactic', fov: 200, target: 'galactic center'});
let dss = aladin.createImageSurvey("DSS blue band", "Color DSS blue HiPS", "http://alasky.cds.unistra.fr/DSS/DSS2-blue-XJ-S/", "equatorial", 9, {imgFormat: 'fits'})
aladin.setBaseImageLayer(dss);
aladin.getBaseImageLayer().setCuts(2, 10000);
dss.setCuts(2, 10000);
});

View File

@@ -383,62 +383,64 @@ export let Aladin = (function () {
this.createCatalogFromVOTable(options.catalogUrls[k]);
}
}
// Keep the default hips list
this.hipsList = {};
let hipsList = [].concat(options.hipsList);
const fillHiPSCache = () => {
for (var survey of hipsList) {
let id, url, name;
let cachedSurvey = {};
for (var hips of hipsList) {
let id, url, name;
let hipsObj = {};
if (typeof survey === "string") {
try {
url = new URL(survey).href;
} catch (e) {
id = survey;
}
name = url || id;
} else if (survey instanceof Object) {
if (survey.id) {
id = survey.id;
}
if (survey.url) {
url = survey.url;
}
name = survey.name || survey.id || survey.url;
cachedSurvey = { ...cachedSurvey, ...survey };
} else {
console.warn(
"unable to parse the survey list item: ",
survey
);
continue;
if (typeof hips === "string") {
try {
url = new URL(hips).href;
} catch (e) {
id = hips;
}
if (id) {
cachedSurvey["id"] = id;
name = url || id;
} else if (hips instanceof Object) {
if (hips.id) {
id = hips.id;
}
if (url) {
cachedSurvey["url"] = url;
}
if (name) {
cachedSurvey["name"] = name;
if (hips.url) {
url = hips.url;
}
// at least id or url is defined
let key = name || id || url;
name = hips.name || hips.id || hips.url;
// Merge what is already in the cache for that HiPS with new properties
// coming from the MOCServer
self.hipsCache.append(key, cachedSurvey);
hipsObj = { ...hipsObj, ...hips };
} else {
console.warn(
"unable to parse the survey list item: ",
hips
);
continue;
}
};
if (id) {
hipsObj["id"] = id;
}
if (url) {
hipsObj["url"] = url;
}
if (name) {
hipsObj["name"] = name;
}
// at least id or url is defined
let key = name || id || url;
// Merge what is already in the cache for that HiPS with new properties
// coming from the MOCServer
this.hipsList[key] = hipsObj;
}
this._setupUI(options);
fillHiPSCache();
ALEvent.FAVORITE_HIPS_LIST_UPDATED.dispatchedTo(document.body, this.hipsList);
if (options.survey) {
if (Array.isArray(options.survey)) {
@@ -1560,6 +1562,8 @@ export let Aladin = (function () {
let hipsOptions = { id, name, maxOrder, url, cooFrame, ...options };
let hips = new HiPS(id, url || id, hipsOptions)
// This allows to retrieve the survey's options when it will be
// added later to the view.
if (this instanceof Aladin && !this.hipsCache.contains(hips.id)) {
// Add it to the cache as soon as possible if we have a reference to the aladin object
this.hipsCache.append(hips.id, hipsOptions)
@@ -1603,20 +1607,24 @@ export let Aladin = (function () {
* <li>4. A {@link Image} FITS image object</li>
* </ul>
*/
Aladin.prototype.removeHiPSFromFavorites = function (survey) {
if (this.contains(survey)) {
Aladin.prototype.removeHiPSFromFavorites = function (hips) {
if (this.contains(hips)) {
// TODO: handle this case
console.warn(survey + ' is among the list of HiPS currently in the view.');
console.warn(hips + ' is among the list of HiPS currently in the view.');
}
let id;
if (typeof survey !== "string") {
id = survey.name
let name;
if (typeof hips !== "string") {
name = hips.name
} else {
id = survey
name = hips
}
if (this.hipsList[name]) {
delete this.hipsList[name];
// Send a change of favorites for the UI selector to adapt their optional list
ALEvent.FAVORITE_HIPS_LIST_UPDATED.dispatchedTo(document.body, this.hipsList);
}
this.hipsCache.delete(id);
}
/**
@@ -1895,10 +1903,21 @@ export let Aladin = (function () {
}
}
let imageLayerCopied = Object.assign(Object.create(Object.getPrototypeOf(imageLayer)), imageLayer)
imageLayerCopied.layer = layer;
// Add it to the hipsList if it is not there yet
if (!this.hipsList[imageLayer.name]) {
this.hipsList[imageLayer.id] = {
id: imageLayer.id,
url: imageLayer.url,
name: imageLayer.name,
};
return this.view.setOverlayImageLayer(imageLayerCopied, layer);
ALEvent.FAVORITE_HIPS_LIST_UPDATED.dispatchedTo(document.body, this.hipsList);
}
//let imageLayerCopied = Object.assign(Object.create(Object.getPrototypeOf(imageLayer)), imageLayer)
imageLayer.layer = layer;
return this.view.setOverlayImageLayer(imageLayer, layer);
};
/**

View File

@@ -57,6 +57,8 @@ export class ALEvent {
static HIPS_CACHE_UPDATED = new ALEvent("AL:HiPSCache.updated");
static FAVORITE_HIPS_LIST_UPDATED = new ALEvent("AL:HiPSFavorites.updated");
static HIPS_LAYER_CHANGED = new ALEvent("AL:HiPSLayer.changed");
static GRAPHIC_OVERLAY_LAYER_ADDED = new ALEvent("AL:GraphicOverlayLayer.added");

View File

@@ -714,31 +714,20 @@ export class OverlayStackBox extends Box {
);
updateOverlayList();
let hipsCache = this.aladin.hipsCache;
// Add a listener for HiPS list changes
ALEvent.HIPS_CACHE_UPDATED.listenedBy(document.body, () => {
ALEvent.FAVORITE_HIPS_LIST_UPDATED.listenedBy(document.body, (event) => {
let hipsList = event.detail;
self.cachedHiPS = {};
for (var key in hipsCache.cache) {
let HiPSOptions = hipsCache.cache[key];
/*if (HiPSOptions.name) {
self.cachedHiPS[HiPSOptions.name.toString()] = HiPSOptions;
} else {
self.cachedHiPS[key] = HiPSOptions;
}*/
for (var key in hipsList) {
let HiPSOptions = hipsList[key];
let k = HiPSOptions.name || key;
self.cachedHiPS[k] = HiPSOptions;
}
// Update the options of the selector
const favorites = Object.keys(self.cachedHiPS);
// one must add the current HiPS too!
favorites.sort();
for (var key in self.HiPSui) {
let hips = self.HiPSui[key];
let currentHiPS = hips.HiPSSelector.options.value
@@ -751,6 +740,9 @@ export class OverlayStackBox extends Box {
favoritesCopy.push(currentHiPS)
}
// one must add the current HiPS too!
favoritesCopy.sort();
hips.HiPSSelector.update({value: currentHiPS, options: favoritesCopy});
}
});