Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read only catalog option #117

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions examples/al-cat-read-only.html
Original file line number Diff line number Diff line change
@@ -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>
47 changes: 24 additions & 23 deletions src/js/Catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

/******************************************************************************
* Aladin Lite project
*
*
* File Catalog
*
*
* Author: Thomas Boch[CDS]
*
*
*****************************************************************************/

import { Source } from "./Source.js"
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -160,10 +161,10 @@ export let Catalog = (function() {
ctx.lineTo(1, 1);
ctx.stroke();
}

return c;
};


// find RA, Dec fields among the given fields
//
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -218,7 +219,7 @@ export let Catalog = (function() {
}
}
}

if ( ! decFieldIdx) {
if (field.ucd) {
var ucd = $.trim(field.ucd.toLowerCase());
Expand All @@ -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;
Expand All @@ -250,7 +251,7 @@ export let Catalog = (function() {
continue;
}
}

}
}

Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand All @@ -715,7 +716,7 @@ export let Catalog = (function() {

this.reportChange();
};

Catalog.prototype.hide = function() {
if (! this.isShowing) {
return;
Expand Down
26 changes: 13 additions & 13 deletions src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -485,7 +485,7 @@ export let View = (function () {
// do something here...
e.preventDefault();
}, false);


let cutMinInit = null
let cutMaxInit = null;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -728,15 +728,15 @@ 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();
} else {
// Case where lastClickedObject is a Source
view.lastClickedObject.actionOtherObjectClicked();
}

var objClickedFunction = view.aladin.callbacksByEventName['objectClicked'];
(typeof objClickedFunction === 'function') && objClickedFunction(null);

Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down