Skip to content

Commit

Permalink
first SAMP commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Oct 30, 2023
1 parent 3281298 commit e0c2288
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
},
"dependencies": {
"autocompleter": "^6.1.3",
"jquery": "^3.6.1"
"jquery": "^3.6.1",
"sampjs": "^1.0.3"
}
}
2 changes: 0 additions & 2 deletions src/js/A.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ A.MOCFromJSON = function (jsonMOC, options) {
};


// TODO: try first without proxy, and then with, if param useProxy not set
// API
A.catalogFromURL = function (url, options, successCallback, errorCallback, useProxy) {
var catalog = A.catalog(options);

Expand Down
4 changes: 4 additions & 0 deletions src/js/Aladin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { ALEvent } from "./events/ALEvent.js";
import { Color } from './Color.js';
import { ImageFITS } from "./ImageFITS.js";
import { DefaultActionsForContextMenu } from "./DefaultActionsForContextMenu.js";
import { SAMPConnector } from "./vo/samp.js";
import A from "./A.js";

import $ from 'jquery';
Expand All @@ -59,6 +60,9 @@ export let Aladin = (function () {

// Constructor
var Aladin = function (aladinDiv, requestedOptions) {
this.samp = new SAMPConnector(this);


// check that aladinDiv exists, stop immediately otherwise
if ($(aladinDiv).length == 0) {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/js/events/ALEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export class ALEvent {

static GRAPHIC_OVERLAY_LAYER_CHANGED = new ALEvent("AL:GraphicOverlayLayer.changed");

static SAMP_AVAILABILITY = new ALEvent("AL:samp.started");

constructor(name) {
this.name = name;
}
Expand Down
164 changes: 164 additions & 0 deletions src/js/vo/samp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// Copyright 2013 - UDS/CNRS
// The Aladin Lite program is distributed under the terms
// of the GNU General Public License version 3.
//
// This file is part of Aladin Lite.
//
// Aladin Lite is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Aladin Lite is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// The GNU General Public License is available in COPYING file
// along with Aladin Lite.
//


/******************************************************************************
* Aladin Lite project
*
* File vo/samp.js
*
*
* Author: Matthieu Baumann [CDS, [email protected]]
*
*****************************************************************************/

import { samp } from "sampjs";
import { ALEvent } from "../events/ALEvent";

export class SAMPConnector {
constructor(aladin) {
// Arrange for document to be adjusted for presence of hub every 2 sec.
this.connector = new samp.Connector("Aladin Lite", {
"samp.name": "Aladin Lite",
"samp.description": "Aladin Lite web visualizer SAMP connector"
});

window.addEventListener('load', (e) => {
this.connector.onHubAvailability((isHubRunning) => {
// Communicate to Aladin Lite
ALEvent.SAMP_AVAILABILITY.listenedBy(aladin.aladinDiv, { isHubRunning: isHubRunning } );
}, 2000);
});

window.addEventListener('unload', (e) => {
this.connector.unregister();
});

// Define listeners
let cc = new samp.ClientTracker();
let callHandler = cc.callHandler;

callHandler["script.aladin.send"] = function(senderId, message, isCall) {
var params = message["samp.params"];
aladin.setBaseImageLayer(params["url"])
};

callHandler["coverage.load.moc.fits"] = function(senderId, message, isCall) {
var params = message["samp.params"];

let name = params["name"];
let moc = A.MOCFromURL(params["url"], {name: name, lineWidth: 3});
aladin.addMOC(moc);
};

callHandler["image.load.fits"] = function(senderId, message, isCall) {
let params = message["samp.params"];

let url = params["url"];
let name = params["name"];
const image = aladin.createImageFITS(url, name, options, (e) => window.alert(e));

aladin.setOverlayImageLayer(image, name);
};

callHandler["table.load.votable"] = function(senderId, message, isCall) {
let params = message["samp.params"];

let url = params["url"];
let name = params["name"];

let cat = A.catalogFromURL(
url,
{name: name, onClick: 'showTable'},
null,
(e) => window.alert(e)
);
aladin.addCatalog(cat)
};

//this.connector.register();
//this.loadHiPS("https://alasky.cds.unistra.fr/NEOWISER/W1W2/")
}

// Broadcasts a message given a hub connection.
_send(mtype, params) {
// Provides execution of a SAMP operation with register-on-demand.
this.connector.runWithConnection(
(connection) => {
let msg = new samp.Message(mtype, params);
connection.notifyAll([msg]);
},
(e) => {
window.alert(e)
}
)
}

/**
* Load a VOTable by url
* @param {String} url - URL of the VOTable document to load
* @param {String} [tableId] - Identifier which may be used to refer to the loaded table in subsequent messages
* @param {String} [name] - Name which may be used to label the loaded table in the application GUI
*/
loadVOTable(url, tableId, name) {
this._send("table.load.votable", {
url: url,
"table-id": tableId,
name: name
})
}

/**
* Load a fits image by url
* @param {String} url - URL of the FITS image to load
* @param {String} [imageId] - Identifier which may be used to refer to the loaded image in subsequent messages
* @param {String} [name] - Name which may be used to label the loaded image in the application GUI
*/
loadImageFITS(url, imageId, name) {
this._send("image.load.fits", {
"url": url,
"image-id": imageId,
"name": name
})
}

/**
* Load a Multi-Order-Coverage FITS file
* @param {String} url - URL of a FITS file containing the MOC to load
* @param {String} [coverageId] - Identifier which may be used to refer to the loaded coverage specification in subsequent messages
* @param {String} [name] - Name which may be used to label the loaded image in the application GUI
*/
loadMocFITS(url, coverageId, name) {
this._send("coverage.load.moc.fits", {
"url": url,
"coverage-id": coverageId,
"name": name
})
}

/**
* Load a HiPS by an url
* @param {String} url - base URL for the HiPS to load
*/
loadHiPS(url) {
const cmd = 'load ' + url;
this._send("script.aladin.send", { "script": cmd })
}
}

0 comments on commit e0c2288

Please sign in to comment.