mirror of
https://github.com/cds-astro/aladin-lite.git
synced 2026-04-28 11:53:18 -07:00
read only catalog option
This commit is contained in:
31
examples/al-cat-read-only.html
Normal file
31
examples/al-cat-read-only.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<!--<link rel="stylesheet" href="./layers.css" />-->
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="aladin-lite-div" style="width: 1024px; height: 768px"></div>
|
||||
|
||||
<script type="module">
|
||||
import A from '../src/js/A.js';
|
||||
let aladin;
|
||||
A.init.then(() => {
|
||||
aladin = A.aladin('#aladin-lite-div', {survey: 'P/DSS2/red', target: 'M50', fov: 0.7});
|
||||
|
||||
var cat1 = A.catalog({readOnly: true});
|
||||
aladin.addCatalog(cat1);
|
||||
cat1.addSources(A.source(105.69239256, -8.45235969));
|
||||
cat1.addSources(A.source(105.70779763, -8.31350997));
|
||||
cat1.addSources(A.source(105.74242906, -8.34776709));
|
||||
|
||||
var cat2 = A.catalog({readOnly: false});
|
||||
aladin.addCatalog(cat2);
|
||||
cat2.addSources(A.source(105.79239256, -8.45235969));
|
||||
cat2.addSources(A.source(105.90779763, -8.31350997));
|
||||
cat2.addSources(A.source(105.54242906, -8.34776709));
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -22,11 +22,11 @@
|
||||
|
||||
/******************************************************************************
|
||||
* Aladin Lite project
|
||||
*
|
||||
*
|
||||
* File Catalog
|
||||
*
|
||||
*
|
||||
* Author: Thomas Boch[CDS]
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
import { Source } from "./Source.js"
|
||||
@@ -57,6 +57,7 @@ export let Catalog = (function() {
|
||||
this.shape = options.shape || "square";
|
||||
this.maxNbSources = options.limit || undefined;
|
||||
this.onClick = options.onClick || undefined;
|
||||
this.readOnly = options.readOnly || false;
|
||||
|
||||
this.raField = options.raField || undefined; // ID or name of the field holding RA
|
||||
this.decField = options.decField || undefined; // ID or name of the field holding dec
|
||||
@@ -82,10 +83,10 @@ export let Catalog = (function() {
|
||||
this.displayLabel = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.selectionColor = '#00ff00';
|
||||
|
||||
// create this.cacheCanvas
|
||||
|
||||
// create this.cacheCanvas
|
||||
// cacheCanvas permet de ne créer le path de la source qu'une fois, et de le réutiliser (cf. http://simonsarris.com/blog/427-increasing-performance-by-caching-paths-on-canvas)
|
||||
this.updateShape(options);
|
||||
|
||||
@@ -104,7 +105,7 @@ export let Catalog = (function() {
|
||||
|
||||
this.isShowing = true;
|
||||
};
|
||||
|
||||
|
||||
Catalog.createShape = function(shapeName, color, sourceSize) {
|
||||
if (shapeName instanceof Image || shapeName instanceof HTMLCanvasElement) { // in this case, the shape is already created
|
||||
return shapeName;
|
||||
@@ -119,7 +120,7 @@ export let Catalog = (function() {
|
||||
ctx.moveTo(sourceSize/2., 0);
|
||||
ctx.lineTo(sourceSize/2., sourceSize);
|
||||
ctx.stroke();
|
||||
|
||||
|
||||
ctx.moveTo(0, sourceSize/2.);
|
||||
ctx.lineTo(sourceSize, sourceSize/2.);
|
||||
ctx.stroke();
|
||||
@@ -128,7 +129,7 @@ export let Catalog = (function() {
|
||||
ctx.moveTo(0, 0);
|
||||
ctx.lineTo(sourceSize-1, sourceSize-1);
|
||||
ctx.stroke();
|
||||
|
||||
|
||||
ctx.moveTo(sourceSize-1, 0);
|
||||
ctx.lineTo(0, sourceSize-1);
|
||||
ctx.stroke();
|
||||
@@ -160,10 +161,10 @@ export let Catalog = (function() {
|
||||
ctx.lineTo(1, 1);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
|
||||
return c;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// find RA, Dec fields among the given fields
|
||||
//
|
||||
@@ -182,7 +183,7 @@ export let Catalog = (function() {
|
||||
if (Utils.isInt(raField) && raField<fields.length) { // raField can be given as an index
|
||||
raFieldIdx = raField;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( (field.ID && field.ID===raField) || (field.name && field.name===raField)) {
|
||||
raFieldIdx = l;
|
||||
break;
|
||||
@@ -195,7 +196,7 @@ export let Catalog = (function() {
|
||||
if (Utils.isInt(decField) && decField<fields.length) { // decField can be given as an index
|
||||
decFieldIdx = decField;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( (field.ID && field.ID===decField) || (field.name && field.name===decField)) {
|
||||
decFieldIdx = l;
|
||||
break;
|
||||
@@ -218,7 +219,7 @@ export let Catalog = (function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( ! decFieldIdx) {
|
||||
if (field.ucd) {
|
||||
var ucd = $.trim(field.ucd.toLowerCase());
|
||||
@@ -236,7 +237,7 @@ export let Catalog = (function() {
|
||||
var field = fields[l];
|
||||
var name = field.name || field.ID || '';
|
||||
name = name.toLowerCase();
|
||||
|
||||
|
||||
if ( ! raFieldIdx) {
|
||||
if (name.indexOf('ra')==0 || name.indexOf('_ra')==0 || name.indexOf('ra(icrs)')==0 || name.indexOf('_ra')==0 || name.indexOf('alpha')==0) {
|
||||
raFieldIdx = l;
|
||||
@@ -250,7 +251,7 @@ export let Catalog = (function() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,8 +263,8 @@ export let Catalog = (function() {
|
||||
|
||||
return [raFieldIdx, decFieldIdx];
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
Catalog.parseFields = function(fields, raField, decField) {
|
||||
// This votable is not an obscore one
|
||||
let [raFieldIdx, decFieldIdx] = findRADecFields(fields, raField, decField);
|
||||
@@ -379,13 +380,13 @@ export let Catalog = (function() {
|
||||
|
||||
this.selectSize = this.sourceSize + 2;
|
||||
|
||||
this.cacheCanvas = Catalog.createShape(this.shape, this.color, this.sourceSize);
|
||||
this.cacheCanvas = Catalog.createShape(this.shape, this.color, this.sourceSize);
|
||||
this.cacheSelectCanvas = Catalog.createShape(this.shape, this.selectionColor, this.selectSize);
|
||||
this.cacheHoverCanvas = Catalog.createShape(this.shape, this.hoverColor, this.sourceSize);
|
||||
|
||||
this.reportChange();
|
||||
};
|
||||
|
||||
|
||||
// API
|
||||
Catalog.prototype.addSources = function(sources) {
|
||||
// make sure we have an array and not an individual source
|
||||
@@ -507,7 +508,7 @@ export let Catalog = (function() {
|
||||
if (! this.sources) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (var k=0; k<this.sources.length; k++) {
|
||||
this.sources[k].select();
|
||||
}
|
||||
@@ -702,7 +703,7 @@ export let Catalog = (function() {
|
||||
Catalog.prototype.reportChange = function() {
|
||||
this.view && this.view.requestRedraw();
|
||||
};
|
||||
|
||||
|
||||
Catalog.prototype.show = function() {
|
||||
if (this.isShowing) {
|
||||
return;
|
||||
@@ -715,7 +716,7 @@ export let Catalog = (function() {
|
||||
|
||||
this.reportChange();
|
||||
};
|
||||
|
||||
|
||||
Catalog.prototype.hide = function() {
|
||||
if (! this.isShowing) {
|
||||
return;
|
||||
|
||||
@@ -256,7 +256,7 @@ export let View = (function () {
|
||||
if (fov !== this.oldFov) {
|
||||
const fovChangedFn = this.aladin.callbacksByEventName['zoomChanged'];
|
||||
(typeof fovChangedFn === 'function') && fovChangedFn(fov);
|
||||
|
||||
|
||||
// finally, save fov value
|
||||
this.oldFov = fov;
|
||||
}
|
||||
@@ -485,7 +485,7 @@ export let View = (function () {
|
||||
// do something here...
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
|
||||
|
||||
|
||||
let cutMinInit = null
|
||||
let cutMaxInit = null;
|
||||
@@ -618,7 +618,7 @@ export let View = (function () {
|
||||
let tables = selectedObjects.map((objList) => {
|
||||
// Get the catalog containing that list of objects
|
||||
let catalog = objList[0].getCatalog();
|
||||
|
||||
|
||||
let rows = objList.map((o) => {
|
||||
if (o instanceof Footprint) {
|
||||
return o.source;
|
||||
@@ -728,7 +728,7 @@ export let View = (function () {
|
||||
if (view.lastClickedObject) {
|
||||
view.aladin.measurementTable.hide();
|
||||
view.popup.hide();
|
||||
|
||||
|
||||
// Deselect the last clicked object
|
||||
if (view.lastClickedObject instanceof Ellipse || view.lastClickedObject instanceof Circle || view.lastClickedObject instanceof Polyline) {
|
||||
view.lastClickedObject.deselect();
|
||||
@@ -736,7 +736,7 @@ export let View = (function () {
|
||||
// Case where lastClickedObject is a Source
|
||||
view.lastClickedObject.actionOtherObjectClicked();
|
||||
}
|
||||
|
||||
|
||||
var objClickedFunction = view.aladin.callbacksByEventName['objectClicked'];
|
||||
(typeof objClickedFunction === 'function') && objClickedFunction(null);
|
||||
|
||||
@@ -770,7 +770,7 @@ export let View = (function () {
|
||||
|
||||
if (view.rightClick) {
|
||||
var onRightClickMoveFunction = view.aladin.callbacksByEventName['rightClickMove'];
|
||||
if (typeof onRightClickMoveFunction === 'function') {
|
||||
if (typeof onRightClickMoveFunction === 'function') {
|
||||
onRightClickMoveFunction(xymouse.x, xymouse.y);
|
||||
|
||||
// do not process further
|
||||
@@ -786,12 +786,12 @@ export let View = (function () {
|
||||
};
|
||||
const cx = (xymouse.x - cs.x) / view.catalogCanvas.clientWidth;
|
||||
const cy = -(xymouse.y - cs.y) / view.catalogCanvas.clientHeight;
|
||||
|
||||
|
||||
const offset = (cutMaxInit - cutMinInit) * cx;
|
||||
|
||||
|
||||
const lr = offset + (1.0 - 2.0 * cy) * cutMinInit;
|
||||
const rr = offset + (1.0 + 2.0 * cy) * cutMaxInit;
|
||||
|
||||
|
||||
if (lr <= rr) {
|
||||
selectedLayer.setCuts(lr, rr)
|
||||
}
|
||||
@@ -885,7 +885,7 @@ export let View = (function () {
|
||||
if (lastHoveredObject.isFootprint()) {
|
||||
view.requestRedraw();
|
||||
}
|
||||
|
||||
|
||||
if (typeof objHoveredStopFunction === 'function') {
|
||||
// call callback function to notify we left the hovered object
|
||||
var ret = objHoveredStopFunction(lastHoveredObject);
|
||||
@@ -1959,7 +1959,7 @@ export let View = (function () {
|
||||
sources = cat.getSources();
|
||||
for (var l = 0; l < sources.length; l++) {
|
||||
s = sources[l];
|
||||
if (!s.isShowing || !s.x || !s.y) {
|
||||
if (!s.isShowing || !s.x || !s.y || cat.readOnly) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1984,7 +1984,7 @@ export let View = (function () {
|
||||
}
|
||||
|
||||
let closest = null;
|
||||
|
||||
|
||||
footprints.forEach((footprint) => {
|
||||
// Hidden footprints are not considered
|
||||
if (footprint.isShowing && footprint.isInStroke(ctx, this, x, y)) {
|
||||
@@ -2022,7 +2022,7 @@ export let View = (function () {
|
||||
if (this.catalogs) {
|
||||
for (var k = 0; k < this.catalogs.length; k++) {
|
||||
let catalog = this.catalogs[k];
|
||||
|
||||
|
||||
let closest = this.closestFootprints(catalog.footprints, ctx, x, y);
|
||||
if (closest) {
|
||||
ctx.lineWidth = pastLineWidth;
|
||||
|
||||
Reference in New Issue
Block a user