olqv.ejs 85.4 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
  <%}%>
Caillat Michel's avatar
Caillat Michel committed
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
<div class="container chart-container">
      <div class="row">
        <div class="col">
Caillat Michel's avatar
Caillat Michel committed
100
          <div id="external_mouse_position_1" class="external_mouse_position"></div>
101
102
103
104
105
106
107
108
109
110
        </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">
Caillat Michel's avatar
Caillat Michel committed
111
          <div id="spectrum"></div>
112
113
114
115
        </div>
      </div>
      <div class="row">
        <div class="col">
Caillat Michel's avatar
Caillat Michel committed
116
117
118
119
120
121
122
123
124
125
          <div class="chart-control">
            <button id="zoomin" class="btn btn-default btn-control">Zoom in</button>
            <button id="zoomout" class="btn btn-default btn-control">Zoom out</button>
            <button id="zoomreset" class="btn btn-default btn-control">Reset</button>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div id="external_mouse_position_2" class="external_mouse_position"></div>
126
127
128
129
130
131
132
133
134
135
136
137
138
        </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>
Caillat Michel's avatar
Caillat Michel committed
139
140
141
142
143
144
145
      <div class="row">
        <div class="col">
          <div class="chart-title">
            <span id="chart_title"></span>
          </div>
        </div>
      </div>
146
    </div>
147

148
149
150
151
152
153
154
155
156
    <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>
Caillat Michel's avatar
Caillat Michel committed
157
158
    </div>

159
160

  <div class="hidden">
161
162
163
164
165
166
    <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
167
  <!-- Modal for samp cassis-->
168
  <div class="modal fade hidden" id="sampModal" role="dialog">
169
170
171
172
173
174
175
176
    <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">
177
          <p>
Caillat Michel's avatar
Caillat Michel committed
178
            This link is intended to send the current artemix spectrum to Cassis tool,
179
180
181
182
            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.
Caillat Michel's avatar
Caillat Michel committed
183
          </p>
184
185
186
187
188
189
190
191
192
193
          <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>
194
195
          <ul>
            <li>1- Go to the Cassis <a href="http://cassis.irap.omp.eu/?page=installation"> website</a></li>
196
197
198
            <li>2- Use Cassis online application or download the latest version </li>
          </ul>
          <p>
Caillat Michel's avatar
Caillat Michel committed
199
200
            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.
201
202
203
204
205
            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>
Caillat Michel's avatar
Caillat Michel committed
206
207
208
	      </div>
	      <div class="modal-footer">
	          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
209
210
211
212
        </div>
      </div>
    </div>
  </div>
213

ba yaye-awa's avatar
ba yaye-awa committed
214
  <!-- Modal for samp aladin -->
ba yaye-awa's avatar
ba yaye-awa committed
215
216
217
218
219
220
221
222
223
  <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">
Caillat Michel's avatar
Caillat Michel committed
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
          <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.
          </p>
          <p>
            For the transfer to work, Check that Aladin is running.
          </p>
          <p>
            How to launch Aladin :
          </p>
          <p>
            <strong>- Aladin with command line:</strong>
          </p>
          <p>
            Open a terminal and run: javaws https://aladin.u-strasbg.fr/java/nph-aladin.pl
          </p>
          <p>
            <strong>- Aladin online:</strong>
          </p>
ba yaye-awa's avatar
ba yaye-awa committed
243
244
          <ul>
            <li>1- Go to the Aladin <a href="https://aladin.u-strasbg.fr/java/nph-aladin.pl?frame=downloading"> website</a></li>
Caillat Michel's avatar
Caillat Michel committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
            <li>2- Use Aladin 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 Aladin,
            and allow the installation on your computer.
          </p>
          <p>
            Please look <a href="images/enablejava.png">here</a> to know how to do with MacOS.
          </p>
          <p>
           If you encouter any problem with Aladin please contact the Aladin team 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>
ba yaye-awa's avatar
ba yaye-awa committed
260
261
262
263
        </div>
      </div>
    </div>
  </div>
264
</body>
Caillat Michel's avatar
Caillat Michel committed
265
266
267
<script>
  var ENTER = function () { console.log(arguments.callee.name + ": entering."); };
  var EXIT = function () { console.log(arguments.callee.name + ": exiting."); };
268

Caillat Michel's avatar
Caillat Michel committed
269
270
  <%if (useSAMP) {%>
    var sAMPPublisher = null;
271
  <%}%>
272

273
  var ROI;
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
      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]]
306
        });
307

308
      }
309

