Skip to content

Commit

Permalink
fix: only cache the HiPS object atm
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Nov 6, 2024
1 parent a6f2f1e commit 8cac042
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"homepage": "https://aladin.u-strasbg.fr/",
"name": "aladin-lite",
"type": "module",
"version": "3.5.1-beta",
"version": "3.6.0-beta",
"description": "An astronomical HiPS visualizer in the browser",
"author": "Thomas Boch and Matthieu Baumann",
"license": "GPL-3",
Expand Down
5 changes: 0 additions & 5 deletions src/core/src/renderable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ impl Layers {
.ok_or(err_layer_not_found)?;
self.layers.remove(id_layer);

al_core::log(&format!("remove layer {:?}", id_layer));
// Loop over all the meta for its longitude reversed property
// and set the camera to it if there is at least one
let longitude_reversed = self.meta.values().any(|meta| meta.longitude_reversed);
Expand All @@ -336,13 +335,9 @@ impl Layers {
// Check if the url is still used
let id_still_used = self.ids.values().any(|rem_id| rem_id == &id);
if id_still_used {
al_core::log("still used");

// Keep the resource whether it is a HiPS or a FITS
Ok(id_layer)
} else {
al_core::log("not needed");

// Resource not needed anymore
if let Some(hips) = self.hipses.remove(&id) {
// A HiPS has been found and removed
Expand Down
3 changes: 1 addition & 2 deletions src/js/A.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,10 @@ A.aladin = function (divSelector, options) {
* @returns {HiPS} - A HiPS image object
*/
A.HiPS = function (id, options) {
let url = id;
return Aladin.createImageSurvey(
id,
options && options.name,
url,
(options && options.url) || id,
options && options.cooFrame,
options && options.maxOrder,
options
Expand Down
25 changes: 15 additions & 10 deletions src/js/Aladin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1544,9 +1544,9 @@ export let Aladin = (function () {
let hipsOptions = { id, name, maxOrder, url, cooFrame, ...options };
let hips = new HiPS(id, url || id, hipsOptions)

if (this instanceof Aladin && !this.hipsCache.contains(hips.name)) {
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.name, hipsOptions)
this.hipsCache.append(hips.id, hipsOptions)
}

return hips;
Expand Down Expand Up @@ -1651,7 +1651,8 @@ export let Aladin = (function () {
// Do not use proxy with CORS headers until we solve that: https://github.com/MattiasBuelens/wasm-streams/issues/20
//url = Utils.handleCORSNotSameOrigin(url).href;

let image = new Image(url, {...options, successCallback, errorCallback});
let imageOptions = {...options, successCallback, errorCallback};
let image = new Image(url, imageOptions);

return image;
};
Expand Down Expand Up @@ -1865,16 +1866,20 @@ export let Aladin = (function () {
// 3/ It is an image survey.
imageLayer = urlOrHiPSOrFITS;

let cachedLayerOptions = hipsCache.get(imageLayer.name)

if (!cachedLayerOptions) {
hipsCache.append(imageLayer.name, imageLayer.options)
} else {
// first set the options of the cached layer to the one of the user
// if it is in the cache we get it from the cache
imageLayer = A.HiPS(imageLayer.id, cachedLayerOptions)
if (imageLayer instanceof HiPS) {
let cachedLayerOptions = hipsCache.get(imageLayer.id)

if (!cachedLayerOptions) {
hipsCache.append(imageLayer.id, imageLayer.options)
} else {
// first set the options of the cached layer to the one of the user
// if it is in the cache we get it from the cache
imageLayer = A.HiPS(imageLayer.id, cachedLayerOptions)
}
}
}

let imageLayerCopied = Object.assign(Object.create(Object.getPrototypeOf(imageLayer)), imageLayer)
imageLayerCopied.layer = layer;

Expand Down
6 changes: 4 additions & 2 deletions src/js/HiPS.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export let HiPS = (function () {
}

this.url = location;

this.maxOrder = options.maxOrder;
this.minOrder = options.minOrder || 0;
this.cooFrame = options.cooFrame;
Expand Down Expand Up @@ -878,6 +879,7 @@ export let HiPS = (function () {
if (isIncompleteOptions) {
// ID typed url
if (self.startUrl && isID) {

// First download the properties from the start url
await HiPSProperties.fetchFromUrl(self.startUrl)
.then((p) => {
Expand Down Expand Up @@ -949,8 +951,8 @@ export let HiPS = (function () {
let self = this;
let hipsCache = this.view.aladin.hipsCache;

if (hipsCache.contains(self.name)) {
hipsCache.append(self.name, this.options)
if (hipsCache.contains(self.id)) {
hipsCache.append(self.id, this.options)
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/js/HiPSProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ HiPSProperties.fetchFromUrl = async function(urlOrId) {
let result = fetch(url, init)
.then((response) => {
if (response.status == 404) {
return Promise.reject("Url points to nothing")
return Promise.reject("Url points to nothing: " + url)
} else {
return response.text();
}
Expand Down
1 change: 1 addition & 0 deletions src/js/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export let Image = (function () {
return Promise.reject(e)
})
} else if (this.imgFormat === 'jpeg' || this.imgFormat === 'png') {

promise = this._addJPGOrPNG(layer)
.catch(e => {
console.error(`Image located at ${this.url} could not be parsed as a ${this.imgFormat} file. Is the imgFormat specified correct?`);
Expand Down
1 change: 1 addition & 0 deletions src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,7 @@ export let View = (function () {
// to the image layer objet (whether it is an HiPS or an Image)
.then((imageLayer) => {
// Add to the backend
imageLayer._setView(this)
const promise = imageLayer._add(layer);
ALEvent.FETCH.dispatchedTo(document, {task});

Expand Down
39 changes: 23 additions & 16 deletions src/js/gui/Box/StackBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,9 @@ export class OverlayStackBox extends Box {
} else {
self.cachedHiPS[key] = HiPSOptions;
}*/
self.cachedHiPS[key] = HiPSOptions;

let k = HiPSOptions.name || key;
self.cachedHiPS[k] = HiPSOptions;
}

// Update the options of the selector
Expand All @@ -742,7 +744,7 @@ export class OverlayStackBox extends Box {
let currentHiPS = hips.HiPSSelector.options.value

let favoritesCopy = [...favorites];

// add the current hips to the selector as well, even if it has been manually
// removed from the HiPSList
if (favoritesCopy.indexOf(currentHiPS) < 0) {
Expand Down Expand Up @@ -941,25 +943,31 @@ export class OverlayStackBox extends Box {
hipsOptions.sort()

for (const layer of layers) {
let options = Array.from([...hipsOptions])
let value = layer.name || layer.id

if (options.indexOf(value) < 0) {
options.push(value)
}

let HiPSSelector = Input.select({
value: layer.name || layer.id,
options: hipsOptions,
value,
options,
title: layer.name,
change: (e) => {
let name = e.target.value;
// search for the
let HiPSOptions = self.cachedHiPS[name];
// search for the
let overlayLayer;
if (name in self.cachedHiPS) {
// it is an hips
let HiPSOptions = self.cachedHiPS[name];

/*let image;
if (HiPS instanceof Image) {
image = HiPS;
overlayLayer = A.HiPS(HiPSOptions.id || HiPSOptions.url, HiPSOptions);
} else {
// HiPS
image = HiPS.id || HiPS.url || undefined;
}*/
let hips = A.HiPS(HiPSOptions.id || HiPSOptions.url, HiPSOptions);

self.aladin.setOverlayImageLayer(hips, layer.layer);
overlayLayer = layer
}

self.aladin.setOverlayImageLayer(overlayLayer, layer.layer);
}
});

Expand All @@ -969,7 +977,6 @@ export class OverlayStackBox extends Box {
disable: layer.layer === "base",
tooltip: { content: "Remove", position: { direction: "top" } },
action(e) {
console.log(layer)
self.aladin.removeImageLayer(layer.layer);
// remove HiPS cube player if any
self.aladin.removeUIByName("cube_displayer" + layer.layer)
Expand Down

0 comments on commit 8cac042

Please sign in to comment.