olqv.ejs 83.6 KB
Newer Older
1
2
<!DOCTYPE html>
<html>
3

4
5
6
7
8
9
10
<head>
  <title><%= title %></title>

  <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />

  <!--script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" type="text/javascript"></script>
11
12
13
14
15
16
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
    integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
    crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"
    integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T"
    crossorigin="anonymous"></script>
17
  <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.js"></script>
18
19
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
    integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
20
21
  <script src="https://code.highcharts.com/highcharts.src.js"></script>
  <script src="https://code.highcharts.com/modules/boost.js"></script>
22
23
24
25
  <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
  <link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css">

  <link rel="stylesheet" type="text/css" href="/stylesheets/overlay.css">
26
  <link rel="stylesheet" type="text/css" href="/stylesheets/olqv.css">
27
28
29
30

  <script src="../javascript/FITSHeaderTable.js"></script>
  <script src="../javascript/olqv_utils.js"></script>

31
  <!--  <script src="https://openlayers.org/en/v4.6.4/build/ol.js" type="text/javascript"></script> -->
32
  <!-- Conditional code generation -->
33
  <%if(useSAMP){%>
34
  <script src="../javascript/samp.js"></script>
35
  <script src="../javascript/samp_utils.js"></script>
36
  <%}%>
37
  <!-- End of conditional code generation --> 
38
39
40
41
42
43
44
</head>

<body>

<div id="loading"></div>
<div id="FITSHDR" class="overlay" style="overflow:scroll"></div>
<div class="pos-f-t">
45
  <div class="collapse" id="sampRegistry"></div>
46
47
48
  <div class="collapse" id="navbarToggleExternalContent">
    <div class="bg-dark p-4">
<% if (renderingCapabilities) { %>
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <ul class="list-group list-group-horizontal">
      <li class="list-group-item ">
        <label for="LUTSelector">LUTs</label>
        <select name="LUTs" class="form-control" id="LUTSelector">
          <% renderingCapabilities["luts"].forEach(function(lut) { %>
          <option> <%=lut%></option>
          <% }) %>
        </select>
      </li>
      <li class="list-group-item ">
        <label for="ITTSelector">ITTs</label>
        <select class="form-control" id="ITTSelector">
          <% renderingCapabilities["itts"].forEach(function(itt) { %>
          <option> <%=itt%></option>
          <% }) %>
        </select>
      </li>
      <li class="list-group-item ">
        <label for="VideoModeSelector">Video mode</label>
        <select class="form-control" id="VideoModeSelector">
70
          <% renderingCapabilities["vmodes"].forEach(function(vmode) { %>
71
          <option> <%=vmode%></option>
72
          <% }) %>
73
74
75
76
77
78
79
80
        </select>
      </li>
      <li class="list-group-item">
        <a class="form-control" id="rccap" class="btn btn-primary" href="#" role="button">Apply</a>
      </li>
    </ul>
  </nav>
  </div>
81

82
  <%}%>
83
84
85
86
87
88
    </div>
  </div>
  <nav class="navbar navbar-dark bg-dark">
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
89
    <img src="../samphub.png" style="width:30px; height:30px" data-toggle="collapse" data-target="#sampRegistry" aria-controls="sampRegistry" aria-expanded="false" aria-label="Toggle navigation"/>
90
    <!--<div><a id="jupyter" href="#" target="_blank"><img src="../jupyter.png" style="width:30px; height:30px" title="jupyter"/></a></div>-->
91
92
    <a href="#" class="btn btn-link btn-sm" onclick="viewIn3D(); return false;"> 3D representation </a>
    <div><a href="http://artemix.obspm.fr/fits/browse" target="_blank" class="btn btn-link btn-sm">See more FITS files...</a></div>
93
94
95
96
    <div id="cubeInfos" style="font-size:15px; color: white"></div>
  </nav>
</div>
<div>
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<div class="container chart-container">
      <div class="row">
        <div class="col">
          <div id="external_mouse_position_1"></div>
        </div>
        <div class="col">
          <div id="publish_spectrum"></div>
        </div>
      </div>
      <div class="row">
        <div class="col chart-img">
          <div id="slice" class="map" style="background-color:darkblue"></div>
        </div>
        <div class="col chart-plot">
          <button id="zoomout">-</button>
          <button id="zoomin">+</button>
          <button id="zoomreset">Reset</button>
          <div id="spectrum"></div>  
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div id="external_mouse_position_2"></div>
        </div>
        <div class="col">
          <div id="publish_summedpixelsspectrum"></div>
        </div>
      </div>
      <div class="row">
        <div class="col chart-img">
          <div id="summedslices" class="map"></div>
        </div>
        <div class="col chart-plot">
          <div id="summedpixelsspectrum"></div>
        </div>
      </div>
    </div>
134