310
311
      /**
        calculate the value displayed as title of summed average spectrum
Caillat Michel's avatar
Caillat Michel committed
312
        avgSpectrum array is reversed if data are radial velocities and
313
314
315
316
317
318
319
320
321
322
323
324
        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));
325
326
      }

327
328
329
330
331
332
333
334
335
336
337
338
339
      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);
      }
340

Caillat Michel's avatar
Caillat Michel committed
341
342
343
344
345
346
347
348
      function jyToK(flux){
        let kb = 1.380649e-23;
        let sec = 4.8481368110954e-06;
        let factor =  1/(2*kb*((_crval3/speedOfLight)**2)*((_bmaj*_bmin*sec*sec*Math.PI/4/Math.log(2))/1e-26));

        return flux * Factor;
      }

349
350
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
      //
      // 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
              }
            });
381

382
383
384
385
386
387
388
389
390
            /**
            * 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;
            };
391

392
393
394
395
396
397
398
399
400
401
            _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;
Caillat Michel's avatar
Caillat Michel committed
402
403
404
405
          _content.innerHTML = 'Chan#'  + _lastChanIndex + '<br>' + 'x = '
                                        + _lastCoordinate[0].toFixed(0)
                                        + ', y = '
                                        + _lastCoordinate[1].toFixed(0) + '<br>' +
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
            '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");
        };
429

430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
        //
        // 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
        }
      }
462

463
464
465
466
467
468
469
470
471
472
      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);
473

474
475
476
477
478
479
          _image.getImage().src = _srcURI;
        } else {
          console.log("Response status: %d (%s)", this.status, this.statusText);
        }
        showLoaderAction(false);
      }
480

481
482
483
484
485
486
487
488
489
490
491
492
493
      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);
494
495
        });

496
497
498
499
500
        image.getImage().src = src;
        image.getImage().crossOrigin = "Anonymous";

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

502
503
504
505
506
507
508
509
510
511
512
      //
      // 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);
        });
513

514
515
        image.getImage().src = src;
        image.getImage().crossOrigin = "Anonymous";
516

517
518
        console.log("_imageLoadFunction_2 : exiting");
      };
519
520


521
522
523
524
525
      var SAMPPNGPublishControl = (function (Control) {
        function SAMPPNGPublishControl(opt_options) {
          var options = opt_options || {};
          var button = document.createElement('button');
          button.innerHTML = '&#8663';
526

527
528
529
          var element = document.createElement('div');
          element.className = 'samp-publish-png ol-unselectable ol-control';
          element.appendChild(button);
530

531
532
533
534
          Control.call(this, {
            element: element,
            target: options.target
          });
535

536
537
538
539
          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) };
        }
540

541
542
543
        if (Control) SAMPPNGPublishControl.__proto__ = Control;
        SAMPPNGPublishControl.prototype = Object.create(Control && Control.prototype);
        SAMPPNGPublishControl.prototype.constructor = SAMPPNGPublishControl;
544

545
546
        return SAMPPNGPublishControl;
      }(ol.control.Control));
547
548


549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
      /*
      ** 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;
590

591
592
593
594
595
        _relFITSFilePath = relFITSFilePath;
        _width = width;
        _height = height;
        _divSlice = divSlice;
        _divSummedSlices = divSummedSlices;
596

597
598
        hidden_canvas_1.width = _width;
        hidden_canvas_1.height = _height;
599

600
601
        hidden_canvas_2.width = _width;
        hidden_canvas_2.height = _height;
602

603
        _extent = [0, 0, _width - 1, _height - 1];
604

605
606
        let _ra0 = RADECRangeInDegrees[0][0];
        let _ra1 = RADECRangeInDegrees[1][0];
607

608
        console.log("_ra0 = " + DecDeg2HMS(_ra0) + " _ra1 =" + DecDeg2HMS(_ra1));
609

610
611
        let _dec0 = RADECRangeInDegrees[0][1];
        let _dec1 = RADECRangeInDegrees[1][1];
612

613
        console.log("_dec0 = " + DecDeg2HMS(_dec0) + " _dec1 =" + DecDeg2HMS(_dec1));
614

615
616
        let _raLabelFormatter = new raLabelFormatter(_extent[0], _extent[2], _ra0, _ra1);
        let _decLabelFormatter = new decLabelFormatter(_extent[1], _extent[3], _dec0, _dec1);
617

618
619
620
621
622
623
        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('_');
Caillat Michel's avatar
Caillat Michel committed
624
625
626
627
            result = 'Chan#' + _sliceIndex
                             + ", " + _raLabelFormatter.format(olc[0]) + ', '
                             + _decLabelFormatter.format(olc[1]) + ', '
                             + (_data_steps_1[data_steps_index]).toExponential(2) + " " + _bunit;
628
629
630
631
632
633
          }
          else {
            result = "???";
          }
          return result;
        };
634

635
636
637
638
639
640
        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('_');
Caillat Michel's avatar
Caillat Michel committed
641
642
643
644
645
            result = _raLabelFormatter.format(olc[0])
                     + ', '
                     + _decLabelFormatter.format(olc[1]) + ', '
                     + _data_steps_2[data_steps_index].toExponential(1) 
                     + " " + summedPixelsUnit(_bunit);
646
647
648
649
650
651
          }
          else {
            result = "???";
          }
          return result;
        };
652

653
        this.getSliceIndex = function () { return sliceIndex; }
654

655
656
657
658
659
660
661
662
663
664
665
666
667
        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;
        };
668

669
670
671
        this.getRADEC = function (pixelCoordinate) {
          return { 'RA': _raLabelFormatter.format(pixelCoordinate[0]), 'DEC': _decLabelFormatter.format(pixelCoordinate[1]) }
        };
672

673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
        /*
        ** 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
                ])
                  <%}%>
715
716
717
718
719
720
721
722
723
724
725
      });

      _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,
726
        lonLabelStyle: new ol.style.Text({
727
728
          font: '12px Calibri,sans-serif',
          textBaseline: 'bottom',
729
730
          fill: new ol.style.Fill({ color: 'rgba(0,0,0,1)' }),
          stroke: new ol.style.Stroke({ color: 'rgba(255,255,255,1)', width: 3 })
731
732
733
734
        }),
        latLabelFormatter: _decLabelFormatter.format
      });

735
736
737
738
      document.getElementById("slice").addEventListener("mouseenter", function () {
        _map_controls_1.forEach(function (ctrl) {
          _map_1.addControl(ctrl);
        });
739
740
      });

741
742
743
744
      document.getElementById("slice").addEventListener("mouseleave", function () {
        _map_controls_1.forEach(function (ctrl) {
          _map_1.removeControl(ctrl);
        });
745
746
747
748
749
750
751
      });

      _graticule_1.setMap(_map_1);

      _lastClickMarker_1 = new LastClickMarker(_map_1);

      this.markLastClickInSlice = function (coordinate) {
752
753
754
755
756
757
758
759
        _lastClickMarker_1.setPositionAndFluxDensity(
          {
            "coordinate": coordinate,
            "chanIndex": _sliceIndex,
            "RADEC": this.getRADEC(coordinate),
            "fluxDensity": "t.b.d."
          }
        );
760
761
      };

762
      this.setFluxDensityInPopup = function (density) {
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
        _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: '',
781
782
          coordinateFormat: _coordinateFormatType_1
        }),
783
784
785
786
        new ol.control.MousePosition({
          className: 'custom-mouse-position',
          target: document.getElementById('external_mouse_position_2'),
          undefinedHTML: '',
787
788
          coordinateFormat: _coordinateFormatType_2
        }),
789
790
791
        new ol.control.FullScreen()
      ];

792
      <%if (useSAMP) {%>
Moreau Nicolas's avatar
Moreau Nicolas committed
793
794
        let _sAMPPNGPublishControl_2 = new SAMPPNGPublishControl();
        _sAMPPNGPublishControl_2.setHandler(sAMPPublisher.sendPNGSummedSlices);
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
  <%}%>

        _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
              ])
                <%}%>
810
811
      });

812
813
814
815
      document.getElementById("summedslices").addEventListener("mouseenter", function () {
        _map_controls_2.forEach(function (ctrl) {
          _map_2.addControl(ctrl);
        });
816
817
      });

818
819
820
821
      document.getElementById("summedslices").addEventListener("mouseleave", function () {
        _map_controls_2.forEach(function (ctrl) {
          _map_2.removeControl(ctrl);
        });
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
      });

      // 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
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
      _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]);
        }
      });
862
863
864
865

      _map_2.addInteraction(_select_2);

      _dragBox_2 = new ol.interaction.DragBox();
866
      _dragBox_2.on('boxend', function () {
867
868
869
870
871
872
873
        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 = []
874
        corners.push(tl, tr, br, bl, tl);
875
876
877

        var ln = new ol.geom.LinearRing(corners);
        var style = {
878
879
880
881
882
          strokeColor: "#00FF00",
          strokeOpacity: 1,
          strokewidth: 3,
          fillColor: "#00FF00",
          fillOpacity: 0.8,
883
        };
884
        var pf = new ol.Feature({ geometry: new ol.geom.Polygon([corners]) });
885
886
887
888
889
890
891
        _box_source_2.addFeature(pf);
      })

      _map_2.addInteraction(_dragBox_2);

      let _updateSliceWithPOST = function () {
        console.log('_updateSliceWithPOST: entering');
892
        showLoaderAction(true);
893
        ittName = $('#ITTSelector').find(':selected').text().trim()
894
        lutName = $('#LUTSelector').find(':selected').text().trim()
895
        vmName = $('#VideoModeSelector').find(':selected').text().trim()
896
897
        $.post('png', { 'si': _sliceIndex, 'relFITSFilePath': _relFITSFilePath, 'ittName': ittName, 'lutName': lutName, 'vmName': vmName }).done(
          function (resp) {
898
            console.log("$.post('/png', {'si': _sliceIndex, 'relFITSFilePath': _relFITSFilePath}).done(: entering");
899
            if (resp["status"] == false) {
900
              alert("Something went wrong during the generation of the image. The message was '" + resp["message"] + "'");
901
902
903
            }
            else {
              _data_steps_1 = resp["result"]["data_steps"];
904
              if (_instrume == "SITELLE") {
905
906
907
908
909
910
911
912
913
914
                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);
              }
915

916
917
              _im_layer_1 = new ol.layer.Image({
                source: new ol.source.ImageStatic({
918
                  url: "<%=urlRoot%>" + "/" + path_to_png,
919
920
                  projection: _projection_1,
                  imageExtent: _extent,
921
922
923
924
                  imageLoadFunction: _imageLoadFunction_1
                })
              });
              _map_1.addLayer(_im_layer_1);
925
            }
926
927
928
929
930
931
932
933
934
  <% if (useSAMP) {%>
              sAMPPublisher.setSliceRelPNGPath(path_to_png);
  <%}%>
            showLoaderAction(false);
            console.log("$.post('/png', {'si': _sliceIndex, 'path': _path}).done(: exiting");
          }
        )
        console.log('_updateSliceWithPOST: exiting');
      };
935

936
      let _displaySlice = function (relFITSFilePath, sliceIndex) {
937
938
        console.log('_displaySlice : entering');
        _sliceIndex = sliceIndex;
939
        _relFITSFilePath = relFITSFilePath;
940
941
942
943
944

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

945
      let _updateSummedSlicesWithPOST = function () {
946
        console.log("_updateSummedSlicesWithPOST : entering");
947
        showLoaderAction(true);
948
        ittName = $('#ITTSelector').find(':selected').text().trim()
949
        lutName = $('#LUTSelector').find(':selected').text().trim()
950
        vmName = $('#VideoModeSelector').find(':selected').text().trim()
951
        $.post('sumpng', { 'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': _relFITSFilePath, 'ittName': ittName, 'lutName': lutName, 'vmName': vmName }).done(
952
          function (resp) {
953
            console.log("$.post('/sumpng', {'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': relFITSFilePath}).done() : entering");
954
            if (resp["status"] == false) {
955
              alert("Something went wrong during the generation of the image. The message was '" + resp["message"] + "'");
956
957
958
959
960
961
962
963
964
965
            }
            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({
966
967
968
                source: new ol.source.ImageStatic({
                  url: "<%=urlRoot%>" + "/" + path_to_png,
                  projection: _projection_2,
969
970
971
972
973
974
975
                  imageExtent: _extent,
                  imageLoadFunction: _imageLoadFunction_2
                })
              });
              _map_2.addLayer(_im_layer_2);
              _map_2.addLayer(_box_layer_2);
            }
976
977
978
979
  <%if (useSAMP) {%>
              sAMPPublisher.setSummedSlicesRelPNGPath(path_to_png);
  <%}%>
            showLoaderAction(false);
980
            console.log("$.post('/sumpng', {'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': relFITSFilePath}).done() : exiting");
981
          });
982
983
        console.log("_updateSummedSlicesWithPOST : exiting");
      };
984

985
      let _displaySummedSlices = function (relFITSFilePath, sliceIndex0, sliceIndex1) {
986
        console.log("let _displaySummedSlices = function(relFITSFilePath, sliceIndex0, sliceIndex1) { : entering");
987
988
        _sliceIndex0 = sliceIndex0;
        _sliceIndex1 = sliceIndex1;
989
        _relFITSFilePath = relFITSFilePath;
990
        _updateSummedSlicesWithPOST();
991
        console.log("let _displaySummedSlices = function(relFITSFilePath, sliceIndex0, sliceIndex1) { : exiting");
992
993
      };

994
      this.display = function (sliceIndex, sliceIndex0, sliceIndex1) {
995
996
997
        console.log("display: entering");
        _sliceIndex = sliceIndex;
        _displaySlice(_relFITSFilePath, _sliceIndex);
998
        if (sliceIndex0 != undefined && sliceIndex1 != undefined) {
999
1000
          _sliceIndex0 = sliceIndex0;
          _sliceIndex1 = sliceIndex1;