Files
aladin-lite/bug-tracking/simple-selection.html
2014-10-23 07:07:36 +00:00

94 lines
3.0 KiB
HTML

<!doctype html>
<html>
<head><title>Aladin lite - example of sources selection</title></head>
<body>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<b>1. Click on <input type="button" id="selectBtn" value="Select" /></b><br/>
<b>2. Select some sources in Aladin Lite</b><br/>
<link rel="stylesheet" href="http://aladin.u-strasbg.fr/AladinLite/api/v2/latest/aladin.min.css" />
<div id="aladinDiv" style="width: 500px; height: 500px"></div>
<div id="explain"></div>
<script type="text/javascript" src="http://aladin.u-strasbg.fr/AladinLite/api/v2/latest/aladin.min.js" charset="utf-8"></script>
<script>
var aladin = $.aladin('#aladinDiv', {target: 'M45', zoom: 1.4, cooFrame: 'J2000', showControl: true, survey: 'P/DSS2/color', showReticle: false});
$(document).ready(function() {
// create a catalogue from a VOTable
aladin.addCatalog(aladin.createCatalogFromVOTable('http://alasky.u-strasbg.fr/cgi/simbad-flat/simbad-cs.py?target=M45&SR=40.0&format=votable&SRUNIT=arcmin'));
// function triggered when some objects are selected
aladin.on('select', function(objects) {
var html = "<b>" + objects.length + " sources selected </b>: <ul>";
for (var k=0; k<objects.length; k++) {
html += '<li>' + objects[k].data.MAIN_ID + ' (' + objects[k].data.OTYPE + ')</li>';
}
html += '</ul>';
$('#explain').html(html);
});
$('#selectBtn').click(function() {
aladin.select();
});
var catalog = aladin.createCatalog();
aladin.addCatalog(catalog);
// first, retrieve all sources
sources = [];
var trs = $('#dataTable tr');
for (var i=1; i<trs.length; i++) {
var ra = trs.eq(i).find('td').eq(8).html();
var dec = trs.eq(i).find('td').eq(9).html();
sources.push(aladin.createSource(ra, dec));
}
catalog.addSources(sources);
// listener on checkboxes
var cbs = $('#dataTable tr td .displaySource');
for (var i=0; i<cbs.length; i++) {
$(cbs[i]).change(function () {
var idx = parseInt($(this).parent().find('a em').html());
var isChecked = $(this).is(':checked');
var source = catalog.getSource(idx-1);
if (isChecked) {
source.show();
}
else {
source.hide();
}
});
}
var curSource;
$('#dataTable tr').mouseenter(function() {
//console.log($('#dataTable tr').index(this));
var idx = parseInt($(this).find('td').eq(0).find('a em').html());
if (idx>0) {
idx = idx -1;
if (curSource) {
curSource.deselect();
}
var source = catalog.getSource(idx);
source.select();
curSource = source;
}
});
$('#dataTable tr').mouseleave(function() {
if (curSource) {
curSource.deselect();
}
});
});
</script>
</body></html>