135
136
137
138
139
140
141
142
143
144
145
146
147
    <div class="container chart-container hidden">
      <div class="row">
        <div class="col">
          <canvas id="hiddenSlice"></canvas>
        </div>
        <div class="col">
          <canvas id="hiddenSummedSlices"></canvas>
        </div>
      </div>
    </div> 
 

  <div class="hidden">
148
149
150
151
152
153
    <div id="popup" class="ol-popup">
      <a href="#" id="popup-closer" class="ol-popup-closer"></a>
      <div id="popup-content"></div>
    </div>
  </div>

ba yaye-awa's avatar
ba yaye-awa committed
154
  <!-- Modal for samp cassis-->
155
  <div class="modal fade hidden" id="sampModal" role="dialog">
156
157
158
159
160
161
162
163
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Send spectrum by SAMP (Cassis)</h4>
        </div>
        <div class="modal-body">
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
          <p>
            This link is intended to send the current artemix spectrum to Cassis tool, 
            or any other tool that runs with the SAMP protocol and accepts our file fits format.
          </p>
          <p>
            For the transfer to work, Check that Cassis is running.
          </p>          
          <h3>How to launch Cassis</h3>
          <p>
            <strong>- Cassis with command line:</strong>
          </p>
          <p>
            Open a terminal and run: javaws http://cassis.irap.omp.eu/online/cassis.jnlp
          </p>
          <p>
            <strong>- Cassis online:</strong>
          </p>
181
182
          <ul>
            <li>1- Go to the Cassis <a href="http://cassis.irap.omp.eu/?page=installation"> website</a></li>
183
184
185
186
187
188
189
190
191
192
            <li>2- Use Cassis online application or download the latest version </li>
          </ul>
          <p>
            If you encounter a problem during the installation, check that you have the correct Java version 
            compatible with Cassis, and allow the installation in your computer. 
            Please read <a href="images/enablejava.png">here</a> on how to do with a Mac.
          </p>
          <p>
            In case you encounter any problem with Cassis please contact the Cassis project manager <a href="#">Jean-Michel.Glorian{at}irap.omp.eu</a>
         </p>
193
194
195
196
197
198
199
	</div>
	<div class="modal-footer">
	  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
200

ba yaye-awa's avatar
ba yaye-awa committed
201
  <!-- Modal for samp aladin -->
ba yaye-awa's avatar
ba yaye-awa committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
  <div class="modal fade" id="sampModalAladin" role="dialog" style="display:none">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Send image by SAMP (Aladin)</h4>
        </div>
        <div class="modal-body">
          <p>This link is intended to send the current Artemix image to Aladin tool, or any other tool that runs with the SAMP protocol and accepts our file png format.
          </br></br>
          For the transfer to work, Check that Aladin is running.</br></br>

          How to launch Aladin</br>
          <strong>- Aladin with command line:</strong></br>
          Open a terminal and run: javaws https://aladin.u-strasbg.fr/java/nph-aladin.pl</br></br>
          <strong>- Aladin online:</strong></br>
          <ul>
            <li>1- Go to the Aladin <a href="https://aladin.u-strasbg.fr/java/nph-aladin.pl?frame=downloading"> website</a></li>
            <li>2- Use Aladin online application or download the latest version </li></ul>
          If you encounter a problem during the installation, check that you have the correct Java version compatible with Aladin, and allow the installation in your computer. Found <a href="images/enablejava.png">here</a> how to do with Mac </br></br>
          In case of problems with Aladin please contact the Aladin team cds-question AT <a href="#"> unistra.fr?Subject=Aladin</a></p>
	</div>
	<div class="modal-footer">
	  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
231
232
233
</body>
    <script>

234
235
      var ENTER = function () { console.log(arguments.callee.name + ": entering."); };
      var EXIT = function () { console.log(arguments.callee.name + ": exiting."); };
236

237
238
239
    <%if (useSAMP) {%>
  var sAMPPublisher = null;
  <%}%>
240

241
  var ROI;
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
      var summedPixelsSpectrumChart;
      var spectrumChart;
      var viewIn3D = function () {
        window.open("getYtObj?relFITSFilePath=" + relFITSFilePath + "&iRA0=" + ROI.iRA0 + "&iRA1=" + ROI.iRA1 + "&iDEC0=" + ROI.iDEC0 + "&iDEC1=" + ROI.iDEC1 + "&iFREQ0=" + ROI.iFREQ0 + "&iFREQ1=" + ROI.iFREQ1);
      };

      var showLoaderAction = function(enable){
        if(enable){
          document.getElementById('loading').style.display = 'block';
        }else{
          document.getElementById('loading').style.display = 'none';
        }
      }

      var handleEvent = function (evt) {
        console.log(JSON.stringify(evt, null, 4));
        return true;
      };

      /**
        Add a series where Y=0 in the given chart
      */
      function addYAxisSeries(chart) {
        chart.addSeries({
          lineWidth: 1,
          enableMouseTracking: false,
          showInLegend: false,
          color: "#000000",
          marker: {
            enabled: false
          },
          data: [[chart.xAxis[0].dataMin, 0], [chart.xAxis[0].dataMax, 0]]
274
        });
275

276
      }
