From b09e61b44e36fa55068eb8e2c678fba28a50696c Mon Sep 17 00:00:00 2001
From: Tom Dwelly <dwelly@mpe.mpg.de>
Date: Tue, 20 Jul 2021 23:24:46 +0100
Subject: [PATCH] improve thumbs, update layout.

---
 js/speccy.js | 71 ++++++++++++++++++++++++++++++++++++++++++----------
 speccy.html  | 54 ++++++++++++++++++++++++++-------------
 2 files changed, 95 insertions(+), 30 deletions(-)

diff --git a/js/speccy.js b/js/speccy.js
index a932d42..bf7169d 100644
--- a/js/speccy.js
+++ b/js/speccy.js
@@ -29,8 +29,8 @@
 
 var canvas = document.getElementById("myCanvas");
 var ctx = canvas.getContext("2d", {'alpha': false});  
-ctx.canvas.width  = window.innerWidth * 0.96;
-ctx.canvas.height = window.innerHeight * 0.6;
+ctx.canvas.width  = Math.max(1000, window.innerWidth * 0.96);
+ctx.canvas.height = Math.max(500, window.innerHeight * 0.6);
 
 var specfile = "";
 //var submit_button = 0;
@@ -549,8 +549,8 @@ function changeTemplate() {
 
 
 function plotData() {
-    ctx.canvas.width  = window.innerWidth * 0.96;
-    ctx.canvas.height = window.innerHeight * 0.5;
+    ctx.canvas.width  = Math.max(1000, window.innerWidth * 0.96);
+    ctx.canvas.height = Math.max(500, window.innerHeight * 0.5);
     var xsize = canvas.width;
     var ysize = canvas.height; 
 
@@ -1317,7 +1317,8 @@ function getMousePosExact(canvas, evt) {
     };
 }
 
-document.body.addEventListener('mousedown', function (evt){
+//document.body.addEventListener('mousedown', function (evt){
+canvas.addEventListener('mousedown', function (evt){
     if(evt.button === rightclick  ){
 	//record the current cursor position;
 	mousePos_old = getMousePos(canvas, evt);
@@ -1355,7 +1356,8 @@ document.body.addEventListener('mousedown', function (evt){
     }
 }, false);
 
-document.body.addEventListener('mouseup', function (evt){
+//document.body.addEventListener('mouseup', function (evt){
+canvas.addEventListener('mouseup', function (evt){
     if(evt.button === rightclick )
     {
 	//record the current cursor position;
@@ -1441,10 +1443,15 @@ function convertMJDtoDate(mjd) {
 };
 
 function zoomStamps(inout){
+    // if (inout == "in") {
+    //     stamp_numpix = stamp_numpix * 0.8;
+    // } else if (inout == "out") {
+    //     stamp_numpix = stamp_numpix * 1.25;
+    // }
     if (inout == "in") {
-        stamp_numpix = stamp_numpix * 0.8;
+        stamp_scale = stamp_scale * 0.8;
     } else if (inout == "out") {
-        stamp_numpix = stamp_numpix * 1.25;
+        stamp_scale = stamp_scale * 1.25;
     }
     setupStamps(keyvals[keynames.indexOf("PLUG_RA")],
                 keyvals[keynames.indexOf("PLUG_DEC")]);
@@ -1453,13 +1460,13 @@ function zoomStamps(inout){
 function setupStamps(ra, dec){
     var _url_img_format = 'http://www.legacysurvey.org/viewer/jpeg-cutout/?ra=${ra}&dec=${dec}&pixscale=${scale}&layer=${layer}&size=${numpix}';
     var _url_link_format = 'http://www.legacysurvey.org/viewer?ra=${ra}&dec=${dec}&layer=${layer}&mark=${ra},${dec}&zoom=18';
-    var _inner_format = "<a href='${url_link}'><img class='picture' title='${title}' src='${url_img}' width='150px'></a>";
+    var _inner_format = "<a href='${url_link}' target='_blank'><img class='picture' title='${title}' src='${url_img}' width='150px' height='150px' alt='go to viewer'></a>";
 
-    var td = document.getElementById("thumb_panel_info");
-    td.innerHTML = "Image size:<br>" + (Math.floor(stamp_numpix)*stamp_scale).toFixed(1) + " arcsec";
+    var el = document.getElementById("thumb_span_zoom");
+    el.innerHTML = "Image size:<br>" + (Math.floor(stamp_numpix)*stamp_scale).toFixed(1) + " arcsec";
     
-    var layers = ["galex", "sdssco", "ls-dr9", "hsc2", "unwise-neo6", "vlass"];
-    for(l=0;l<layers.length;l++){
+    var layers = ["galex", "sdss", "ls-dr9", "hsc2", "unwise-neo6", "vlass"];
+    for(var l=0;l<layers.length;l++){
         var layer = layers[l];
         var td = document.getElementById("thumb_panel_" + layer);
         var _url_img = _url_img_format.replace(/\${ra}/g, ra);
@@ -1472,10 +1479,48 @@ function setupStamps(ra, dec){
         _url_link = _url_link.replace(/\${dec}/g, dec);
         _url_link = _url_link.replace(/\${layer}/g, layer);
         
+        var _inner = _inner_format.replace(/\${title}/g, 'Cutout: ' + layer);
+        _inner = _inner.replace(/\${url_img}/g, _url_img);
+        _inner = _inner.replace(/\${url_link}/g, _url_link);
+        td.innerHTML = _inner;
+    }
+
+
+
+    // now use the hips2fits service
+
+    // http://alasky.u-strasbg.fr/hips-image-services/hips2fits
+    // https://aladin.u-strasbg.fr/hips/list
+
+    var _url_img_format = 'https://alasky.u-strasbg.fr/hips-image-services/hips2fits?hips=${layer}&width=${numpix}&height=${numpix}&fov=${size_deg}&projection=TAN&ra=${ra}&dec=${dec}&format=jpg';
+    var _url_link_format =  'http://aladin.unistra.fr/AladinLite/?target=${ra}${dec}&fov=0.05&survey=${layer}';
+
+    var layers = [{'name': 'xmm', 'hips': 'ESAVO/P/XMM/EPIC-RGB'},
+                  {'name': 'csc', 'hips': 'cxc.harvard.edu/P/cda/hips/allsky/rgb'},
+                  {'name': '2mass', 'hips': 'CDS/P/2MASS/color'},
+                  {'name': 'dss2', 'hips': 'CDS/P/DSS2/color'},
+                  {'name': 'nvss', 'hips': 'CDS/P/NVSS'},
+                  {'name': 'ps1', 'hips': 'CDS/P/PanSTARRS/DR1/color-i-r-g'}];
+    for(var l=0; l<layers.length; l++){
+        var layer = layers[l];
+        var td = document.getElementById("thumb_panel_" + layer['name']);
+        var _url_img = _url_img_format.replace(/\${ra}/g, Number(ra).toFixed(7));
+        var size_deg = Math.floor(stamp_numpix) * stamp_scale / 3600.0;
+        _url_img = _url_img.replace(/\${dec}/g, Number(dec).toFixed(7));
+        _url_img = _url_img.replace(/\${layer}/g, layer['hips']);
+        _url_img = _url_img.replace(/\${size_deg}/g, size_deg);
+        _url_img = _url_img.replace(/\${numpix}/g, Math.floor(stamp_numpix));
+
+        var _url_link = _url_link_format.replace(/\${ra}/g, Number(ra).toFixed(7));
+        var dec_signed = (dec >= 0.0 ? '-'  : '' ) + Number(dec).toFixed(7); 
+        _url_link = _url_link.replace(/\${dec}/g, dec_signed);
+        _url_link = _url_link.replace(/\${layer}/g, layer['hips']);
+
         var _inner = _inner_format.replace(/\${title}/g, 'Cutout: ' + layer);
         _inner = _inner.replace(/\${url_img}/g, _url_img);
         _inner = _inner.replace(/\${url_link}/g, _url_link);
         td.innerHTML = _inner;
 
     }
+    
 }
diff --git a/speccy.html b/speccy.html
index 2bfe84d..edbd14c 100644
--- a/speccy.html
+++ b/speccy.html
@@ -53,6 +53,14 @@
              border-collapse: collapse;
              border: 1px solid gray;
          }
+         td.thumb {
+             min-width: 150px;
+             text-align: center;
+         }
+         th {
+             text-align: center;
+             background-color: #c5ffe5;
+         }
         </style>
     </head>
 
@@ -313,25 +321,37 @@
         <td  colspan="5">
             <table>
                 <tr>
-                    <td>Cutouts</td>
-                    <td>GALEX</td>
-                    <td>SDSS gri</td>
-                    <td>ls dr9 grz</td>
-                    <td>HSC dr2 gri</td>
-                    <td>unWISE W1W2</td>
-                    <td>VLASS 1.4GHz</td>
-                    <td>Zoom</td>
+                    <th class="thumb">XMM</td>
+                    <th class="thumb">Chandra</td>
+                    <th class="thumb">GALEX</td>
+                    <th class="thumb">DSS2</td>
+                    <th class="thumb">SDSS gri</td>
+                    <th class="thumb">PS1dr1 gri</td>
+                    <th class="thumb">LSdr9 grz</td>
+                    <th class="thumb">HSCdr2 grz</td>
+                    <th class="thumb">2MASS JHK</td>
+                    <th class="thumb">unWISE W1W2</td>
+                    <th class="thumb">VLASS 2-4GHz</td>
+                    <th class="thumb">NVSS 1.4GHz</td>
+                    <th class="thumb">Zoom</td>
                 </tr>
                 <tr>
-                    <td id="thumb_panel_info" style="min-width:50px"></td>
-                    <td id="thumb_panel_galex" style="min-width:50px"></td>
-                    <td id="thumb_panel_sdssco" style="min-width:50px"></td>
-                    <td id="thumb_panel_ls-dr9" style="min-width:50px"></td>
-                    <td id="thumb_panel_hsc2" style="min-width:50px"></td>
-                    <td id="thumb_panel_unwise-neo6" style="min-width:50px"></td>
-                    <td id="thumb_panel_vlass" style="min-width:50px"></td>
-                    <td id="thumb_panel_zoom" style="min-width:50px">
-                        <input type="button" onclick="zoomStamps('in')" value="Zoom in" />&nbsp;
+                    <td class="thumb" id="thumb_panel_xmm" ></td>
+                    <td class="thumb" id="thumb_panel_csc" ></td>
+                    <td class="thumb" id="thumb_panel_galex"></td>
+                    <td class="thumb" id="thumb_panel_dss2"></td>
+                    <td class="thumb" id="thumb_panel_sdss"></td>
+                    <td class="thumb" id="thumb_panel_ps1"></td>
+                    <td class="thumb" id="thumb_panel_ls-dr9"></td>
+                    <td class="thumb" id="thumb_panel_hsc2"></td>
+                    <td class="thumb" id="thumb_panel_2mass"></td>
+                    <td class="thumb" id="thumb_panel_unwise-neo6"></td>
+                    <td class="thumb" id="thumb_panel_vlass"></td>
+                    <td class="thumb" id="thumb_panel_nvss"></td>
+                    <td class="thumb" id="thumb_panel_zoom">
+                        <span id="thumb_span_zoom"></span><br><br>
+                        <input type="button" onclick="zoomStamps('in')" value="Zoom in" />
+                        <br><br>
                         <input type="button" onclick="zoomStamps('out')" value="Zoom out" />
                     </td>
                 </tr>
-- 
GitLab