Files
aladin-lite/src/js/DefaultActionsForContextMenu.js

132 lines
5.4 KiB
JavaScript

// Copyright 2023 - 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 DefaultActionsForContextMenu
*
* Author: Thomas Boch[CDS]
*
*****************************************************************************/
import { SimbadPointer } from "./SimbadPointer.js";
import { PlanetaryFeaturesPointer } from "./PlanetaryFeaturesPointer.js";
export let DefaultActionsForContextMenu = (function () {
let DefaultActionsForContextMenu = {};
DefaultActionsForContextMenu.getDefaultActions = function (aladinInstance) {
return [
{
label: "Copy position", action(o) {
var r = document.createRange();
r.selectNode(o.target);
window.getSelection().removeAllRanges();
window.getSelection().addRange(r);
try {
let successful = document.execCommand('copy');
let msg = successful ? 'successful' : 'unsuccessful';
//console.log('Copying text command was ' + msg);
} catch (err) {
console.error('Oops, unable to copy to clipboard');
}
window.getSelection().removeAllRanges();
}
},
{
label: "Take snapshot", action(o) { aladinInstance.exportAsPNG(); }
},
{
label: "Add", action(o) { console.log(o) },
subMenu: [
{
label: 'New image layer', action(o) {
aladinInstance.addNewImageLayer();
console.log(o)
}
},
{ label: 'New catalogue layer', action(o) { console.log(o) } }
]
},
{
label: "Load local file",
subMenu: [
{
label: 'Load FITS MOC', action(o) {
let input = document.createElement('input');
input.type = 'file';
input.onchange = _ => {
let files = Array.from(input.files);
files.forEach(file => {
const url = URL.createObjectURL(file);
let moc = A.MOCFromURL(url, { name: file.name });
aladinInstance.addMOC(moc);
});
};
input.click();
}
},
{
label: 'Load VOTable', action(o) {
let input = document.createElement('input');
input.type = 'file';
input.onchange = _ => {
let files = Array.from(input.files);
files.forEach(file => {
const url = URL.createObjectURL(file);
let catalogue = A.catalogFromURL(url, { name: file.name, onClick: 'showTable'}, null, false);
aladinInstance.addCatalog(catalogue);
});
};
input.click();
}
}
]
},
{
label: "What is this?", action(e) {
const xymouse = aladinInstance.view.imageCanvas.relMouseCoords(e);
let radec = aladinInstance.wasm.screenToWorld(xymouse.x, xymouse.y);
if (radec) {
// sky case
if (aladinInstance.getBaseImageLayer().properties.isPlanetaryBody === false) {
SimbadPointer.query(radec[0], radec[1], Math.min(1, 15 * aladinInstance.view.fov / aladinInstance.view.largestDim), aladinInstance);
}
// planetary body case
else {
// TODO: replace with actual value
const body = aladinInstance.getBaseImageLayer().properties.hipsBody;
PlanetaryFeaturesPointer.query(radec[0], radec[1], Math.min(80, aladinInstance.view.fov / 20.0), body, aladinInstance);
}
}
}
},
]
}
return DefaultActionsForContextMenu;
})();