277

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
      /**
        calculate the value displayed as title of summed average spectrum
        avgSpectrum array is reversed if data are radial velocities and 
        cdelt3 < 0
      */
      function getSummedSpectrumTitle(avgSpectrum, imin, imax, cdelt3prim) {
        let result = 0;
        if (_ctype3 === 'VRAD' && _cdelt3 < 0) {
          let copy = (x) => x;
          let arraycopy = avgSpectrum.map(copy);
          result = sumArr(arraycopy.reverse(), imin, imax, cdelt3prim);
        } else {
          result = sumArr(avgSpectrum, imin, imax, cdelt3prim);
        }
        return result / unitRescale(summedPixelsSpectrumUnit(_bunit));
293
294
      }

295
296
297
298
299
300
301
302
303
304
305
306
307
      function getCalculatedIndex(value) {
        let result = 0;
        if (_ctype3 === 'VRAD') {
          let step1 = (unitFactor[defaultOutputUnit[_ctype3]] / unitFactor[getCunit3()]) / _cdelt3;
          result = Math.abs(value * step1) - _crval3 + _crpix3 - 1;
        } else if (_ctype3 === 'FREQ') {
          // if ctype is FREQ we have to read defaultOutputUnit['VRAD']
          let step1 = v2f(value * unitFactor[defaultOutputUnit['VRAD']], _restfreq);
          let step2 = (step1 - _crval3) / _cdelt3;
          result = step2 + _crpix3 - 1;
        }
        return Math.round(result);
      }
308

309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
      //
      // A object to mark informations related to a position
      // in a popup bow located close to the position passed
      // as a parameter.
      //
      function LastClickMarker(map) {
        var _map = map;
        var _overlay = null;
        var _container = document.getElementById('popup');
        var _content = document.getElementById('popup-content');
        var _closer = document.getElementById('popup-closer');

        var _lastChanIndex = null;
        var _lastCoordinate = null;
        var _lastRADEC = null;
        var _lastFluxDensity = null;

        // popup creation and addition to an ol overlay to the map passed
        // as a parameter.
        //
        var _popupLastClickInfos = function () {
          if (_overlay == null) {
            /**
            * Create an overlay to anchor the popup to the map.
            */
            _overlay = new ol.Overlay({
              element: _container,
              autoPan: true,
              autoPanAnimation: {
                duration: 250
              }
            });
341

342
343
344
345
346
347
348
349
350
            /**
            * Add a click handler to hide the popup.
            * @return {boolean} Don't follow the href.
            */
            _closer.onclick = function () {
              _overlay.setPosition(undefined);
              _closer.blur();
              return false;
            };
351

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
            _map.addOverlay(_overlay);
          }
        };

        //
        // update the content of the popup by using the informations
        // stored in _lastCoordinate, _lastRADEC and _lastFluxDensity
        //
        var _updateLastClickInfos = function () {
          if (_lastCoordinate == null) return;
          _content.innerHTML = 'Chan#' + _lastChanIndex + '<br>' + 'x = ' + _lastCoordinate[0].toFixed(0) + ', y = ' + _lastCoordinate[1].toFixed(0) + '<br>' +
            'RA=' + _lastRADEC['RA'] + '<br>' +
            'DEC=' + _lastRADEC['DEC'] + '<br>' +
            'Value=' + Number(_lastFluxDensity).toExponential(4);

          _overlay.setPosition(_lastCoordinate);
        }

        //
        // public method to register the values to be displayed
        // in the popup and update its content.
        //
        this.setPositionAndFluxDensity = function (data) {
          console.log("this.setPosition = function(coordinate) { : entering");

          _lastChanIndex = data["chanIndex"]
          _lastCoordinate = data["coordinate"];
          _lastRADEC = data["RADEC"];
          _lastFluxDensity = data["fluxDensity"];

          _updateLastClickInfos();

          console.log("this.setPosition = function(coordinate) { : exiting");
        };
386

387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
        //
        // public method to register the fluxDensity value passed as a parameter
        // and update the popup content accordingly.
        //
        this.setFluxDensity = function (fluxDensity, sliceIndex) {
          console.log("this.setFluxDensity = function(fluxDensity)  { : entering");
          _lastFluxDensity = fluxDensity;
          _lastChanIndex = sliceIndex;
          _updateLastClickInfos();
          console.log("this.setFluxDensity = function(fluxDensity)  { : exiting");
        };

        // create our popup.
        _popupLastClickInfos();
      };

      /*
      ** A function to start/stop an hold-on animation while
      ** an image is prepared by the server until it serves it to the client.
      ** This function is dedicated to be passed a the value
      ** of the option imageLoadFunction of an ImageStatic constructor.
      **
      */
      var _image = null;
      function _onProgress(event) {
        if (event.lengthComputable) {
          var percentComplete = (event.loaded / event.total) * 100;
          console.log("Transfert: %d%%", percentComplete);
        } else {
          // Impossible de calculer la progression puisque la taille totale est inconnue
        }
      }
