mirror of
https://github.com/cds-astro/aladin-lite.git
synced 2025-12-12 15:49:18 -08:00
Add customizeShareURLFunction method and associated example, solves issue #273
This commit is contained in:
22
examples/al-customize-share-url-fn.html
Normal file
22
examples/al-customize-share-url-fn.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, height=device-height, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
|
||||
</head>
|
||||
<body>
|
||||
<div id="aladin-lite-div" style="width: 500px; height: 500px"></div>
|
||||
|
||||
<script type="text/javascript" src="./../dist/aladin.umd.cjs" charset="utf-8"></script>
|
||||
<script type="text/javascript">
|
||||
var aladin;
|
||||
A.init.then(() => {
|
||||
aladin = A.aladin('#aladin-lite-div', {fullScreen: true, cooFrame: "ICRSd", showSimbadPointerControl: true, showShareControl: true, showShareControl: true, survey: 'https://alasky.cds.unistra.fr/DSS/DSSColor/', fov: 1.0, target: 'M 20', showContextMenu: true});
|
||||
|
||||
// customize share URL function
|
||||
aladin.customizeShareURLFunction(() => {return 'https://sky.esa.int/esasky/?target=' + aladin.getRaDec()[0] + '%20' + aladin.getRaDec()[1] + '&fov=' + aladin.getFoV()[0]})
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -285,6 +285,9 @@ export let Aladin = (function () {
|
||||
this.callbacksByEventName = {}; // we store the callback functions (on 'zoomChanged', 'positionChanged', ...) here
|
||||
this.hipsCache = new HiPSCache();
|
||||
|
||||
this.customShareURLFn = null;
|
||||
|
||||
|
||||
// check that aladinDiv exists, stop immediately otherwise
|
||||
if (!aladinDiv) {
|
||||
console.error(
|
||||
@@ -2906,23 +2909,23 @@ export let Aladin = (function () {
|
||||
this.popup.hide();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the URL corresponding to the current view
|
||||
*
|
||||
* @memberof Aladin
|
||||
*
|
||||
* @returns {string} The URL allowing to share the current view
|
||||
// @API
|
||||
/*
|
||||
* return a URL allowing to share the current view
|
||||
*/
|
||||
Aladin.prototype.getShareURL = function () {
|
||||
var radec = this.getRaDec();
|
||||
var coo = new Coo();
|
||||
// do we have a custom share URL function set?
|
||||
if (this.customShareURLFn) {
|
||||
return this.customShareURLFn();
|
||||
}
|
||||
|
||||
const radec = this.getRaDec();
|
||||
const coo = new Coo();
|
||||
coo.prec = 7;
|
||||
coo.lon = radec[0];
|
||||
coo.lat = radec[1];
|
||||
|
||||
return (
|
||||
Aladin.URL_PREVIEWER +
|
||||
return Aladin.URL_PREVIEWER +
|
||||
"?target=" +
|
||||
encodeURIComponent(coo.format("s")) +
|
||||
"&fov=" +
|
||||
@@ -2930,10 +2933,25 @@ export let Aladin = (function () {
|
||||
"&survey=" +
|
||||
encodeURIComponent(
|
||||
this.getBaseImageLayer().id || this.getBaseImageLayer().rootUrl
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Customize share URL creation
|
||||
* @memberof Aladin
|
||||
* @param {Function} [customShareURLFn] - The function that will be called when a user clicks on "Get view URL", to share with collaborators
|
||||
*
|
||||
* @example
|
||||
aladin.customizeShareURLFunction(() => {return 'https://sky.esa.int/esasky/?target=' + aladin.getRaDec()[0] + '%20' + aladin.getRaDec()[1] + '&fov=' + aladin.getFoV()[0]})
|
||||
*/
|
||||
Aladin.prototype.customizeShareURLFunction = function(customShareURLFn) {
|
||||
if (! typeof customShareURLFn === 'function') {
|
||||
this.customShareURLFn = null;
|
||||
}
|
||||
|
||||
this.customShareURLFn = customShareURLFn;
|
||||
}
|
||||
|
||||
// @API
|
||||
/*
|
||||
* return, as a string, the HTML embed code
|
||||
|
||||
Reference in New Issue
Block a user