-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathastrohopper.html
2368 lines (2148 loc) · 66.5 KB
/
astrohopper.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
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
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
267
268
269
270
271
272
273
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
306
307
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
341
342
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
465
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
841
842
843
844
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
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
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
<!DOCTYPE>
<html>
<head>
<title>AstroHopper - Web Application for Sky Navigation</title>
<link rel="manifest" href="manifest.json">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<style>
body, td { margin:3mm 0 0 0; font-size: 5mm ; color:red ; font-family: sans; background-color:black }
a:link {color: red;}
a:visited { color: red; }
a:active { color:red; }
a:hover { color:red; }
button { border-radius:2mm; height:10mm; font-size:5mm ; text-align:center; vertical-align: middle; background-color:black; color:red; border: 2px solid red }
.comp_but, .incdec_but { width: 10mm ; height:10mm; font-size:5mm ; padding: 0 }
.comp_but { float:right }
.only_tiny { display : none }
.only_tiny_tr { display : none }
.only_full { display : inline }
.only_tiny_b { display : none }
#search_field_main_ok {
position:absolute;
top:31mm;
right:10%;
height:10mm;
border:0px;
margin-left:1mm;
display:none;
background-color: transparent;
}
#main_search_button {
position:absolute;
right:27mm;
margin:0;
top:3mm;
}
#search_field_main {
position:absolute;
right:12mm;
top:3mm;
margin:0;
border-radius:2mm;
width:15mm;
padding-left:1mm;
font-size:66%;
}
#search_field_main:focus {
position:absolute;
right:10%;
left:10%;
top:31mm;
padding:0;
width:80%;
font-size:100%;
}
.first_line_controls {
padding:0;
margin:1mm 1mm 1mm 1mm;
}
.manual_background {
background: url(manual-blk.png) no-repeat center center;
background-size: 10mm 10mm;
}
.compass_background {
background: url(compass-blk.png) no-repeat center center;
background-size: 10mm 10mm;
}
.wiki_background {
background: url(wiki.png) no-repeat center center;
background-size: 10mm 10mm;
}
.search_background {
background: url(search.png) no-repeat center center;
background-size: 10mm 10mm;
}
.nocompass_background {
background: url(nocompass-blk.png) no-repeat center center;
background-size: 10mm 10mm;
}
.settings_background {
background: url(settings-blk.png) no-repeat center center;
background-size: 10mm 10mm;
}
input[type=text], input[type=text]:focus, textarea, input[type=submit], input[type=number] {
border: 2px solid red;
color:red;
background-color:black;
}
input[type=text], input[type=text]:focus, input[type=submit], input[type=number] {
height:10mm;
font-size:5mm;
padding: 0;
vertical-align: middle; background-color:black;
}
input[type=submit] { width:10mm;}
</style>
<body>
<canvas style="position:absolute; left:0; top:0; z-index:-1" id="myCanvas" width="640" height="480"> </canvas>
<div class="only_full">
<input id="search_field_main" class="search_field" autocomplete="off" type="text" value="search" onkeyup="mainSearchDoneCheck(event);" oninput="mainSearchFindTarget(this.value);" onfocus="mainSearchFocus();" onclick="mainSearchFocus();" onfocusout="mainSearchOnFocusChange(false);" onfocusin="mainSearchOnFocusChange(true)" />
<button class="incdec_but search_background" id="main_search_button" style="display:none; margin-right:1mm;" onclick="reShearchMain();"> </button>
<button id="search_field_main_ok" ></button>
</div>
<p class="first_line_controls" >
<span class="only_full"><button class="ui_but" onclick="align();">Align</button></span>
<span class="only_tiny"><button class="incdec_but" onclick="align();">◎</button></span>
<span id="countdown"></span>
<span class="only_tiny" id="alignment_tiny"></span><span class="only_full" id="alignment"></span>
<button class="comp_but nocompass_background" id="nocompass_button" style="display:none"> </button>
<button class="comp_but manual_background" id="hand_button" style="display:none;" onclick="manualMode();"> </button>
<button class="comp_but compass_background" id="compass_button" style="display:none" onclick="compassMode();"> </button>
</p>
<p class="first_line_controls only_full_b">
<button class="incdec_but" onclick="incFOV();">-</button>
<button class="incdec_but" onclick="decFOV();">+</button>
∠<span class="fov_val">60°</span>
<button style="display:inline" class="comp_but settings_background" onclick="showConfig('inline');"> </button>
</p>
<p class="only_tiny_b first_line_controls"><button class="comp_but settings_background" onclick="showConfig('inline');"> </button>
</p>
<p class="first_line_controls" style="display:none" id="wl_ctl"><button class="incdec_but" onclick="watchListItemUpdate(-1);"><</button> <button class="incdec_but" onclick="watchListItemUpdate(1);">></button><br/><i><span id="wl_target_name"></span></i></p>
<p class="first_line_controls" style="display:none" id="show_info">
<button class="incdec_but wiki_background" onclick="showObjectInfo();" > </button>
</p>
<p class="first_line_controls" id="gps">No Geolocation</p>
<div id="object_log" style="display:none">
<p>Sirius:<span id="Sirius_alt"></span>, <span id="Sirius_az"></span></p>
<p>Mars:<span id="Mars_alt"></span>, <span id="Mars_az"></span></p>
<p>Rigel:<span id="Rigel_alt"></span>, <span id="Rigel_az"></span></p>
<p>Jupiter:<span id="Jupiter_alt"></span>, <span id="Jupiter_az"></span></p>
</div>
<p class="first_line_controls" id="orient"></p>
<p class="first_line_controls" id="status"></p>
<div class="config_div" id="quick_start" style="display:none; position:absolute; left:10%; top:10%; z-index:4 ; padding: 1% 1% 1% 1%; width: 78%; background:black; border: 1px solid red ; text-align:left ">
<span style="position:absolute; right:1mm; top:1mm">
<button class="incdec_but" onclick="qsHide()">X</button>
</span>
<h3>Quick Start Guide</h3>
<p><input class="dso_selector" id="qs_hide_1" type="checkbox" onchange="showOnStartup(!this.checked,1)" /><label for="qs_hide_1" >Don't show on startup</label></p>
<div id="qs_1">
<p>
<button class="ui_but" disabled style="color:#800">< Prev</button>
<button class="ui_but" onclick="qsShowHide(2,1)">Next ></button>
</p>
<img style="float:right" width="50%" src="images/qs_1_1.png" alt="Setup" />
<p>Connect the smartphone to the optical tube such that its top points to the viewing direction and it lies flat on the tube.</p>
<hr style="border-color:red">
<p><i><a href="https://stories.bringthemhomenow.net/">Bring them home now!</a></i></p>
<p><b>Stand with Israel against terror!</b></p>
</div>
<div id="qs_2" style="display:none;">
<p>
<button class="ui_but" onclick="qsShowHide(1,2)">< Prev</button>
<button class="ui_but" onclick="qsShowHide(3,2)">Next ></button>
</p>
<img style="float:right" width="50%" src="images/qs_2_1.png" alt="Setup" />
<p>Point the telescope to an easily identifiable star or planet <strong>nearby</strong> an object you want to find. For example in order to find M41 or M47, point the telescope to Sirius — this is going to be the <em>alignment star</em>.</p>
<p>When the telescope is pointing to the alignment star tap <button class="ui_but">Align</button> button and tap on the alignment star on the map. Once the application is aligned, it tracks the telescope movement using smartphone's sensors.</p>
</div>
<div id="qs_3" style="display:none;">
<p>
<button class="ui_but" onclick="qsShowHide(2,3)">< Prev</button>
<button class="ui_but" onclick="qsShowHide(4,3)">Next ></button>
</p>
<p>If you can't see the alignment star on the map, there may be a common compass accuracy problem.</p>
<p>In such a case tap on <button class="incdec_but manual_background"> </button> to switch to manual mode and scroll the map left
or right till you see the alignment star.</p>
<p>Then tap <button class="ui_but">Align</button> and tap on the alignment star on the map as usual.</p>
</div>
<div id="qs_4" style="display:none;">
<p>
<button class="ui_but" onclick="qsShowHide(3,4)">< Prev</button>
<button class="ui_but" disabled style="color:#800">Next ></button>
</p>
<img style="float:right" width="50%" src="images/qs_3_1.png" alt="Setup" />
<p>Once aligned, tap on the object you want to find (for example M41, M47) and follow the direction line on the map till you reach the target. Now you can observe the object you selected.</p>
<p>It is recommended to repeat alignment for each new target you want to find</p>
<p>For detailed instruction and troubleshooting please refer to the <a href="https://youtu.be/AtArqBLWWJ8">[Video Tutorial]</a>
and to the integrated manual via:
<button class="incdec_but settings_background"> </button> → <button class="incdec_but">?</button>
</p>
</div>
</div>
<div class="config_div" id="wiki_info" style="display:none; position:absolute; left:5%; top:5%; right:5%; bottom:5%; z-index:3; padding: 1% 1% 1% 1%; background:black; border: 1px solid red ">
<span style="position:absolute; right:1mm; top:1mm">
<button class="incdec_but" onclick="hideWiki();">X</button>
</span>
<iframe id="wiki_iframe" style="width:100%; height:100%"></iframe>
</div>
<div class="config_div" id="allow_orientation" style="display:none; position:absolute; left:10%; top:10%; z-index:3 ; padding: 1% 1% 1% 1%; width: 78%; background:black; border: 1px solid red ; text-align:center ">
<button class="ui_but" style="height:30mm" onclick="iOSOrientation();">Enable Device Orientation</button>
</div>
<div class="config_div" id="config" style="display:none; position:absolute; left:5%; top:5%; z-index:2 ; padding: 1% 1% 1% 1%; width: 88%; background:black; border: 1px solid red ">
<span style="position:absolute; right:1mm; top:1mm">
<button class="incdec_but" onclick="showManual(true)">?</button>
<button class="incdec_but" onclick="showConfig('none');">X</button>
</span>
<p><b>Settings (version)</b></p>
<p>
<button class="ui_but" onclick="resetAll();">↻</button>
<input class="dso_selector" id="small_screen" type="checkbox" /><label for="small_screen" >Small UI</label>
<input class="dso_selector" id="NM_checked" type="checkbox" /><label for="NM_checked" >Night</label>
<input class="dso_selector" id="FS_checked" type="checkbox" onchange="toggleFS(this.checked)" /><label for="FS_checked" >Full S.</label>
</p><p>
<input class="dso_selector" id="SWL_checked" type="checkbox" onchange="toggleSWL(this.checked)" /><label for="SWL_checked" >Keep Screen On</label>
</p>
<table>
<tr class="only_tiny_tr">
<td>FOV</td>
<td>
<button class="incdec_but" onclick="incFOV();">-</button> <button class="incdec_but" onclick="decFOV();">+</button>
</td>
<td>
∠<span class="fov_val">60°</span>
</td>
<td> </td>
</tr>
<tr>
<td>Stars</td>
<td>
<button class="incdec_but" onclick="starMagUpdate(-1);">-</button> <button class="incdec_but" onclick="starMagUpdate(1);">+</button>
</td>
<td>
<i>m≤</i><span id="mag_val">4</span>
</td>
<td> </td>
</tr>
<tr>
<td>DSO</td>
<td>
<button class="incdec_but" onclick="dsoMagUpdate(-1);">-</button> <button class="incdec_but" onclick="dsoMagUpdate(1)">+</button>
</td>
<td>
<i>m≤</i><span id="dso_level_val">5</span>
</td>
<td> </td>
</tr>
<tr>
<td>List</td>
<td>
<button class="incdec_but" onclick="prevWatchList();"><</button> <button class="incdec_but" onclick="nextWatchList()">></button>
</td>
<td id="wl_sel">None</td>
<td>
<a id="list_edit_toggle" href="javascript:toggleEditWL()">[edit]</a>
</td>
</tr>
<tr>
<td>Font</td>
<td>
<button class="incdec_but" onclick="incDecLF(-1);">-</button> <button class="incdec_but" onclick="incDecLF(1)">+</button>
</td>
<td>
<i>+</i><span id="lf_val">0</span><i>mm</i>
</td>
<td> </td>
</tr>
</table>
<div id="wl_edit" style="display:none;">
<p>name: dso1, dso2, dso3, …</p>
<p>
<textarea id="user_wl" style="width:80%" rows="5"></textarea>
</p>
<p><button class="ui_but" onclick="saveWL();" >Save</button> <button class="ui_but" onclick="discardWL();" >Discard</button></p>
<p id="wl_errors"></p>
</div>
<form onsubmit="return hideSettingIfSelectionOk()" >
<p> <input id="search_field" type="text" oninput="findTargetByName(this.value)" onclick="this.value='';" onfocus="findTargetByName(this.value)" style="width:30%" /> <input type="submit" value="⌕"/> <b><span style="float:right" id="find_status"><span></b></p>
</form>
<table style="width:100%">
<tr>
<td>
<input class="dso_selector" id="align_dso_checked" type="checkbox" /><label for="align_dso_checked" >Align on DSO</label>
</td>
<td>
<input class="dso_selector" id="show_star_names_checked" type="checkbox" checked="checked" onchange="global_show_star_names = this.checked;" /><label for="show_star_names_checked" >Star Names</label>
</td>
</tr>
<tr>
<td>
<input class="dso_selector" id="Oc_checked" type="checkbox" checked="checked" /><label for="Oc_checked">Open Clusters</label>
</td>
<td>
<input class="dso_selector" id="Gc_checked" type="checkbox" checked="checked" /><label for="Gc_checked">Glob. Clusters</label>
</td>
</tr>
<tr>
<td>
<input class="dso_selector" id="Ne_checked" type="checkbox" checked="checked" /><label for="Ne_checked">Nebulae</label>
</td>
<td>
<input class="dso_selector" id="Ga_checked" type="checkbox" checked="checked" /><label for="Ga_checked">Galaxies</label>
</td>
</tr>
<tr>
<td>
<input class="dso_selector" id="P_checked" type="checkbox" checked="checked" /><label for="P_checked" >Planets</label>
</td>
<td>
<input class="dso_selector" id="Ca_checked" type="checkbox" checked="checked" /><label for="Ca_checked">Constellations</label>
</td>
</tr>
<tr>
<td>
<input class="dso_selector" id="qs_hide_2" type="checkbox" checked="checked" onchange="showOnStartup(this.checked,2);" /><label for="qs_hide_2">Show Tutorial</label>
</td>
<td>
<input class="dso_selector" id="pinch_zoom" type="checkbox" checked="checked" /><label for="pinch_zoom">Pinch Zoom</label>
</td>
</tr>
<tr>
<td>
</td>
<td>
Wiki:
<select id="wiki_info_opt" onchange="wikiInfoConfig()">
<option value="no">Never</option>
<option selected value="day">Day Only</option>
<option value="always">Always</option>
</select>
</td>
</tr>
</table>
<p><input class="dso_selector" id="U_checked" type="checkbox" checked="checked" /><label for="U_checked">User Objects</label> <a id="edit_user_dso" href="javascript:toggleEditDSO();">[edit]</a></p>
<div id="dso_edit" style="display:none;">
<p>Name,RA(hh:mm:ss),DE(±dd:mm:ss)</p>
<p>
<textarea id="user_dso" style="width:80%" rows="5"></textarea>
</p>
<p><button class="ui_but" onclick="saveUserDSO();" >Save</button> <button class="ui_but" onclick="discardUserDSO();" >Discard</button></p>
<p id="dso_errors"></p>
</div>
<hr>
<p><button class="incdec_but" onclick="requestGeolocation();">↻</button> GPS: <span id="lat">Unknown</span>, <span id="lon">Unknown</span></p>
<p>α=<span id="ang_a"></span> β=<span id="ang_b"></span> γ=<span id="ang_g"></span> C=<span id="ang_c"></span> UTC=<span id="utc_time"></span></p>
<table>
<th><td colspan="2" style="text-align:left">GPS Override</td></th>
<tr><td>Lat:</td><td><input type="number" min="-90" max=90" value="" id="manual_lat" oninput="updateManualLatLon()"></td></tr>
<tr><td>Lon:</td><td><input type="number" min="-180" max=180" value="" id="manual_lon" oninput="updateManualLatLon()"></td></tr>
</table>
</div>
<div style="position:absolute; left:0; top:0; z-index:5; width:100%; background:black; display:none;" id="manual">
<span style="float:right; margin-right: 2mm; margin-top:2mm">
<button class="incdec_but" onclick="showManual(false);">X</button>
</span>
MANUAL
</div>
<script src="vsop87a_combined.js"></script>
<script src="vsop87-multilang/Languages/JavaScript/CelestialProgrammingReduce.js"></script>
<script>
vsop87a_full = vsop87a_xsmall;
vsop87a_full_velocities = vsop87a_milli_velocities;
</script>
<script src="jsdb.js"></script>
<script>
var global_day_style = {
cross : 'blue',
constelations : 'yellow',
bearing : 'green',
star : 'white',
altaz : 'red',
target : 'cyan',
align : 'magenta'
};
var global_show_obj = {
'S': true,
'Oc': true,
'Gc': true,
'Ca': true,
'Ga':true,
'Ne':true,
'P': true,
'U': true
};
var global_night_style = {
cross : 'red',
constelations : '#880000',
bearing : 'red',
star : 'red',
altaz : 'red',
target : 'red',
align : '#AA0000'
};
var global_style = global_day_style;
var global_align_on_dso=false;
var global_show_star_names=true;
var global_targets_list = [];
var global_prev_xy=null;
var global_start_zoom_size = null;
var global_start_zoom = null;
var global_allow_pinch_zoom = true;
var global_toch_start_time = null;
var global_target_index = -1;
var global_align_index = -1;
var global_expecting_select = null;
var global_camera_projection = true;
var global_expected_frame_rate_ms = 66;
var global_use_compass = false;
var global_dso_mag = parseInt(document.getElementById('dso_level_val').innerHTML);
var global_large_font = 0;
var global_fov_values = [7,15,30,60,90,120,150]
var global_fov = 60;
var global_mag = 4;
var gdata = {
"lat" : 31.9,
"lon" : 34.8,
"compass_alpha" : 0,
"alpha" : 0,
"alpha_user_offset" : 0,
"alpha_gyro" : 0,
"alpha_diff" : 0,
"beta" : 0,
"gamma" : 0,
"time" : Date.now(), //1614716453109
}
var global_align_matrix = [1,0,0,0,1,0,0,0,1];
var global_use_gyro = false;
var global_full_screen = false;
var global_status = "";
var global_watchlist = null;
function showManual(v)
{
document.getElementById('manual').style.display = v ? 'inline' : 'none';
}
function qsHide()
{
document.getElementById('quick_start').style.display = 'none';
}
function qsShowHide(show_id,hide_id)
{
document.getElementById('qs_' + hide_id).style.display = 'none';
document.getElementById('qs_' + show_id).style.display = 'inline';
}
function setDisplayByClass(cls,value)
{
var el = document.getElementsByClassName(cls);
for(var i=0;i<el.length;i++) {
el[i].style.display = value;
}
}
function smallScreen(v)
{
var tiny = v ? 'inline' : 'none';
var tiny_tr = v ? 'table-row' : 'none';
var tiny_b = v ? 'block' : 'none';
var full = v ? 'none' : 'inline';
var full_b = v ? 'none' : 'block';
setDisplayByClass('only_tiny_tr',tiny_tr);
setDisplayByClass('only_tiny',tiny);
setDisplayByClass('only_tiny_b',tiny_b);
setDisplayByClass('only_full',full);
setDisplayByClass('only_full_b',full_b);
}
function showStatus(v)
{
global_status += v+"<br/>"
document.getElementById('status').innerHTML = global_status;
}
function showConfig(v)
{
document.getElementById('config').style.display = v;
}
function largeF(n,s)
{
return (s+global_large_font) + "mm " +n;
}
function toggleFS(fs)
{
if(fs) {
document.documentElement.requestFullscreen({navigationUI:'hide'});
}
else {
document.exitFullscreen();
}
}
let wakeLock = null;
async function toggleSWL(swl) {
try {
if (swl) {
wakeLock = await navigator.wakeLock.request('screen');
} else if (wakeLock) {
await wakeLock.release();
wakeLock = null;
}
} catch (err) {
console.error(`${err.name}, ${err.message}`);
}
}
function hideSettingIfSelectionOk()
{
var value = document.getElementById("search_field").value;
if(findTargetByName(value)) {
showConfig('none')
}
return false;
}
function normalizeName(name)
{
name = name.toUpperCase()
const re=/^(.*)(([A-Z]+)[ 0]+)([^0].*)$/;
var match = name.match(re);
if(match) {
return normalizeName(match[1]+match[3]+match[4]);
}
return name;
}
function reShearchMain()
{
findTargetByName(document.getElementById('search_field_main').value);
}
function mainSearchOnFocusChange(val)
{
if(!val) {
var isOk = document.getElementById('search_field_main_ok');
isOk.style.display = 'none';
var el = document.getElementById('search_field_main');
var content = el.value;
reShearchMain();
if(content.trim()=='') {
el.value='search';
}
}
var but = document.getElementById('main_search_button');
if(!val && global_target_index >= 0) {
but.style.display='inline';
}
else {
but.style.display='none';
}
}
function mainSearchOnSubmit()
{
document.getElementById('search_field_main').blur();
return false;
}
function mainSearchDoneCheck(e)
{
if(e.key == "Enter") {
mainSearchOnSubmit();
}
}
function mainSearchFindTarget(name)
{
findTargetByName(name.trim());
var el = document.getElementById('search_field_main');
var isOk = document.getElementById('search_field_main_ok');
isOk.style.display = 'inline';
isOk.innerHTML= (global_target_index>=0) ? "✓" : "✗";;
}
function mainSearchFocus()
{
document.getElementById('search_field_main').value="";
event.stopPropagation();
}
function findTargetByName(name ='')
{
var found = document.getElementById('find_status')
var name = normalizeName(name);
var N=allstars_index_name.names.length;
var found_index = -1;
if(name != '') {
for(var i=0;i<N;i++) {
let candidate = allstars_index_name.names[i];
if(candidate == name) {
found_index = i;
break;
}
else if(found_index != -2 && candidate.startsWith(name)) {
if(found_index == -1) {
found_index = i;
}
else {
found_index = -2;
}
}
}
}
if(found_index >= 0) {
global_target_index = allstars_index_name.index[found_index];
found.innerHTML = allstars[global_target_index].name;
showHideInfoIcon();
return true;
}
else {
global_target_index = -1;
found.innerHTML = '';
showHideInfoIcon();
return false;
}
}
function starMagUpdate(offset)
{
global_mag += offset;
global_mag = Math.max(1,Math.min(6,global_mag));
updateMAG()
}
function updateMAG()
{
document.getElementById("mag_val").innerHTML = global_mag + "";
saveMagVal(global_mag,"mag_val");
}
function incFOV()
{
var N = global_fov_values.length;
for(var i=0;i<N-1;i++) {
if(global_fov == global_fov_values[i]
|| (global_fov_values[i] < global_fov && global_fov < global_fov_values[i+1]))
{
global_fov = global_fov_values[i+1];
break;
}
}
updateFOV()
}
function decFOV()
{
var N = global_fov_values.length;
for(var i=N-1;i>0;i--) {
if(global_fov == global_fov_values[i]
|| (global_fov_values[i-1] < global_fov && global_fov < global_fov_values[i]))
{
global_fov = global_fov_values[i-1];
break;
}
}
updateFOV();
}
function updateFOV()
{
var vals = document.getElementsByClassName("fov_val");
for(var i=0;i<vals.length;i++) {
vals[i].innerHTML = global_fov + "°";
}
}
function setUseGyro(val,message=null,message_tiny=null)
{
global_use_gyro = val;
if(message) {
var status = message;
}
else {
var status= global_use_gyro ? "Aligned" : "Not Aligned";
}
if(message_tiny) {
var status_t = message_tiny;
}
else {
var status_t = global_use_gyro ? "✓" : "✗";
}
document.getElementById("alignment").innerHTML = status;
document.getElementById("alignment_tiny").innerHTML = status_t;
}
function resetAll()
{
global_expecting_select = selectTarget;
findTargetByName();
global_target_index = -1;
showHideInfoIcon();
document.getElementById('find_status').innerHTML = '';
global_align_index = -1;
setUseGyro(false);
}
function align()
{
if(global_expecting_select == doNothing)
return;
/// realign in manual mode
if(global_use_gyro && !global_use_compass) {
// keep bearing
gdata.alpha_user_offset = gdata.alpha_gyro + gdata.alpha_diff - gdata.alpha;
}
setUseGyro(false,"Select Star","?");
global_align_index = -1;
global_expecting_select = selectAlignWithTimer;
}
function normV(v)
{
var len = Math.sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
return [v[0]/len,v[1]/len,v[2]/len];
}
function matMul(A,B)
{
var v1 = mvec(A,[B[0],B[3],B[6]]);
var v2 = mvec(A,[B[1],B[4],B[7]]);
var v3 = mvec(A,[B[2],B[5],B[8]]);
return [v1[0],v2[0],v3[0],
v1[1],v2[1],v3[1],
v1[2],v2[2],v3[2]];
}
function matAdd(A,alpha,B,beta)
{
var res = [];
for(var i=0;i<9;i++) {
res.push(A[i]*alpha + B[i]*beta);
}
return res;
}
function matEye()
{
return [1,0,0, 0,1,0, 0,0,1];
}
function doNothing(index)
{
}
function selectAlignWithTimer(index,start_val=3)
{
var cd = document.getElementById("countdown");
global_align_index = index;
global_expecting_select = doNothing;
if(start_val <= 0) {
cd.innerHTML="";
selectAlign(index);
}
else {
document.getElementById("alignment").innerHTML = '';
document.getElementById("alignment_tiny").innerHTML = '';
cd.innerHTML = start_val.toFixed(1) + "s";
setTimeout(function() {
selectAlignWithTimer(index,start_val - 0.1);
},100);
}
}
function selectAlign(index)
{
var camRays = getCameraRays();
var st = allstars[index];
var tr = rayFromPos(st.RA,st.DE);
var fw = camRays[2];
var left = camRays[1];
var dAZ = Math.asin(crossProd(normV([tr[0],tr[1],0]),normV([fw[0],fw[1],0]))[2]);
var dAlt = Math.asin(tr[2]) - Math.asin(fw[2]);
// rotate around AZ axis
var daz_mat = [ Math.cos(dAZ), Math.sin(dAZ), 0,
-Math.sin(dAZ), Math.cos(dAZ), 0,
0, 0, 1];
// rotate around up/dwn - axis of the camera
var u0 = left[0];
var u1 = left[1];
var u2 = left[2];
var W = [ 0, -u2, u1, u2, 0, -u0, -u1, u0, 0 ]
var dalt_mat = matAdd(matEye(),1,W,Math.sin(-dAlt));
dalt_mat = matAdd(dalt_mat,1,matMul(W,W),2*Math.sin(-dAlt/2)*Math.sin(-dAlt/2));
//global_align_matrix = daz_mat;
global_align_matrix = matMul(daz_mat,dalt_mat);
setUseGyro(true);
gdata.alpha_diff = (gdata.alpha + gdata.alpha_user_offset) - gdata.alpha_gyro;
global_align_index = index;
global_expecting_select = selectTarget;
}
/// rotation matrix is
/// taken from https://www.w3.org/TR/2016/CR-orientation-event-20160818/#worked-example-2
var degtorad = Math.PI / 180; // Degree-to-Radian conversion
function getRotationMatrix( alpha, beta, gamma ) {
var _x = beta ? beta * degtorad : 0; // beta value
var _y = gamma ? gamma * degtorad : 0; // gamma value
var _z = alpha ? alpha * degtorad : 0; // alpha value
var cX = Math.cos( _x );
var cY = Math.cos( _y );
var cZ = Math.cos( _z );
var sX = Math.sin( _x );
var sY = Math.sin( _y );
var sZ = Math.sin( _z );
//
// ZXY rotation matrix construction.
//
var m11 = cZ * cY - sZ * sX * sY;
var m12 = - cX * sZ;
var m13 = cY * sZ * sX + cZ * sY;
var m21 = cY * sZ + cZ * sX * sY;
var m22 = cZ * cX;
var m23 = sZ * sY - cZ * cY * sX;
var m31 = - cX * sY;
var m32 = sX;
var m33 = cX * cY;
return [
m11, m12, m13,
m21, m22, m23,
m31, m32, m33
];
};
function mvec(m,v)
{
return [ m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
m[6] * v[0] + m[7] * v[1] + m[8] * v[2] ];
}
function crossProd(a,b)
{
return [ a[1]*b[2] - a[2]*b[1],
a[2]*b[0] - a[0]*b[2],
a[0]*b[1] - a[1]*b[0] ];
}
function getCameraRays()
{
// zxy
// after Mul comonents are [S,E,D]
var alpha = global_use_gyro ? gdata.alpha_gyro + gdata.alpha_diff : gdata.alpha + gdata.alpha_user_offset;
var M = getRotationMatrix(alpha,gdata.beta,gdata.gamma);
//var top = mvec(M,[1,0,0]);
//var lft = mvec(M,[0,1,0]);
//var fwd = mvec(M,[0,0,-1]);
var fwd = mvec(M,[0,1,0]);
// make sure left is horizontal
var fwd_hlen = Math.sqrt(fwd[0]*fwd[0] + fwd[1]*fwd[1])
var fwd_hor = [fwd[0]/fwd_hlen,fwd[1]/fwd_hlen,0.0];
var lft = [-fwd_hor[1],fwd_hor[0],0.0]
var top = crossProd(fwd,lft);
if(global_use_gyro) {
return [
mvec(global_align_matrix,top),
mvec(global_align_matrix,lft),
mvec(global_align_matrix,fwd)
];
}
else {
return [top,lft,fwd];
}
}
function rayFromPos(RAd,DEd)
{
var deg2rad = Math.PI / 180;
RA = RAd * deg2rad;
DE = DEd * deg2rad;
var jd = gdata.time * 1e-3 / 86400.0 + 2440587.5;
var tu = jd - 2451545.0;
var angle = Math.PI * 2 * (0.7790572732640+1.00273781191135448 * tu);
var q = angle + gdata.lon*deg2rad;
var H = q - RA;
var f = deg2rad * gdata.lat;
var az_y = Math.sin(H);
var az_x = (Math.cos(H) * Math.sin(f) - Math.tan(DE) * Math.cos(f));
var az = Math.atan2(az_y,az_x)
var sinH = Math.sin(f) * Math.sin(DE) + Math.cos(f) * Math.cos(DE) * Math.cos(H);
var hz = Math.asin(sinH)
var ray_n = -Math.cos(az) * Math.cos(hz);
var ray_e = -Math.sin(az) * Math.cos(hz);
var ray_u = Math.sin(hz);
return [ ray_e, ray_n, ray_u ];
}
function sprod(v1,v2)
{
return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
}
function cameraBearing(RAd,DEd,cameraRays)
{
var ray = rayFromPos(RAd,DEd);
var top = cameraRays[0];
var lft = cameraRays[1];
var fwd = cameraRays[2];
var x = -sprod(lft,ray);
var y = sprod(top,ray);
var z = sprod(fwd,ray);
return {"x":x,"y":y,"z":z};
}
function getFOV()
{
var ratio = canvas.width / canvas.height;
var fov_td,fov_lr;
if(ratio < 1) {
fov_td = global_fov;
fov_lr = fov_td * ratio;
}
else {
fov_lr = global_fov;
fov_td = fov_lr / ratio;
}
return {"lr":fov_lr,"td":fov_td};
}
function xyzTo2d(xyz,in_fov=true)
{
var deg2rad = Math.PI / 180;
var fov = getFOV();
var fov_td = fov.td * deg2rad / 2;
var fov_lr = fov.lr * deg2rad / 2;
var x=xyz.x; var y=xyz.y; var z=xyz.z;
if(z<=0)
return null;
if(global_camera_projection) {
var lim_x = Math.sin(fov_lr);
var lim_y = Math.sin(fov_td);
}
else {
x = Math.asin(x);
y = Math.asin(y)
var lim_x = fov_lr;
var lim_y = fov_td;
}
if(in_fov) {
if(x < -lim_x || x > lim_x)
return null;
if(y < -lim_y || y > lim_y)
return null;
}
return { x:(x + lim_x) / (lim_x*2), y: 1 - (y + lim_y) / (lim_y * 2) };
}
function projectToCamera(RAd,DEd,cameraRays,in_fov=true)