diff --git a/examples/al-additive-blend.html b/examples/al-additive-blend.html index 85c6ff60..f816d3ee 100644 --- a/examples/al-additive-blend.html +++ b/examples/al-additive-blend.html @@ -17,11 +17,11 @@ A.init.then(() => { hscGreenSurvey.setColormap("green", { stretch: "asinh" }); hscGreenSurvey.setCuts(-0.2186, 5.30322); - const HSCRedSurvey = aladin.createImageSurvey('HSC-r', "HSC red", "CDS/P/HSC/DR2/deep/r", null, null, {imgFormat: 'fits', colormap: "red", minCut: 0.34228, maxCut: 2.75785, additive: true, stretch: "asinh"}); - const HSCBlueSurvey = aladin.createImageSurvey('HSC-b', "HSC blue", "CDS/P/HSC/DR2/deep/z", null, null, {imgFormat: 'fits', colormap: "blue", minCut: -0.01218, maxCut: 2.27397, additive: true, stretch: "asinh"}); + const HSCRedSurvey = aladin.createImageSurvey('CDS/P/HSC/DR2/deep/r', "HSC red", undefined, null, null, {imgFormat: 'fits', colormap: "red", minCut: 0.34228, maxCut: 2.75785, additive: true, stretch: "asinh"}); + const HSCBlueSurvey = aladin.createImageSurvey('CDS/P/HSC/DR2/deep/z', "HSC blue", undefined, null, null, {imgFormat: 'fits', colormap: "blue", minCut: -0.01218, maxCut: 2.27397, additive: true, stretch: "asinh"}); - aladin.setOverlayImageLayer('HSC-r', 'hsc red layer'); - aladin.setOverlayImageLayer('HSC-b', 'hsc blue layer'); + aladin.setOverlayImageLayer('CDS/P/HSC/DR2/deep/r', 'hsc red layer'); + aladin.setOverlayImageLayer('CDS/P/HSC/DR2/deep/z', 'hsc blue layer'); }); diff --git a/examples/al-catalog-hips.html b/examples/al-catalog-hips.html index 490e7a3b..1272a138 100644 --- a/examples/al-catalog-hips.html +++ b/examples/al-catalog-hips.html @@ -12,7 +12,7 @@ diff --git a/src/core/src/app.rs b/src/core/src/app.rs index 080384b3..a31c89f8 100644 --- a/src/core/src/app.rs +++ b/src/core/src/app.rs @@ -894,11 +894,11 @@ impl App { use crate::renderable::image::Image; use futures::TryStreamExt; use futures::future::Either; - use web_sys::{Request, RequestInit}; + use web_sys::{Request, RequestInit, RequestMode}; let mut opts = RequestInit::new(); opts.method("GET"); - //opts.mode(RequestMode::Cors); + opts.mode(RequestMode::Cors); let window = window().unwrap(); let request = Request::new_with_str_and_init(&url, &opts)?; diff --git a/src/js/Aladin.js b/src/js/Aladin.js index 1e663088..0505e0a8 100644 --- a/src/js/Aladin.js +++ b/src/js/Aladin.js @@ -1193,11 +1193,11 @@ export let Aladin = (function () { const url = idOrUrl; const id = url; // Url - imageLayer = this.createImageSurvey(id, name, url, null, null); + imageLayer = this.createImageSurvey(idOrUrl, name, idOrUrl, null, null); } else { const id = idOrUrl; // ID - imageLayer = this.createImageSurvey(id, name, undefined, null, null); + imageLayer = this.createImageSurvey(idOrUrl, name, idOrUrl, null, null); } // 2. User gives a non resolved promise } else { @@ -1727,7 +1727,17 @@ Aladin.prototype.getEmbedCode = function () { /* * Creates remotely a HiPS from a FITS image URL and displays it */ -Aladin.prototype.displayFITS = function (url, options, successCallback, errorCallback, layer = "base") { +Aladin.prototype.displayFITS = function ( + url, + options, + successCallback, + errorCallback, + layer = "base" +) { + successCallback = successCallback || ((ra, dec, fov, _) => { + this.gotoRaDec(ra, dec); + this.setFoV(fov); + }); const imageFits = this.createImageFITS(url, url, options, successCallback, errorCallback); return this.setOverlayImageLayer(imageFits, layer); }; @@ -1786,7 +1796,7 @@ Aladin.prototype.displayJPG = Aladin.prototype.displayPNG = function (url, optio var label = options.label || "FITS image"; var meta = response.data.meta; - const survey = self.createImageSurvey(response.data.url, label); + const survey = self.createImageSurvey(response.data.url, label, response.data.url); self.setOverlayImageLayer(survey, "overlay"); var transparency = (options && options.transparency) || 1.0; diff --git a/src/js/Catalog.js b/src/js/Catalog.js index 8141479a..fa180191 100644 --- a/src/js/Catalog.js +++ b/src/js/Catalog.js @@ -35,6 +35,7 @@ import { Utils } from "./Utils.js"; import { AladinUtils } from "./AladinUtils.js"; import { Coo } from "./libs/astro/coo.js"; import { VOTable } from "./vo/VOTable.js"; +import { ALEvent } from "./events/ALEvent.js"; import $ from 'jquery'; @@ -385,9 +386,14 @@ export let Catalog = (function() { this.dec.push(sourcesToAdd[k].dec); } - this.view.wasm.setCatalog(this); + ALEvent.AL_USE_WASM.dispatchedTo(document.body, { + callback: (wasm) => { + wasm.setCatalog(this); + this.reportChange(); + + } + }); - this.reportChange(); }; Catalog.prototype.addFootprints = function(footprintsToAdd) { @@ -409,7 +415,7 @@ export let Catalog = (function() { }; Catalog.prototype.isObsCore = function() { - return this.fields.subtype === "ObsCore"; + return this.fields && this.fields.subtype === "ObsCore"; }; // API diff --git a/src/js/HiPSProperties.js b/src/js/HiPSProperties.js index fb1ac7e6..f32752e2 100644 --- a/src/js/HiPSProperties.js +++ b/src/js/HiPSProperties.js @@ -33,84 +33,100 @@ import { MocServer } from "./MocServer.js"; export let HiPSProperties = {}; -HiPSProperties.fetch = async function(urlOrId) { +HiPSProperties.fetchFromID = async function(ID) { + // Use the MOCServer to retrieve the properties + const params = { + get: "record", + fmt: "json", + ID: "*" + ID + "*", + }; + + let metadata = await Utils.loadFromMirrors(MocServer.MIRRORS_HTTPS, { + data: params, + }).then(response => response.json()); + + // We get the property here + // 1. Ensure there is exactly one survey matching + if (!metadata || metadata.length == 0) { + throw 'No surveys matching have been found for the id: ' + ID; + } else { + let result; + + if (metadata.length > 1) { + let matching = metadata.find((m) => m.ID === ID); + if (matching) { + result = matching; + } else { + result = metadata[0]; + console.warn("Multiple surveys are matching, please choose one. The chosen one is: " + result); + } + } else { + // Exactly one matching + result = metadata[0]; + } + + return result; + } +} + +HiPSProperties.fetchFromUrl = async function(urlOrId) { try { urlOrId = new URL(urlOrId); - } catch (e) {} - - let result = {}; - if (!(urlOrId instanceof URL)) { - // Use the MOCServer to retrieve the - // properties - const ID = urlOrId; - const params = { - get: "record", - fmt: "json", - ID: "*" + ID + "*", - }; - - let metadata = await Utils.loadFromMirrors(MocServer.MIRRORS_HTTPS, { - data: params, - }).then(response => response.json()); - - // We get the property here - // 1. Ensure there is exactly one survey matching - if (!metadata || metadata.length == 0) { - throw 'No surveys matching have been found for the id: ' + ID; - } else { - if (metadata.length > 1) { - let matching = metadata.find((m) => m.ID === ID); - if (matching) { - result = matching; - } else { - result = metadata[0]; - console.warn("Multiple surveys are matching, please choose one. The chosen one is: " + result); - } - } else { - // Exactly one matching - result = metadata[0]; - } + } catch (e) { + // Relative path + try { + urlOrId = Utils.getAbsoluteURL(urlOrId) + urlOrId = new URL(urlOrId); + } catch(e) { + throw e; } - } else { - // Fetch the properties of the survey - const HiPSServiceUrl = urlOrId.toString(); - - let url = HiPSServiceUrl; - // Use the url for retrieving the HiPS properties - // remove final slash - if (url.slice(-1) === '/') { - url = url.substr(0, url.length - 1); - } - url = url + '/properties'; - - // make URL absolute - url = Utils.getAbsoluteURL(url); - // fix for HTTPS support --> will work for all HiPS served by CDS - url = Utils.fixURLForHTTPS(url) - - let init = {}; - if (Utils.requestCORSIfNotSameOrigin(url)) { - init = { mode: 'cors' }; - } - - result = await fetch(url, init) - .then((response) => response.text()) - .then((response) => { - // We get the property here - let metadata = HiPSDefinition.parseHiPSProperties(response); - - // 1. Ensure there is exactly one survey matching - if (metadata) { - // Set the service url if not found - metadata.hips_service_url = HiPSServiceUrl; - } else { - throw 'No surveys matching at this url: ' + rootURL; - } - - return metadata; - }); } + // Fetch the properties of the survey + const HiPSServiceUrl = urlOrId.toString(); + + let url = HiPSServiceUrl; + // Use the url for retrieving the HiPS properties + // remove final slash + if (url.slice(-1) === '/') { + url = url.substr(0, url.length - 1); + } + url = url + '/properties'; + + // make URL absolute + url = Utils.getAbsoluteURL(url); + // fix for HTTPS support --> will work for all HiPS served by CDS + url = Utils.fixURLForHTTPS(url) + + let init = {}; + if (Utils.requestCORSIfNotSameOrigin(url)) { + init = { mode: 'cors' }; + } + + let result = await fetch(url, init) + .then((response) => { + if (response.status == 404) { + return Promise.reject("Url points to nothing") + } else { + return response.text(); + } + }) + .then((response) => { + + // We get the property here + let metadata = HiPSDefinition.parseHiPSProperties(response); + + // 1. Ensure there is exactly one survey matching + if (metadata) { + // Set the service url if not found + metadata.hips_service_url = HiPSServiceUrl; + } else { + throw 'No surveys matching at this url: ' + rootURL; + } + + return metadata; + }) + return result; } diff --git a/src/js/ImageLayer.js b/src/js/ImageLayer.js index f27ad227..f04c844c 100644 --- a/src/js/ImageLayer.js +++ b/src/js/ImageLayer.js @@ -206,6 +206,6 @@ ImageLayer.LAYERS = [ }, ]; -ImageLayer.getAvailableSurveys = function () { +ImageLayer.getAvailableLayers = function () { return ImageLayer.LAYERS; }; diff --git a/src/js/ImageSurvey.js b/src/js/ImageSurvey.js index 0147a517..d3a3cd05 100644 --- a/src/js/ImageSurvey.js +++ b/src/js/ImageSurvey.js @@ -153,7 +153,14 @@ export let ImageSurvey = (function () { let maxOrder, frame, tileSize, formats, minCutout, maxCutout, bitpix, skyFraction, minOrder, initialFov, initialRa, initialDec, hipsBody, isPlanetaryBody, dataproductSubtype; try { - const properties = await HiPSProperties.fetch(url || id); + let properties; + try { + properties = await HiPSProperties.fetchFromUrl(url) + .catch(async (e) => { + // url not valid + return await HiPSProperties.fetchFromID(id); + }) + } catch(e) {} // Give a better name if we have the HiPS metadata self.name = self.name || properties.obs_title; diff --git a/src/js/Source.js b/src/js/Source.js index c2c1a89a..b64a6e98 100644 --- a/src/js/Source.js +++ b/src/js/Source.js @@ -108,7 +108,7 @@ export let Source = (function() { }; let options = {}; - if (this.catalog.isObsCore()) { + if (this.catalog.isObsCore && this.catalog.isObsCore()) { // If the source is obscore, save the table state inside the measurement table // This is used to go back from a possible datalink table to the obscore one options["save"] = true; diff --git a/src/js/View.js b/src/js/View.js index 9f6e28f2..884342ef 100644 --- a/src/js/View.js +++ b/src/js/View.js @@ -594,7 +594,7 @@ export let View = (function () { 'fieldsClickedActions': catalog.fieldsClickedActions, }; - if (catalog.isObsCore()) { + if (catalog.isObsCore && catalog.isObsCore()) { // If the source is obscore, save the table state inside the measurement table // This is used to go back from a possible datalink table to the obscore one options["save"] = true; @@ -1675,12 +1675,11 @@ export let View = (function () { // check if there are no more surveys const noMoreLayersToWaitFor = this.promises.length === 0; - - if (noMoreLayersToWaitFor && this.empty) { + if (noMoreLayersToWaitFor && this.empty || layer === "base") { // no promises to launch! const idxServiceUrl = Math.round(Math.random()); const dssUrl = Aladin.DEFAULT_OPTIONS.surveyUrl[idxServiceUrl] - + console.log(idxServiceUrl) this.aladin.setBaseImageLayer(dssUrl); } }; @@ -1819,7 +1818,6 @@ export let View = (function () { } // Set the grid label format - console.log("lavel", this.cooFrame.label) if (this.cooFrame.label == "J2000d") { this.setGridConfig({fmt: "HMS"}); } diff --git a/src/js/vo/VOTable.js b/src/js/vo/VOTable.js index d7d59695..a538d94e 100644 --- a/src/js/vo/VOTable.js +++ b/src/js/vo/VOTable.js @@ -56,8 +56,6 @@ export let VOTable = (function() { let tables = resource.get("tables") if (tables) { tables.forEach((table) => { - console.log(table.get("elems")) - let fields = table.get("elems") .filter((elem) => { const elemType = elem["elem_type"] || elem.get("elem_type")