olqv.ejs 94.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html>
<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>
  <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>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.js"></script>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">

  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
16
17
  <script src="https://code.highcharts.com/highcharts.src.js"></script>
  <script src="https://code.highcharts.com/modules/boost.js"></script>
18
19
20
21
22
23
24
25
26
27
28
29
  <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">

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

<!--  <script src="https://openlayers.org/en/v4.6.4/build/ol.js" type="text/javascript"></script> -->
  <!-- Conditional code generation -->
<%if(useSAMP){%>
  <script src="../javascript/samp.js"></script>
30
  <script src="../javascript/samp_utils.js"></script>
ba yaye-awa's avatar
ba yaye-awa committed
31
<%}%>
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
  <!-- End of conditional code generation -->

  <style>
  .map {
    height: 512px;
    width: 512px;
  }

  #loading {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;
    width: 100vw;
    height: 100vh;
    background-color: rgba(192, 192, 192, 0.5);
    background-image: url("../MnyxU.gif");
    background-repeat: no-repeat;
    background-position: center;
  }

  #info {
        z-index: 1;
        opacity: 0;
        position: absolute;
        top: 100%;
        left: 0;
        margin: 0;
        background: rgba(0,60,136,0.7);
        color: white;
        border: 0;
        transition: opacity 100ms ease-in;
      }

  .marker {
        width: 16px;
        height: 16px;
        border: 1px solid #088;
        border-radius: 8px;
        background-color: #0FF;
        opacity: 0.5;
  }

  .ol-popup {
     position: absolute;
     background-color: white;
     -webkit-filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
     filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
     padding: 10px;
     border-radius: 10px;
     border: 1px solid #cccccc;
     bottom: 12px;
     left: -50px;
     min-width: 150px;
     font-size: 10px;
   }

   .ol-popup:after, .ol-popup:before {
     top: 100%;
     border: solid transparent;
     content: " ";
     height: 0;
     width: 0;
     position: absolute;
     pointer-events: none;
   }
   .ol-popup:after {
     border-top-color: white;
     border-width: 10px;
     left: 48px;
     margin-left: -10px;
   }
   .ol-popup:before {
     border-top-color: #cccccc;
     border-width: 11px;
     left: 48px;
     margin-left: -11px;
   }
   .ol-popup-closer {
     text-decoration: none;
     position: absolute;
     top: 2px;
     right: 8px;
   }
   .ol-popup-closer:after {
     content: "x";
   }

  th, td {
    padding: 0px;
    margin: 0px;
    font-size: 16px;
    height: 20px;
  }

  .list-group{
       flex-direction: row;
   }

   .map:-moz-full-screen {
     height: 100%;
   }
   .map:-webkit-full-screen {
     height: 100%;
   }
   .map:-ms-fullscreen {
     height: 100%;
   }
   .map:fullscreen {
     height: 100%;
   }

  .samp-publish-png {
     top: 65px;
     left: .5em;
148
     display:none;
149
150
151
152
153
154
155
156
157
158
159
160
161
  }

  .ol-touch .samp-publish-png {
     top: 80px
  }
  </style>
</head>

<body>

<div id="loading"></div>
<div id="FITSHDR" class="overlay" style="overflow:scroll"></div>
<div class="pos-f-t">
162
  <div class="collapse" id="sampRegistry"></div>
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  <div class="collapse" id="navbarToggleExternalContent">
    <div class="bg-dark p-4">
<% if (renderingCapabilities) { %>
      <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">
          <% renderingCapabilities["vmodes"].forEach(function(vmode) { %>
            <option> <%=vmode%></option>
          <% }) %>
          </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>

<%}%>
    </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>
206
    <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"/>
207
    <!--<div><a id="jupyter" href="#" target="_blank"><img src="../jupyter.png" style="width:30px; height:30px" title="jupyter"/></a></div>-->
208
209
    <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>
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
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
    <div id="cubeInfos" style="font-size:15px; color: white"></div>
  </nav>