419

420
421
422
423
424
425
426
427
428
429
      function _onError(event) {
        console.error("Error  " + event.target.status + " during the transfert.");
      }

      function _onLoad(event) {
        // Ici, this.readyState  XMLHttpRequest.DONE .
        if (this.status === 200) {
          console.log("Transfert done - " + this.responseText.length + "bytes.");
          var _srcURI = "data:image/png," + this.responseText;
          console.log("_srcURI=" + _srcURI);
430

431
432
433
434
435
436
          _image.getImage().src = _srcURI;
        } else {
          console.log("Response status: %d (%s)", this.status, this.statusText);
        }
        showLoaderAction(false);
      }
437

438
439
440
441
442
443
444
445
446
447
448
449
450
      let hidden_canvas_1 = document.getElementById("hiddenSlice");
      let hidden_canvas_2 = document.getElementById("hiddenSummedSlices");
      //
      //
      // What happends when the image to be displayed in 'image'
      // is loaded. To be used for _map_1
      //
      var _imageLoadFunction_1 = function (image, src) {
        console.log("_imageLoadFunction_1 : entering");
        showLoaderAction(true);
        image.getImage().addEventListener('load', function () {
          showLoaderAction(false);
          hidden_canvas_1.getContext('2d').drawImage(image.getImage(), 0, 0);
451
452
        });

453
454
455
456
457
        image.getImage().src = src;
        image.getImage().crossOrigin = "Anonymous";

        console.log("_imageLoadFunction_1 : exiting");
      };
458

459
460
461
462
463
464
465
466
467
468
469
      //
      // What happends when the image to be displayed in 'image'
      // is loaded. To be used for _map_2
      //
      var _imageLoadFunction_2 = function (image, src) {
        console.log("_imageLoadFunction_2 : entering");
        showLoaderAction(true);
        image.getImage().addEventListener('load', function () {
          showLoaderAction(false);
          hidden_canvas_2.getContext('2d').drawImage(image.getImage(), 0, 0);
        });
470

471
472
        image.getImage().src = src;
        image.getImage().crossOrigin = "Anonymous";
473

474
475
        console.log("_imageLoadFunction_2 : exiting");
      };
476
477


478
479
480
481
482
      var SAMPPNGPublishControl = (function (Control) {
        function SAMPPNGPublishControl(opt_options) {
          var options = opt_options || {};
          var button = document.createElement('button');
          button.innerHTML = '&#8663';
483

484
485
486
          var element = document.createElement('div');
          element.className = 'samp-publish-png ol-unselectable ol-control';
          element.appendChild(button);
487

488
489
490
491
          Control.call(this, {
            element: element,
            target: options.target
          });
492

493
494
495
496
          this.handlePublish = function () { ; }
          button.addEventListener('click', this.handlePublish.bind(this), false);
          this.setHandler = function (handler) { console.log("Changing handler"); button.addEventListener('click', handler.bind(this), false) };
        }
497

498
499
500
        if (Control) SAMPPNGPublishControl.__proto__ = Control;
        SAMPPNGPublishControl.prototype = Object.create(Control && Control.prototype);
        SAMPPNGPublishControl.prototype.constructor = SAMPPNGPublishControl;
501

502
503
        return SAMPPNGPublishControl;
      }(ol.control.Control));
504
505


506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
      /*
      ** A class definition for the object in charge of displaying
      ** two imagee - one for a slice ( at a given frequency ), one for the sum of
      ** slices ( belonging to a frequency range) of a data cube.
      */
      var _canvasContext_1 = null;

      function SliceViewer(relFITSFilePath, width, height, RADECRangeInDegrees, FITSHeader, divSlice, divSummedSlices) {
        console.log("SliceViewer : entering");

        let _relFITSFilePath = null;
        let _width;
        let _height;
        let _extent;

        let _divSlice;
        let _divSummedSlices;

        let _projection_1;
        let _map_controls_1;
        let _map_1;
        let _im_layer_1;
        let _graticule_1;
        let _data_steps_1;

        let _lastClickMarker_1;

        let _projection_2;
        let _map_controls_2;
        let _select_2;
        let _map_2;
        let _im_layer_2;
        let _graticule_2;
        let _data_steps_2;
        let _box_source_2;
        let _box_layer_2;
        let _dragBox_2;
        let _box_2_extent;
        let _selected_box_2;

        var _sliceIndex;
547

548
549
550
551
552
        _relFITSFilePath = relFITSFilePath;
        _width = width;
        _height = height;
        _divSlice = divSlice;
        _divSummedSlices = divSummedSlices;
553

554
555
        hidden_canvas_1.width = _width;
        hidden_canvas_1.height = _height;
556

557
558
        hidden_canvas_2.width = _width;
        hidden_canvas_2.height = _height;
559

560
        _extent = [0, 0, _width - 1, _height - 1];
561

562
563
        let _ra0 = RADECRangeInDegrees[0][0];
        let _ra1 = RADECRangeInDegrees[1][0];
564

565
        console.log("_ra0 = " + DecDeg2HMS(_ra0) + " _ra1 =" + DecDeg2HMS(_ra1));
566

567
568
        let _dec0 = RADECRangeInDegrees[0][1];
        let _dec1 = RADECRangeInDegrees[1][1];
569

570
        console.log("_dec0 = " + DecDeg2HMS(_dec0) + " _dec1 =" + DecDeg2HMS(_dec1));
571

572
573
        let _raLabelFormatter = new raLabelFormatter(_extent[0], _extent[2], _ra0, _ra1);
        let _decLabelFormatter = new decLabelFormatter(_extent[1], _extent[3], _dec0, _dec1);
574

575
576
577
578
579
580
581
582
583
584
585
586
587
        let _coordinateFormatType_1 = function (olc) {
          let result;
          var ctx = hidden_canvas_1.getContext('2d');
          var pixelAtPosition = ctx.getImageData(olc[0], height - olc[1], 1, 1).data;
          if (pixelAtPosition) {
            var data_steps_index = pixelAtPosition.slice(0, 3).join('_');
            result = 'Chan#' + _sliceIndex + ", " + _raLabelFormatter.format(olc[0]) + ', ' + _decLabelFormatter.format(olc[1]) + ', ' + (_data_steps_1[data_steps_index]).toExponential(2) + " " + _bunit;
          }
          else {
            result = "???";
          }
          return result;
        };
588

589
590
591
592
593
594
595
596
597
598
599
600
601
        let _coordinateFormatType_2 = function (olc) {
          let result;
          var ctx = hidden_canvas_2.getContext('2d');
          var pixelAtPosition = ctx.getImageData(olc[0], height - olc[1], 1, 1).data;
          if (pixelAtPosition) {
            var data_steps_index = pixelAtPosition.slice(0, 3).join('_');
            result = _raLabelFormatter.format(olc[0]) + ', ' + _decLabelFormatter.format(olc[1]) + ', ' + _data_steps_2[data_steps_index].toExponential(1) + " " + summedPixelsUnit(_bunit);
          }
          else {
            result = "???";
          }
          return result;
        };
602

603
        this.getSliceIndex = function () { return sliceIndex; }
604

605
606
607
608
609
610
611
612
613
614
615
616
617
        this.getFluxDensity = function (pixelCoordinate) {
          let result = null;
          var ctx = hidden_canvas_1.getContext('2d');
          var pixelAtPosition = ctx.getImageData(pixelCoordinate[0], height - pixelCoordinate[1], 1, 1).data;
          if (pixelAtPosition) {
            var data_steps_index = pixelAtPosition.slice(0, 3).join('_');
            result = _data_steps_1[data_steps_index];
          }
          else {
            result = "???";
          }
          return result;
        };
618

619
620
621
        this.getRADEC = function (pixelCoordinate) {
          return { 'RA': _raLabelFormatter.format(pixelCoordinate[0]), 'DEC': _decLabelFormatter.format(pixelCoordinate[1]) }
        };
622

623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
        /*
        ** The slice display
        */
        _projection_1 = new ol.proj.Projection({
          code: 'local_image',
          units: 'pixels',
          extent: _extent,
          worldExtent: [..._extent]
        });

        _map_controls_1 = [
          new ol.control.MousePosition({
            className: 'custom-mouse-position',
            target: document.getElementById('external_mouse_position_1'),
            undefinedHTML: '',
            coordinateFormat: _coordinateFormatType_1
          }),
          new ol.control.MousePosition({
            className: 'custom-mouse-position',
            target: document.getElementById('external_mouse_position_2'),
            undefinedHTML: '',
            coordinateFormat: _coordinateFormatType_2
          }),
          new ol.control.FullScreen()
        ];
      <%if (useSAMP) {%>
          let _sAMPPNGPublishControl_1 = new SAMPPNGPublishControl();
          _sAMPPNGPublishControl_1.setHandler(sAMPPublisher.sendPNGSlice);
  <%}%>
          _map_1 = new ol.Map({
            target: _divSlice,
            view: new ol.View({
              projection: _projection_1,
              center: ol.extent.getCenter(_extent),
              resolution: hidden_canvas_1.width / 512
            })
              <%if(useSAMP) {%>
  ,
                controls: ol.control.defaults().extend([
                  _sAMPPNGPublishControl_1
                ])
                  <%}%>
665
666
667
668
669
670
671
672
673
674
675
      });

      _graticule_1 = new ol.Graticule({
        showLabels: true,
        strokeStyle: new ol.style.Stroke({
          color: 'rgba(0,0,0,0.9)',
          width: 1,
          lineDash: [0.5, 4]
        }),
        //targetSize: 75,
        lonLabelFormatter: _raLabelFormatter.format,
676
        lonLabelStyle: new ol.style.Text({
677
678
          font: '12px Calibri,sans-serif',
          textBaseline: 'bottom',
679
680
          fill: new ol.style.Fill({ color: 'rgba(0,0,0,1)' }),
          stroke: new ol.style.Stroke({ color: 'rgba(255,255,255,1)', width: 3 })
681
682
683
684
        }),
        latLabelFormatter: _decLabelFormatter.format
      });

685
686
687
688
      document.getElementById("slice").addEventListener("mouseenter", function () {
        _map_controls_1.forEach(function (ctrl) {
          _map_1.addControl(ctrl);
        });
689
690
      });

691
692
693
694
      document.getElementById("slice").addEventListener("mouseleave", function () {
        _map_controls_1.forEach(function (ctrl) {
          _map_1.removeControl(ctrl);
        });
695
696
697
698
699
700
701
      });

      _graticule_1.setMap(_map_1);

      _lastClickMarker_1 = new LastClickMarker(_map_1);

      this.markLastClickInSlice = function (coordinate) {
702
703
704
705
706
707
708
709
        _lastClickMarker_1.setPositionAndFluxDensity(
          {
            "coordinate": coordinate,
            "chanIndex": _sliceIndex,
            "RADEC": this.getRADEC(coordinate),
            "fluxDensity": "t.b.d."
          }
        );
710
711
      };

712
      this.setFluxDensityInPopup = function (density) {
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
        _lastClickMarker_1.setFluxDensity(density * unitRescale(_bunit), _sliceIndex);
      }

      /*
      ** The sum of slices display
      */
      _projection_2 = new ol.proj.Projection({
        code: 'local_image',
        units: 'pixels',
        extent: _extent,
        worldExtent: [..._extent]
      });

      _map_controls_2 = [
        new ol.control.MousePosition({
          className: 'custom-mouse-position',
          target: document.getElementById('external_mouse_position_1'),
          undefinedHTML: '',
731
732
          coordinateFormat: _coordinateFormatType_1
        }),
733
734
735
736
        new ol.control.MousePosition({
          className: 'custom-mouse-position',
          target: document.getElementById('external_mouse_position_2'),
          undefinedHTML: '',
737
738
          coordinateFormat: _coordinateFormatType_2
        }),
739
740
741
        new ol.control.FullScreen()
      ];

742
      <%if (useSAMP) {%>
Moreau Nicolas's avatar
Moreau Nicolas committed
743
744
        let _sAMPPNGPublishControl_2 = new SAMPPNGPublishControl();
        _sAMPPNGPublishControl_2.setHandler(sAMPPublisher.sendPNGSummedSlices);
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
  <%}%>

        _map_2 = new ol.Map({
          target: _divSummedSlices,
          view: new ol.View({
            projection: _projection_2,
            center: ol.extent.getCenter(_extent),
            resolution: hidden_canvas_2.width / 512
          })
            <%if(useSAMP) {%>
  ,
              controls: ol.control.defaults().extend([
                _sAMPPNGPublishControl_2
              ])
                <%}%>
760
761
      });

762
763
764
765
      document.getElementById("summedslices").addEventListener("mouseenter", function () {
        _map_controls_2.forEach(function (ctrl) {
          _map_2.addControl(ctrl);
        });
766
767
      });

768
769
770
771
      document.getElementById("summedslices").addEventListener("mouseleave", function () {
        _map_controls_2.forEach(function (ctrl) {
          _map_2.removeControl(ctrl);
        });
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
      });

      // Here we have the stuff to generate reticule on summedslices.
      //
      _graticule_2 = new ol.Graticule({
        showLabels: true,
        strokeStyle: new ol.style.Stroke({
          color: 'rgba(0,0,0,0.9)',
          width: 1,
          lineDash: [0.5, 4]
        }),
        targetSize: 100,
        lonLabelFormatter: _raLabelFormatter.format,
        latLabelFormatter: _decLabelFormatter.format,
        decLabelPosition: 0.92
      });

      _graticule_2.setMap(_map_2);

      // Here we have all the stuff to create boxes on summedslices
      // and trigger the update of the spectrum of sums of pixels per slice
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
      _box_source_2 = new ol.source.Vector({ wrapX: false });
      _box_layer_2 = new ol.layer.Vector({ source: _box_source_2 });

      _select_2 = new ol.interaction.Select({ condition: ol.events.pointerMove });
      _select_2.on('select', function (e) {
        console.log(
          e.target.getFeatures().getLength() +
          ' selected features (last operation selected ' + e.selected.length +
          ' and deselected ' + e.deselected.length + ' features)');
        if (e.selected.length) {
          _selected_box_2 = e.selected[0];
          var extent = e.selected[0].getGeometry().getExtent();
          summedPixelsSpectrumViewer.plot(extent[0], extent[2], extent[1], extent[3]);
          ROI.iRA0 = Math.round(extent[0]);
          ROI.iRA1 = Math.round(extent[2]);
          ROI.iDEC0 = Math.round(extent[1]);
          ROI.iDEC1 = Math.round(extent[3]);
        }
      });
812
813
814
815

      _map_2.addInteraction(_select_2);

      _dragBox_2 = new ol.interaction.DragBox();
816
      _dragBox_2.on('boxend', function () {
817
818
819
820
821
822
823
        var extent = _dragBox_2.getGeometry().getExtent();
        var tl = ol.extent.getTopLeft(extent);
        var tr = ol.extent.getTopRight(extent);
        var br = ol.extent.getBottomRight(extent);
        var bl = ol.extent.getBottomLeft(extent);

        var corners = []
824
        corners.push(tl, tr, br, bl, tl);
825
826
827

        var ln = new ol.geom.LinearRing(corners);
        var style = {
828
829
830
831
832
          strokeColor: "#00FF00",
          strokeOpacity: 1,
          strokewidth: 3,
          fillColor: "#00FF00",
          fillOpacity: 0.8,
833
        };
834
        var pf = new ol.Feature({ geometry: new ol.geom.Polygon([corners]) });
835
836
837
838
839
840
841
        _box_source_2.addFeature(pf);
      })

      _map_2.addInteraction(_dragBox_2);

      let _updateSliceWithPOST = function () {
        console.log('_updateSliceWithPOST: entering');
842
        showLoaderAction(true);
843
        ittName = $('#ITTSelector').find(':selected').text().trim()
844
        lutName = $('#LUTSelector').find(':selected').text().trim()
845
        vmName = $('#VideoModeSelector').find(':selected').text().trim()
846
847
        $.post('png', { 'si': _sliceIndex, 'relFITSFilePath': _relFITSFilePath, 'ittName': ittName, 'lutName': lutName, 'vmName': vmName }).done(
          function (resp) {
848
            console.log("$.post('/png', {'si': _sliceIndex, 'relFITSFilePath': _relFITSFilePath}).done(: entering");
849
            if (resp["status"] == false) {
850
              alert("Something went wrong during the generation of the image. The message was '" + resp["message"] + "'");
851
852
853
            }
            else {
              _data_steps_1 = resp["result"]["data_steps"];
854
              if (_instrume == "SITELLE") {
855
856
857
858
859
860
861
862
863
864
                for (var k in _data_steps_1) {
                  if (_data_steps_1.hasOwnProperty(k)) {
                    _data_steps_1[k] /= Math.abs(3600. * 3600. * _cdelt1 * _cdelt2);
                  }
                }
              }
              var path_to_png = resp["result"]["path_to_png"];
              if (_im_layer_1) {
                _map_1.removeLayer(_im_layer_1);
              }
865

866
867
              _im_layer_1 = new ol.layer.Image({
                source: new ol.source.ImageStatic({
868
                  url: "<%=urlRoot%>" + "/" + path_to_png,
869
870
                  projection: _projection_1,
                  imageExtent: _extent,
871
872
873
874
                  imageLoadFunction: _imageLoadFunction_1
                })
              });
              _map_1.addLayer(_im_layer_1);
875
            }
876
877
878
879
880
881
882
883
884
  <% if (useSAMP) {%>
              sAMPPublisher.setSliceRelPNGPath(path_to_png);
  <%}%>
            showLoaderAction(false);
            console.log("$.post('/png', {'si': _sliceIndex, 'path': _path}).done(: exiting");
          }
        )
        console.log('_updateSliceWithPOST: exiting');
      };
885

886
      let _displaySlice = function (relFITSFilePath, sliceIndex) {
887
888
        console.log('_displaySlice : entering');
        _sliceIndex = sliceIndex;
889
        _relFITSFilePath = relFITSFilePath;
890
891
892
893
894

        _updateSliceWithPOST();
        console.log('_displaySlice : exiting');
      };

895
      let _updateSummedSlicesWithPOST = function () {
896
        console.log("_updateSummedSlicesWithPOST : entering");
897
        showLoaderAction(true);
898
        ittName = $('#ITTSelector').find(':selected').text().trim()
899
        lutName = $('#LUTSelector').find(':selected').text().trim()
900
        vmName = $('#VideoModeSelector').find(':selected').text().trim()
901
        $.post('sumpng', { 'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': _relFITSFilePath, 'ittName': ittName, 'lutName': lutName, 'vmName': vmName }).done(
902
          function (resp) {
903
            console.log("$.post('/sumpng', {'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': relFITSFilePath}).done() : entering");
904
            if (resp["status"] == false) {
905
              alert("Something went wrong during the generation of the image. The message was '" + resp["message"] + "'");
906
907
908
909
910
911
912
913
914
915
            }
            else {
              _data_steps_2 = resp["result"]["data_steps"];
              var path_to_png = resp["result"]["path_to_png"];

              if (_im_layer_2) {
                _map_2.removeLayer(_im_layer_2);
                _map_2.removeLayer(_box_layer_2);
              }
              _im_layer_2 = new ol.layer.Image({
916
917
918
                source: new ol.source.ImageStatic({
                  url: "<%=urlRoot%>" + "/" + path_to_png,
                  projection: _projection_2,
919
920
921
922
923
924
925
                  imageExtent: _extent,
                  imageLoadFunction: _imageLoadFunction_2
                })
              });
              _map_2.addLayer(_im_layer_2);
              _map_2.addLayer(_box_layer_2);
            }
926
927
928
929
  <%if (useSAMP) {%>
              sAMPPublisher.setSummedSlicesRelPNGPath(path_to_png);
  <%}%>
            showLoaderAction(false);
930
            console.log("$.post('/sumpng', {'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': relFITSFilePath}).done() : exiting");
931
          });
932
933
        console.log("_updateSummedSlicesWithPOST : exiting");
      };
934

935
      let _displaySummedSlices = function (relFITSFilePath, sliceIndex0, sliceIndex1) {
936
        console.log("let _displaySummedSlices = function(relFITSFilePath, sliceIndex0, sliceIndex1) { : entering");
937
938
        _sliceIndex0 = sliceIndex0;
        _sliceIndex1 = sliceIndex1;
939
        _relFITSFilePath = relFITSFilePath;
940
        _updateSummedSlicesWithPOST();
941
        console.log("let _displaySummedSlices = function(relFITSFilePath, sliceIndex0, sliceIndex1) { : exiting");
942
943
      };

944
      this.display = function (sliceIndex, sliceIndex0, sliceIndex1) {
945
946
947
        console.log("display: entering");
        _sliceIndex = sliceIndex;
        _displaySlice(_relFITSFilePath, _sliceIndex);
948
        if (sliceIndex0 != undefined && sliceIndex1 != undefined) {
949
950
951
952
953
954
955
          _sliceIndex0 = sliceIndex0;
          _sliceIndex1 = sliceIndex1;
          _displaySummedSlices(_relFITSFilePath, _sliceIndex0, _sliceIndex1);
        }
        console.log("display: exiting");
      };

956
      this.refresh = function () {
957
958
959
960
961
962
        console.log("refresh: entering")
        _updateSliceWithPOST();
        _updateSummedSlicesWithPOST();
        console.log("refresh: exiting")
      }

963
      this.updateSummedSlices = function (sliceIndex0, sliceIndex1) {
964
965
966
967
968
969
970
        ENTER();
        _sliceIndex0 = sliceIndex0;
        _sliceIndex1 = sliceIndex1;
        _displaySummedSlices(_relFITSFilePath, _sliceIndex0, _sliceIndex1);
        EXIT();
      };

971
      var updateView = function (event, viewRef) {
972
973
974
975
        let newValue = event.target.get(event.key);
        viewRef.set(event.key, newValue);
      };

976
      this.forgetSelectedBox = function () {
977
978
979

        console.log('this.forgetSelectedBox = function() {: entering');

980
981
        var styleForget = function () {
          return [new ol.style.Style({ stroke: new ol.style.Stroke({ color: [255, 0, 0, 1] }) })];
982
983
984
985
986
987
988
989
990
991
992
993
        };

        if (_selected_box_2) {
          _selected_box_2.setStyle(styleForget);
          _box_source_2.removeFeature(_selected_box_2);
          _box_source_2.refresh();
          summedPixelsSpectrumViewer.plot();

        }
        console.log('this.forgetSelectedBox = function() {: exiting');
      }

994
      _map_1.getView().on('change:resolution', function (event) {
995
996
997
        updateView(event, _map_2.getView());
      });

998
      _map_1.getView().on('change:center', function (event) {
999
1000
        updateView(event, _map_2.getView());
      });
For faster browsing, not all history is shown. View entire blame