</div>
<div>
  <table style="width: 100%">

    <tr>
      <td style= "background-color: lightgray">
        <div id="external_mouse_position_1"></div>
      </td>
      <td align="middle" style= "background-color: lightgray">
        <div id="publish_spectrum"></div>
      </td>
    </tr>
    <tr>
      <td style="width: 25%">
        <div id="slice" class="map" style="background-color:darkblue"></div>
      </td>
      <td>
        <div id="spectrum"></div>
      </td>
    </tr>
    <tr>
      <td style="background-color: lightgray">
        <div id="external_mouse_position_2"></div>
      </td>
      <td align="middle" style="background-color: lightgray">
        <div id="publish_summedpixelsspectrum"></div>
      </td>
    </tr>
    <tr>
      <td style="width: 25%, background-color:darkblue">
        <div id="summedslices" class="map"></div>
      </td>
      <td>
        <div id="summedpixelsspectrum"></div>
      </td>
    </tr>
  </table>

  <table style='display: none'>
    <tr>
      <td><canvas id="hiddenSlice"></canvas></td>
    </tr>
    <tr>
      <td><canvas id="hiddenSummedSlices"></canvas></td>
    </tr>
  </table>
</div>

  <div style='display: none'>
    <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
267
  <!-- Modal for samp cassis-->
268
269
270
271
272
273
274
275
276
277
278
279
  <div class="modal fade" id="sampModal" 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 spectrum by SAMP (Cassis)</h4>
        </div>
        <div class="modal-body">
          <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.
          </br></br>
          For the transfer to work, Check that Cassis is running.</br></br>
280

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
          How to launch Cassis</br>
          <strong>- Cassis with command line:</strong></br>
          Open a terminal and run: javaws http://cassis.irap.omp.eu/online/cassis.jnlp </br></br>
          <strong>- Cassis online:</strong></br>
          <ul>
            <li>1- Go to the Cassis <a href="http://cassis.irap.omp.eu/?page=installation"> website</a></li>
            <li>2- Use Cassis 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 Cassis, 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 Cassis please contact the Cassis project manager <a href="#">Jean-Michel.Glorian{at}irap.omp.eu</a></p>
	</div>
	<div class="modal-footer">
	  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
297

ba yaye-awa's avatar
ba yaye-awa committed
298
  <!-- Modal for samp aladin -->
ba yaye-awa's avatar
ba yaye-awa committed
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
  <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>
328
329
330
331
332
333
334
335
336
337
</body>
    <script>

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

<%if(useSAMP){%>
    var sAMPPublisher = null;
<%}%>

338
339
340
341
342
  var ROI;

  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);
  };
343
344
345
346
347
348
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
381
382
383
384
385
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
419
420
421
422
423
424
425
426
427
428
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
462
463
464

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

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

          /**
          * 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;
          };

          _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");
      };

      //
      // 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
      }
    }

    function _onError(event) {
      console.error("Error  " + event.target.status + " during the transfert.");
    }

    function _onLoad(event) {
465
      // Ici, this.readyState �gale XMLHttpRequest.DONE .
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
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
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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
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
665
666
667
668
669
670
671
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
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
      if (this.status === 200) {
        console.log("Transfert done - " + this.responseText.length + "bytes.");
        var _srcURI = "data:image/png," + this.responseText;
        console.log("_srcURI=" + _srcURI);

        _image.getImage().src = _srcURI;
      } else {
        console.log("Response status: %d (%s)", this.status, this.statusText);
      }
      document.getElementById('loading').style.display='none';
    }

    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");
      document.getElementById('loading').style.display='block';
      image.getImage().addEventListener('load', function() {
        document.getElementById('loading').style.display='none';
        hidden_canvas_1.getContext('2d').drawImage(image.getImage(), 0, 0);
      });

      image.getImage().src = src;
      image.getImage().crossOrigin = "Anonymous";

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

    //
    // 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");
    document.getElementById('loading').style.display='block';
    image.getImage().addEventListener('load', function() {
        document.getElementById('loading').style.display='none';
        hidden_canvas_2.getContext('2d').drawImage(image.getImage(), 0, 0);
    });

    image.getImage().src = src;
    image.getImage().crossOrigin = "Anonymous";

    console.log("_imageLoadFunction_2 : exiting");
    };


var SAMPPNGPublishControl = (function (Control) {
    function SAMPPNGPublishControl(opt_options) {
	var options = opt_options || {};
	var button = document.createElement('button');
	button.innerHTML = '&#8663';

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

        Control.call(this, {
	    element: element,
	    target: options.target
        });

	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)};
    }

    if ( Control ) SAMPPNGPublishControl.__proto__ = Control;
    SAMPPNGPublishControl.prototype = Object.create( Control && Control.prototype );
    SAMPPNGPublishControl.prototype.constructor = SAMPPNGPublishControl;

    return SAMPPNGPublishControl;
}(ol.control.Control));


    /*
    ** 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;

      _relFITSFilePath=relFITSFilePath;
      _width=width;
      _height=height;
      _divSlice=divSlice;
      _divSummedSlices=divSummedSlices;

      hidden_canvas_1.width = _width;
      hidden_canvas_1.height = _height;

      hidden_canvas_2.width = _width;
      hidden_canvas_2.height = _height;

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

      let _ra0 = RADECRangeInDegrees[0][0];
      let _ra1 = RADECRangeInDegrees[1][0];

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

      let _dec0 = RADECRangeInDegrees[0][1];
      let _dec1 = RADECRangeInDegrees[1][1];

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

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

      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;
      };

      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;
      };

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

      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;
      };

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

      /*
      ** 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
        ])
<%}%>
      });

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

      document.getElementById("slice").addEventListener("mouseenter", function() {
	       _map_controls_1.forEach(function(ctrl) {
	          _map_1.addControl(ctrl);
	         });
      });

      document.getElementById("slice").addEventListener("mouseleave", function() {
	       _map_controls_1.forEach(function(ctrl) {
	          _map_1.removeControl(ctrl);
	         });
      });

      _graticule_1.setMap(_map_1);

      _lastClickMarker_1 = new LastClickMarker(_map_1);

      this.markLastClickInSlice = function (coordinate) {
          _lastClickMarker_1.setPositionAndFluxDensity(
            {"coordinate": coordinate,
              "chanIndex": _sliceIndex,
              "RADEC" :this.getRADEC(coordinate),
              "fluxDensity" : "t.b.d."}
            );
      };

      this.setFluxDensityInPopup = function(density) {
        _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: '',
          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_2 = new SAMPPNGPublishControl();
      _sAMPPNGPublishControl_2.setHandler(sAMPPublisher.sendPNGSummedSlices);
<%}%>

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

      document.getElementById("summedslices").addEventListener("mouseenter", function() {
	       _map_controls_2.forEach(function(ctrl) {
	          _map_2.addControl(ctrl);
	         });
      });

      document.getElementById("summedslices").addEventListener("mouseleave", function() {
	       _map_controls_2.forEach(function(ctrl) {
	          _map_2.removeControl(ctrl);
	        });
      });

      // 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
      _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();
              console.log(JSON.stringify(e.selected[0].getGeometry().getExtent()));
              summedPixelsSpectrumViewer.plot(extent[0], extent[2], extent[1], extent[3]);
841
842
843
844
              ROI.iRA0 = Math.round(extent[0]);
              ROI.iRA1 = Math.round(extent[2]);
              ROI.iDEC0 = Math.round(extent[1]);
              ROI.iDEC1 = Math.round(extent[3]);
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
            }
          });

      _map_2.addInteraction(_select_2);

      _dragBox_2 = new ol.interaction.DragBox();
      _dragBox_2.on('boxend', function() {
        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 = []
        corners.push(tl,tr, br, bl, tl);

        var ln = new ol.geom.LinearRing(corners);
        var style = {
            strokeColor: "#00FF00",
            strokeOpacity: 1,
            strokewidth: 3,
            fillColor: "#00FF00",
            fillOpacity: 0.8,
        };
        var pf = new ol.Feature({geometry : new ol.geom.Polygon([corners])});
        _box_source_2.addFeature(pf);
      })

      _map_2.addInteraction(_dragBox_2);

      let _updateSliceWithPOST = function () {
        console.log('_updateSliceWithPOST: entering');
        document.getElementById('loading').style.display="block";
        ittName = $('#ITTSelector').find(':selected').text().trim()
        lutName =  $('#LUTSelector').find(':selected').text().trim()
        vmName = $('#VideoModeSelector').find(':selected').text().trim()
881
        $.post('png', {'si': _sliceIndex, 'relFITSFilePath': _relFITSFilePath, 'ittName': ittName, 'lutName': lutName , 'vmName' : vmName}).done(
882
          function(resp) {
883
            console.log("$.post('/png', {'si': _sliceIndex, 'relFITSFilePath': _relFITSFilePath}).done(: entering");
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
            if (resp["status"] == false) {
              alert ("Something went wrong during the generation of the image. The message was '" + resp["message"] +"'");
            }
            else {
              _data_steps_1 = resp["result"]["data_steps"];
              if ( _instrume == "SITELLE") {
                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);
              }
900

901
902
              _im_layer_1 = new ol.layer.Image({
                source: new ol.source.ImageStatic({
Caillat Michel's avatar
Caillat Michel committed
903
                  url : "<%=urlRoot%>"+"/"+path_to_png,
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
                  projection: _projection_1,
                  imageExtent: _extent,
                  imageLoadFunction: _imageLoadFunction_1})
                });
                _map_1.addLayer(_im_layer_1);
              }
<% if(useSAMP){%>
              sAMPPublisher.setSliceRelPNGPath(path_to_png);
<%}%>
              document.getElementById('loading').style.display="none";
              console.log("$.post('/png', {'si': _sliceIndex, 'path': _path}).done(: exiting");
            }
          )
          console.log('_updateSliceWithPOST: exiting');
        };

920
      let _displaySlice = function(relFITSFilePath, sliceIndex) {
921
922
        console.log('_displaySlice : entering');
        _sliceIndex = sliceIndex;
923
        _relFITSFilePath = relFITSFilePath;
924
925
926
927
928
929
930
931
932
933
934

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

      let _updateSummedSlicesWithPOST = function() {
        console.log("_updateSummedSlicesWithPOST : entering");
        document.getElementById('loading').style.display="block";
        ittName = $('#ITTSelector').find(':selected').text().trim()
        lutName =  $('#LUTSelector').find(':selected').text().trim()
        vmName = $('#VideoModeSelector').find(':selected').text().trim()
935
        $.post('sumpng', {'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': _relFITSFilePath, 'ittName': ittName, 'lutName': lutName, 'vmName' :vmName}).done(
936
          function (resp) {
937
            console.log("$.post('/sumpng', {'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': relFITSFilePath}).done() : entering");
938
939
940
941
942
943
944
945
946
947
948
949
950
            if (resp["status"] == false) {
              alert ("Something went wrong during the generation of the image. The message was '" + resp["message"] +"'");
            }
            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({
                source : new ol.source.ImageStatic({
Caillat Michel's avatar
Caillat Michel committed
951
                  url: "<%=urlRoot%>"+"/"+path_to_png,
952
953
954
955
956
957
958
959
960
961
962
963
                  projection : _projection_2,
                  imageExtent: _extent,
                  imageLoadFunction: _imageLoadFunction_2
                })
              });
              _map_2.addLayer(_im_layer_2);
              _map_2.addLayer(_box_layer_2);
            }
<%if(useSAMP){%>
	            sAMPPublisher.setSummedSlicesRelPNGPath(path_to_png);
<%}%>
              document.getElementById('loading').style.display="none";
964
            console.log("$.post('/sumpng', {'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': relFITSFilePath}).done() : exiting");
965
966
967
968
          });
          console.log("_updateSummedSlicesWithPOST : exiting");
        };

969
970
      let _displaySummedSlices = function(relFITSFilePath, sliceIndex0, sliceIndex1) {
        console.log("let _displaySummedSlices = function(relFITSFilePath, sliceIndex0, sliceIndex1) { : entering");
971
972
        _sliceIndex0 = sliceIndex0;
        _sliceIndex1 = sliceIndex1;
973
        _relFITSFilePath = relFITSFilePath;
974
        _updateSummedSlicesWithPOST();
975
        console.log("let _displaySummedSlices = function(relFITSFilePath, sliceIndex0, sliceIndex1) { : exiting");
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
      };

      this.display = function(sliceIndex, sliceIndex0, sliceIndex1) {
        console.log("display: entering");
        _sliceIndex = sliceIndex;
        _displaySlice(_relFITSFilePath, _sliceIndex);
        if ( sliceIndex0 != undefined && sliceIndex1 != undefined ) {
          _sliceIndex0 = sliceIndex0;
          _sliceIndex1 = sliceIndex1;
          _displaySummedSlices(_relFITSFilePath, _sliceIndex0, _sliceIndex1);
        }
        console.log("display: exiting");
      };

      this.refresh = function() {
        console.log("refresh: entering")
        _updateSliceWithPOST();
        _updateSummedSlicesWithPOST();
        console.log("refresh: exiting")
      }

      this.updateSummedSlices = function(sliceIndex0, sliceIndex1) {
        ENTER();
        _sliceIndex0 = sliceIndex0;
        _sliceIndex1 = sliceIndex1;
For faster browsing, not all history is shown. View entire blame