-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
2402 lines (2056 loc) · 131 KB
/
index.html
File metadata and controls
2402 lines (2056 loc) · 131 KB
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>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>IIMC Card Tool</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
:root {
--bg: #18191a; --card: #242526; --text: #e4e6eb; --border: #3e4042;
--primary: #478df5; --secondary: #3a3b3c; --danger: #fb6161;
--success: #28a745; --earth: #2d81ff; --link: #a3c7ff; --dispatch: #f39c12;
--section-bg: rgba(0,0,0,0.15);
--input-bg: #3a3b3c;
}
[data-theme="light"] {
--bg: #f0f2f5; --card: #ffffff; --text: #1c1e21; --border: #dadde1;
--primary: #1a73e8; --secondary: #e4e6eb; --danger: #fa3e3e;
--link: #1a73e8; --dispatch: #f39c12;
--section-bg: #f7f8fa;
--input-bg: #ffffff;
}
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; margin: 10px; background: var(--bg); color: var(--text); transition: background 0.3s; }
.container { max-width: 900px; margin: auto; background: var(--card); padding: 20px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.header-row { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid var(--border); padding-bottom: 15px; margin-bottom: 20px; }
h2 { margin: 0; color: var(--primary); font-size: 20px; }
.session-status-card { background: var(--secondary); padding: 12px 15px; border-radius: 8px; border: 1px solid var(--border); font-size: 11px; margin-bottom: 20px; }
.status-line { margin-top: 6px; display: flex; justify-content: space-between; align-items: center; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #555; display: inline-block; flex-shrink: 0; }
.status-dot.ready { background: var(--success); }
.status-dot.loading { background: var(--dispatch); animation: dbPulse 1s infinite; }
@keyframes dbPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.section-card { border: 1px solid var(--border); border-radius: 8px; padding: 15px; margin-bottom: 15px; background: var(--section-bg); }
.section-title { font-weight: bold; color: var(--primary); margin-bottom: 12px; text-transform: uppercase; font-size: 10px; letter-spacing: 0.5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }
label { display: block; font-weight: bold; color: var(--text); font-size: 12px; margin-bottom: 6px; }
input[type="number"], input[type="text"] { width: 100%; padding: 12px; background: var(--input-bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; box-sizing: border-box; font-size: 15px; font-weight: bold; -webkit-appearance: none; }
.btn-group { margin-top: 25px; }
button.action { width: 100%; padding: 16px; background-color: var(--success); color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: bold; cursor: pointer; transition: 0.2s; }
.output-block { background: var(--input-bg); border: 1px solid var(--border); border-radius: 6px; padding: 15px; text-align: center; }
.output-label { font-size: 10px; text-transform: uppercase; color: #90949c; font-weight: bold; margin-bottom: 5px; }
.output-value { font-size: 26px; font-weight: bold; color: var(--text); }
.output-value.msa-val { color: var(--danger); }
.output-value.freq-val { color: var(--success); }
.audit-text { font-size: 11px; color: #a0a4ac; margin-bottom: 8px; font-family: monospace; line-height: 1.4; }
.audit-highlight { color: var(--text); font-weight: bold; }
/* New Split Layout Styles */
.split-layout { display: flex; gap: 20px; align-items: flex-start; }
.split-left { flex: 1; min-width: 0; width: 100%; }
.split-right { flex: 0 0 300px; min-width: 0; }
/* Convert audit grid to a vertical stack */
.audit-grid, .audit-grid.multi { display: flex; flex-direction: column; gap: 12px; padding-right: 5px; }
@media (max-width: 768px) {
.split-layout { flex-direction: column; }
.audit-grid, .audit-grid.multi { max-height: none; overflow-y: visible; padding-right: 0; }
}
.action-btn { background: var(--card); border: 1px solid var(--border); color: var(--text); padding: 10px; border-radius: 6px; cursor: pointer; }
/* Map UI Additions */
.btn-preview { background-color: var(--earth); margin-top: 10px; }
.btn-preview:hover { background-color: #1a60d4; }
#mapOverlay {
display: none; position: fixed; top: 5%; left: 5%; width: 90%; height: 80%;
background: var(--card); z-index: 3000; border: 2px solid var(--primary);
border-radius: 12px; overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,0.8);
}
#mapOverlay.maximized { width: 100vw; height: 100vh; top: 0; left: 0; border: none; border-radius: 0; }
#map { width: 100%; height: 100%; background: #222; }
.map-command-bar {
position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
width: auto; background: rgba(30, 31, 32, 0.98); border: 1px solid var(--border); border-radius: 12px;
padding: 10px 20px; display: flex; align-items: center; gap: 15px;
box-shadow: 0 10px 40px rgba(0,0,0,0.6); backdrop-filter: blur(12px); z-index: 9999 !important;
}
.cmd-group { display: flex; align-items: center; gap: 8px; position: relative; }
.cmd-divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.layer-switch { display: flex; background: rgba(0,0,0,0.4); border-radius: 6px; padding: 2px; border: 1px solid var(--border); }
.layer-btn { background: transparent; border: none; color: #888; padding: 8px 12px; font-size: 11px; font-weight: 600; cursor: pointer; border-radius: 4px; transition: 0.2s; white-space: nowrap; height: 32px; display: flex; align-items: center; }
.layer-btn.active { background: var(--primary); color: white; }
.close-btn { background: var(--danger); border-color: var(--danger); color: white; }
/* --- KNEEBOARD TEMPLATE STYLES (Shared by Print & Preview) --- */
#print-container { display: none; font-family: Arial, sans-serif; color: black; }
.print-landscape-sheet { display: flex; flex-direction: row; width: 11in; height: 8.5in; background: white; box-sizing: border-box; margin: 0 auto; }
.print-page, .print-notes { display: flex; flex-direction: column; width: 5.5in; height: 8.5in; box-sizing: border-box; padding: 0.25in; overflow: hidden; }
.print-notes { border-left: 1px dashed #ccc; background: white; }
.print-header { display: flex; justify-content: flex-start; align-items: stretch; height: 55px; margin-bottom: 0; gap: 0; }
.print-logo-box, .print-title-box, .print-meta-box { border: 2px solid black; border-bottom: none; padding: 4px; display: flex; flex-direction: column; justify-content: center; box-sizing: border-box; container-type: inline-size; }
.print-logo-box { width: 18%; text-align: center; border-right: none; }
.print-title-box { width: 52%; text-align: center; font-weight: bold; border-right: none; }
.print-title-box .print-title { height: 100%; width: 100%; display: flex; flex-direction: column; justify-content: center; font-size: clamp(12px, 6cqi, 22px); line-height: 1.1; margin: 0; }
.print-meta-box { width: 30%; font-weight: bold; }
.print-meta-box .print-meta { font-size: 14px; line-height: 1.3; display: block; margin: 0; }
.print-body { border: 3px solid black; display: flex; flex-direction: column; flex: 1; box-sizing: border-box; overflow: hidden; }
.print-diagram-section { position: relative; flex: 1; display: flex; justify-content: center; align-items: center; padding: 10px; box-sizing: border-box; overflow: hidden; }
.print-freq-box { position: absolute; top: 10px; right: 10px; text-align: center; font-size: 11px; font-weight: bold; z-index: 10; background: white; padding: 4px; border: 1px solid black; line-height: 1.1; }
.print-circle-container { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; background: white; box-sizing: border-box; border-radius: 50%; }
.print-circle-container svg { max-width: 100%; max-height: 100%; }
.print-center-text { text-align: center; font-size: 24px; font-weight: bold; line-height: 1.2; }
.print-center-text span { font-size: 20px; }
.active-layout-btn { background: var(--primary) !important; color: white !important; border-color: var(--primary) !important; }
.print-instructions-section { border-top: 3px solid #1a237e; padding: 12px; font-size: 12px; line-height: 1.3; box-sizing: border-box; }
.print-avoid { margin-bottom: 10px; font-size: 11px; }
.print-section-title { font-weight: bold; font-size: 13px; margin-bottom: 5px; }
.print-recover ul { margin: 0; padding-left: 18px; list-style-type: disc; }
.print-recover li { margin-bottom: 4px; padding-left: 4px; }
.print-note { font-weight: normal; margin: 8px 0; font-size: 11px; }
.notes-header { font-weight: bold; font-size: 14px; margin-bottom: 10px; text-align: center; text-transform: uppercase; border-bottom: 2px solid black; padding-bottom: 5px; }
.notes-textarea { flex: 1; width: 100%; border: none; resize: none; font-family: inherit; font-size: 12px; line-height: 1.5; outline: none; background: transparent; }
/* --- PREVIEW MODE (Screen Only) --- */
@media screen {
body.preview-mode { background: #222 !important; overflow-y: auto; overflow-x: auto; }
body.preview-mode .container, body.preview-mode #mapOverlay { display: none !important; }
body.preview-mode #print-container { display: flex; flex-direction: column; align-items: center; padding: 40px 20px; min-height: 100vh; transition: padding-left 0.3s ease; }
body.is-customizing #print-container { padding-left: 280px; }
body.preview-mode .print-landscape-sheet { background: white; box-shadow: 0 10px 30px rgba(0,0,0,0.8); border-radius: 4px; }
}
/* --- ACTUAL PRINT SPOOLER STYLES --- */
@media print {
@page { size: letter landscape; margin: 0; }
body { background: white !important; margin: 0 !important; padding: 0 !important; width: 11in !important; height: 8.5in !important; overflow: hidden !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.container, #mapOverlay, .customize-sidebar, .modal-overlay, .app-footer, .header-row { display: none !important; }
#print-container { display: block !important; width: 11in !important; height: 8.5in !important; margin: 0 !important; padding: 0 !important; }
.print-landscape-sheet { width: 11in !important; height: 8.5in !important; margin: 0 !important; padding: 0 !important; box-shadow: none !important; border-radius: 0 !important; page-break-after: avoid; page-break-inside: avoid; }
.print-notes { border-left: 1px dashed transparent !important; }
}
/* --- CUSTOMIZE MODE STYLES --- */
body.is-customizing .print-page { outline: 2px dashed var(--primary); }
body.is-customizing .draggable-box { cursor: grab; }
body.is-customizing .draggable-box:active { cursor: grabbing; }
body.is-dragging .editable-text { outline: none !important; background: transparent !important; }
body.is-customizing .editable-text { outline: 1px dashed rgba(71, 141, 245, 0.5); background: rgba(71, 141, 245, 0.05); transition: 0.2s; }
body.is-customizing .editable-text:hover { outline: 2px solid var(--primary); background: rgba(71, 141, 245, 0.1); }
.customize-sidebar {
position: fixed; top: 0; left: -300px; width: 260px; height: 100vh;
background: var(--card); border-right: 1px solid var(--border);
box-shadow: 4px 0 15px rgba(0,0,0,0.5); z-index: 10000;
padding: 15px; box-sizing: border-box; transition: left 0.3s ease;
display: flex; flex-direction: column; gap: 12px; overflow-y: auto;
}
body.is-customizing .customize-sidebar { left: 0; }
.customize-sidebar h3 { margin: 0 0 10px 0; color: var(--primary); font-size: 16px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.sidebar-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: bold; }
.btn-sidebar { background: var(--secondary); color: var(--text); border: 1px solid var(--border); padding: 8px 12px; border-radius: 6px; cursor: pointer; width: 100%; font-weight: bold; margin-top: 10px; }
.btn-sidebar:hover { background: var(--border); }
@media print {
.customize-sidebar { display: none !important; }
.editable-text { outline: none !important; background: transparent !important; }
.freq-box .editable-text { background: white !important; }
}
/* --- UI Updates: Header, Footer, Modals, Print --- */
.version-subtitle { font-size: 11px; color: var(--link); margin-top: 4px; margin-bottom: 20px; display: inline-block; font-weight: normal; cursor: pointer; text-decoration: underline; }
.project-link { font-size: 11px; color: #90949c; margin-left: 15px; text-decoration: underline; cursor: pointer; transition: color 0.2s; }
.project-link:hover { color: var(--link); }
.app-footer { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border); font-size: 11px; color: #90949c; line-height: 1.6; text-align: left; }
.disclaimer-bold { font-weight: bold; color: var(--text); }
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.75); z-index: 5999; }
#versionHistory { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--card); border: 2px solid var(--primary); padding: 25px; border-radius: 12px; font-size: 12px; z-index: 6000; box-shadow: 0 10px 30px rgba(0,0,0,0.5); max-width: 500px; width: 90%; max-height: 80vh; overflow-y: auto; color: var(--text); line-height: 1.6; }
.sticky-action-bar {
position: sticky;
top: 0;
z-index: 1002;
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
box-shadow: 0 8px 16px rgba(0,0,0,0.3);
background: rgba(36, 37, 38, 0.85) !important;
border-bottom: 3px solid var(--primary) !important;
}
[data-theme="light"] .sticky-action-bar { background: rgba(255, 255, 255, 0.85) !important; }
@media print { .no-print { display: none !important; } }
</style>
</head>
<body data-theme="dark">
<div class="modal-overlay no-print" id="historyOverlay" onclick="toggleVersionHistory()">
<div id="versionHistory" onclick="event.stopPropagation()">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:15px; border-bottom:1px solid var(--border); padding-bottom:10px;">
<strong style="color:var(--primary); font-size:14px;">Version History</strong>
<span style="cursor:pointer; font-size:18px; opacity:0.7;" onclick="toggleVersionHistory()">✕</span>
</div>
<b>v3.0.1</b> - Reorganized repository structure to fix GitHub Pages routing and data script pathing.<br>
<b>v2.6</b> - Fixed database update to correctly download current DOF.<br>
<b>v2.5.1</b> - Added single-sector card scaling options.<br>
<b>v2.5</b> - Added manual frequency changes to save/load with template.<br>
<b>v2.4.4.7</b> - Made action bar buttons sticky.<br>
<b>v2.4.4.1</b> - Revised action bar buttons.<br>
<b>v2.4.3.1</b> - UI refinements. Fixed kneeboard date to align with DOF/sectional expiry.<br>
<b>v2.4.3</b> - Added user input data validation logic.<br>
<b>v2.4.2</b> - Fixed antimeridian wrapping bug (Aleutian Islands / Dateline Fix).<br>
<b>v2.4.1</b> - Fixed expiration date on kneeboard card to correctly reflect next AIRAC cycle.<br>
<b>v2.4</b> - Major update - integrated new terrain engine using NumPY array to ensure correct resolution of highest points.<br>
<b>v2.3</b> - Revised frequency search logic to account FAA encoding of larger airports.<br>
<b>v2.2</b> - Overhauled kneeboard print options and menu.<br>
<b>v2.1</b> - Minor UI updates.<br>
<b>v2.0.1</b> - Transitioned to web-based deployment on GitHub.<br>
<b>v1.9.5</b> - Updated terrain model to Copernicus GLO-30. Added usage instructions and pre-flight disclaimers.<br>
<b>v1.9.4</b> - Added Map Preview functionality.<br>
</div>
</div>
<div class="container">
<div class="header-row no-print">
<div>
<h2 style="margin: 0; color: var(--primary); line-height: 1; font-size: 22px;">IIMC Card Tool</h2>
<span class="version-subtitle" onclick="toggleVersionHistory()">v3.0.1</span>
<a href="https://github.com/cwmauze/iimc-card-tool" target="_blank" class="project-link">GitHub project home</a>
<a href="mailto:cistern_fob3m@icloud.com" class="project-link">Contact / Feedback</a>
</div>
<button class="action-btn" onclick="toggleTheme()" id="themeBtn" style="font-size: 16px; padding: 6px 10px; height: auto;">☀️</button>
</div>
<div class="grid-2 no-print" style="margin-bottom: 20px; align-items: stretch;">
<div style="font-size: 13px; color: #90949c; line-height: 1.5; border-left: 2px solid var(--border); padding-left: 15px; display: flex; flex-direction: column; justify-content: center;">
<strong style="color: var(--text); margin-bottom: 4px;">Pre-Flight Data Prep:</strong>
<div>1. <strong>Define Location:</strong> Enter an FAA Identifier or precise Lat/Lon and set the action radius.</div>
<div>2. <strong>Configure Sectors:</strong> Use a standard 360° ring or toggle custom magnetic sectors.</div>
<div>3. <strong>Audit & Preview:</strong> Verify controlling obstacles/terrain (Copernicus 30m) and preview on the map.</div>
<div>4. <strong>Export:</strong> Export to .PDF to arrange and print your kneeboard card.</div>
</div>
<div class="session-status-card" style="margin-bottom: 0;">
<div style="font-weight: bold; color: var(--primary); text-transform: uppercase; font-size: 10px;">Database Status</div>
<div class="status-line">
<span>Airport/heliport data (NASR):</span>
<div style="display:flex; align-items:center; gap:8px;">
<span id="apt-status">Checking...</span>
<div class="status-dot loading" id="apt-dot"></div>
</div>
</div>
<div class="status-line">
<span>Obstacle data (DOF):</span>
<div style="display:flex; align-items:center; gap:8px;">
<span id="obs-status">Checking...</span>
<div class="status-dot loading" id="obs-dot"></div>
</div>
</div>
<div class="status-line">
<span>Topographical Terrain (Copernicus 30m):</span>
<div style="display:flex; align-items:center; gap:8px;">
<span id="usgs-status">Checking...</span>
<div class="status-dot loading" id="usgs-dot"></div>
</div>
</div>
<div class="status-line">
<span>Magnetic Model (WMM):</span>
<div style="display:flex; align-items:center; gap:8px;">
<span id="mag-status">Checking...</span>
<div class="status-dot loading" id="mag-dot"></div>
</div>
</div>
</div>
</div>
<style>
.container { max-width: 1600px !important; width: 96%; transition: max-width 0.3s ease-in-out; }
.export-toolbar { display: flex; align-items: stretch; gap: 10px; flex: 1; justify-content: flex-end; }
.export-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px 12px; border-radius: 6px; border: none; color: white; cursor: pointer; text-align: center; transition: opacity 0.2s; min-width: 110px; font-family: inherit; }
.export-btn:hover { opacity: 0.85; }
.export-icon { margin-bottom: 4px; }
.export-title { font-size: 12px; font-weight: bold; margin-bottom: 2px; }
.export-sub { font-size: 8px; text-transform: uppercase; opacity: 0.9; }
.btn-map { background-color: #4285F4; }
.btn-pdf { background-color: #0F9D58; }
.btn-reset { background-color: #DB4437; min-width: 70px; }
.efb-toggle { position: relative; display: inline-block; width: 44px; height: 24px; margin: 0; }
.efb-toggle input { opacity: 0; width: 0; height: 0; }
.efb-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border); transition: .2s; border-radius: 24px; }
.efb-slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: var(--text); transition: .2s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.3); }
.efb-toggle input:checked + .efb-slider { background-color: var(--primary); }
.efb-toggle input:checked + .efb-slider:before { transform: translateX(20px); background-color: #fff; }
/* Segmented Control Styles */
.segmented-control { display: inline-flex; background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.segmented-control input { display: none; }
.segmented-control label { padding: 8px 16px; font-size: 13px; font-weight: bold; color: #a0a4ac; cursor: pointer; border-radius: 6px; transition: background 0.2s, color 0.2s; margin: 0; }
.segmented-control input:checked + label { background: var(--primary); color: white; }
</style>
<div class="section-card">
<div class="section-title">Location Parameters</div>
<div style="margin-bottom: 12px;">
<div class="segmented-control">
<input type="radio" name="centerMode" id="cm-faa" value="faa" checked onchange="toggleCenterInput()">
<label for="cm-faa">FAA Identifier</label>
<input type="radio" name="centerMode" id="cm-coord" value="coord" onchange="toggleCenterInput()">
<label for="cm-coord">Lat/Lon Coordinates</label>
</div>
</div>
</div>
<div class="sticky-action-bar" style="display: flex; gap: 20px; align-items: center; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 8px; padding: 15px 15px 28px 15px; margin-bottom: 15px;">
<div style="flex: 0 0 auto;">
<input type="file" id="template-upload" accept=".json" style="display: none;" onchange="loadTemplate(event)">
<button class="export-btn" style="background-color: #546E7A; height: 100%; min-height: 65px; justify-content: center;" onclick="document.getElementById('template-upload').click()">
<svg class="export-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="17 8 12 3 7 8"></polyline><line x1="12" y1="3" x2="12" y2="15"></line></svg>
<span class="export-title">Load Setup</span>
<span class="export-sub">JSON TEMPLATE</span>
</button>
</div>
<div style="width: 1px; min-height: 60px; background: var(--border); align-self: stretch;"></div>
<div style="flex: 0 0 auto; min-width: 260px;">
<div id="faaWrap" style="position: relative;">
<label>Centerpoint (FAA ID)</label>
<input type="text" id="centerpoint" placeholder="E.G. KRWI" style="text-transform: uppercase;" oninput="handleLocationChange()">
<div id="facilityName" style="position: absolute; top: 100%; left: 0; font-size: 11px; font-weight: bold; margin-top: 6px; color: var(--success); white-space: nowrap;"></div>
</div>
<div id="coordWrap" style="display: none; position: relative;">
<div style="display: flex; gap: 10px;">
<div style="width: 150px;">
<label>Latitude</label>
<input type="text" id="latInput" placeholder="e.g. 35.85" oninput="handleLocationChange()">
</div>
<div style="width: 150px;">
<label>Longitude</label>
<input type="text" id="lonInput" placeholder="e.g. -77.89" oninput="handleLocationChange()">
</div>
<div style="width: 100px;">
<label>ID</label>
<input type="text" id="customLabel" placeholder="e.g. LZ-1" style="text-transform: uppercase;" oninput="handleLocationChange()" maxlength="6">
</div>
</div>
<div id="coordHelper" style="position: absolute; top: 100%; left: 0; font-size: 11px; font-weight: bold; margin-top: 6px; color: var(--link); white-space: nowrap;">Accepts decimal or DMS</div>
</div>
</div>
<div style="width: 1px; min-height: 60px; background: var(--border); align-self: stretch;"></div>
<div style="display: flex; gap: 20px; align-items: flex-start; flex: 0 0 auto;">
<div style="width: 75px; flex-shrink: 0;">
<label>Radius</label>
<input type="number" id="radius" value="30" oninput="triggerLiveUpdate()" style="text-align: center;">
</div>
<div style="display: flex; flex-direction: column;">
<label>Custom sectors</label>
<div style="display: flex; gap: 12px; height: 42px; align-items: center;">
<input type="radio" name="sectorMode" id="sm-single" value="single" checked style="display: none;">
<input type="radio" name="sectorMode" id="sm-custom" value="custom" style="display: none;">
<label class="efb-toggle" title="Toggle Custom Sectors">
<input type="checkbox" id="ui-sector-toggle" onchange="syncSectors(this)">
<span class="efb-slider"></span>
</label>
<div id="sector-btn-wrapper" style="display: none; align-items: center; gap: 6px; margin-left: 8px;">
<button class="action-btn" id="btn-rem-sector" onclick="removeSectorHandle()" disabled style="padding: 0; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: bold; border-color: var(--border); line-height: 1;" title="Remove Sector">−</button>
<button class="action-btn" id="btn-add-sector" onclick="addSectorHandle()" disabled style="padding: 0; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: bold; background: var(--primary); color: white; border: none; line-height: 1;" title="Add Sector">+</button>
</div>
</div>
</div>
</div>
<div style="width: 1px; min-height: 60px; background: var(--border); align-self: stretch;"></div>
<div class="export-toolbar">
<button class="export-btn btn-map" onclick="showMapPreview()">
<svg class="export-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="1 6 1 22 8 18 16 22 23 18 23 2 16 6 8 2 1 6"></polygon><line x1="8" y1="2" x2="8" y2="18"></line><line x1="16" y1="6" x2="16" y2="22"></line></svg>
<span class="export-title">Preview on map</span>
<span class="export-sub">STREET / SAT / VFR</span>
</button>
<button class="export-btn btn-pdf" onclick="generateKneeboard()">
<svg class="export-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>
<span class="export-title">Generate kneeboard</span>
<span class="export-sub">IIMC CARD</span>
</button>
<button class="export-btn btn-reset" onclick="resetApp()">
<svg class="export-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>
<span class="export-title">CLEAR</span>
<span class="export-sub">ALL DATA</span>
</button>
</div>
</div>
<script>
function syncSectors(checkbox) {
document.getElementById('sm-custom').checked = checkbox.checked;
document.getElementById('sm-single').checked = !checkbox.checked;
toggleSectorUI();
}
function resetApp() {
document.getElementById('centerpoint').value = '';
document.getElementById('latInput').value = '';
document.getElementById('lonInput').value = '';
document.getElementById('customLabel').value = '';
document.getElementById('radius').value = '30';
document.querySelector('input[name="centerMode"][value="faa"]').checked = true;
toggleCenterInput();
const toggleBtn = document.getElementById('ui-sector-toggle');
if (toggleBtn) {
toggleBtn.checked = false;
syncSectors(toggleBtn);
}
document.getElementById('audit-container').innerHTML = '<div class="audit-sector-card" id="audit-single"><div class="audit-text" id="audit-terr">Highest Terrain: --</div><div class="audit-text" id="audit-obs">Highest Obstacle: --</div><div class="audit-text" style="margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px;" id="audit-math">Formula: --</div></div>';
document.getElementById('sectorUI').style.display = 'none';
// FIX: Reset the MagVar UI status text
const magUi = document.getElementById('mag-status');
if (magUi) {
magUi.innerText = "Verified (WMM 2025-2030 Epoch)";
}
currentCalc = null;
// FIX: Wipe the persistent sector math back to a clean slate
wheelSectors = [0];
window.currentSectors = [];
draggingHandle = null;
// Force the background wheel to redraw with the fresh data
if (typeof updateWheel === 'function') {
updateWheel();
}
}
</script>
<div class="section-card" id="combined-section" style="background: rgba(0,0,0,0.15);">
<div class="section-title">Sector Configuration & Calculation Audit</div>
<div class="split-layout">
<div class="split-left">
<div id="sector-helper-text" style="display: none; font-size: 11px; font-style: italic; color: #a0a4ac; margin-bottom: 10px; text-align: center;">Drag the handles on the wheel to adjust sector boundaries.</div>
<div id="sectorUI" style="display: none;">
<div class="wheel-container" style="text-align: center; margin-bottom: 15px;">
<svg class="wheel-svg" viewBox="-160 -160 320 320" style="width: 100%; max-width: 700px; height: auto; overflow: visible;" id="sector-wheel">
<circle cx="0" cy="0" r="100" fill="rgba(255,255,255,0)" stroke="var(--border)" stroke-width="2" />
<circle cx="0" cy="0" r="6" class="wheel-center" fill="var(--text)" />
</svg>
</div>
</div>
</div>
<div class="split-right">
<div id="audit-container" class="audit-grid">
<div class="audit-sector-card" id="audit-single">
<div class="audit-text" id="audit-terr">Highest Terrain: --</div>
<div class="audit-text" id="audit-obs">Highest Obstacle: --</div>
<div class="audit-text" style="margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px;" id="audit-math">Formula: --</div>
</div>
</div>
</div>
</div>
</div>
<footer class="app-footer no-print">
<span class="disclaimer-bold">DISCLAIMER:</span> This tool is strictly designed to assist pilots in pre-flight planning and the development of local IIMC procedures. The pilot in command remains solely responsible for verifying all altitudes, frequencies, and headings against current, official flight information publications prior to flight.
</footer>
</div>
<div id="mapOverlay">
<div id="map-header-badge" style="position: absolute; top: 20px; left: 20px; background: rgba(30, 31, 32, 0.85); border: 1px solid var(--border); padding: 8px 15px; border-radius: 8px; color: var(--text); font-size: 14px; font-weight: bold; z-index: 9999; backdrop-filter: blur(8px); box-shadow: 0 4px 12px rgba(0,0,0,0.5); pointer-events: none;">
Preview: ---
</div>
<div class="map-command-bar">
<div class="cmd-group">
<div class="layer-switch">
<button class="layer-btn active" id="b-street" onclick="setBaseView('street')">Map Light</button>
<button class="layer-btn" id="b-dark" onclick="setBaseView('dark')">Map Dark</button>
<button class="layer-btn" id="b-sat" onclick="setBaseView('sat')">Satellite</button>
<button class="layer-btn" id="b-vfr" onclick="setBaseView('vfr')">VFR Sectional</button>
</div>
</div>
<div class="cmd-divider"></div>
<div class="cmd-group" style="margin-left:auto;">
<button class="action-btn" onclick="recenterMap()" title="Recenter Map">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><circle cx="12" cy="12" r="3"></circle></svg>
</button>
<button class="action-btn" onclick="toggleMaximize()" title="Toggle Fullscreen">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"></path></svg>
</button>
<button class="action-btn close-btn" onclick="hideMap()">Close</button>
</div>
</div>
<div id="map"></div>
</div>
<div id="print-container">
<div class="customize-sidebar" id="customizeSidebar">
<div style="font-size: 11px; color: #a0a4ac; line-height: 1.4; margin-bottom: 10px;">
<b>Instructions:</b><br>
• <b>Drag</b> items to move them.<br>
• <b>Click</b> highlighted text to edit.<br>
• Changes appear exactly as printed.
</div>
<div id="customization-sliders" style="background: var(--section-bg); padding: 10px; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 12px;">
<strong style="font-size: 10px; text-transform: uppercase; color: var(--primary); display: block; margin-bottom: 10px;">1. Adjust Sizing</strong>
<div style="margin-bottom: 12px;">
<label style="font-size: 11px; margin-bottom: 4px; display: block; color: var(--text);">MSA Text Size <span id="val-msa-scale" style="float: right; color: var(--success); font-family: monospace;">1.00x</span></label>
<input type="range" id="slider-msa-scale" min="0.5" max="2.0" step="0.05" value="1.0" style="width: 100%; cursor: pointer;">
</div>
<div style="margin-bottom: 12px;">
<label style="font-size: 11px; margin-bottom: 4px; display: block; color: var(--text);">Frequency box size <span id="val-freq-scale" style="float: right; color: var(--success); font-family: monospace;">1.00x</span></label>
<input type="range" id="slider-freq-scale" min="0.5" max="2.0" step="0.05" value="1.0" style="width: 100%; cursor: pointer;">
</div>
<div style="margin-bottom: 12px;">
<label style="font-size: 11px; margin-bottom: 4px; display: block; color: var(--text);">Degree Marker Size <span id="val-deg-scale" style="float: right; color: var(--success); font-family: monospace;">1.00x</span></label>
<input type="range" id="slider-deg-scale" min="0.5" max="2.0" step="0.05" value="1.0" style="width: 100%; cursor: pointer;">
</div>
<div style="margin-bottom: 0;">
<label style="font-size: 11px; margin-bottom: 4px; display: block; color: var(--text);">Degree Marker Distance <span id="val-degDist-scale" style="float: right; color: var(--success); font-family: monospace;">270px</span></label>
<input type="range" id="slider-degDist-scale" min="120" max="420" step="5" value="270" style="width: 100%; cursor: pointer;">
</div>
</div>
<div style="background: var(--section-bg); padding: 10px; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 12px;">
<strong style="font-size: 10px; text-transform: uppercase; color: var(--primary); display: block; margin-bottom: 10px;">2. Branding</strong>
<div class="sidebar-row" style="color: var(--text);">
<span style="font-size: 11px; font-weight: normal;">Company Logo</span>
<label class="efb-toggle" style="margin: 0;">
<input type="checkbox" id="toggle-logo-btn" onchange="togglePrintLogo()">
<span class="efb-slider"></span>
</label>
</div>
<div id="logo-select-wrapper" style="display: none; margin-top: 10px;">
<select id="logo-selector" onchange="updateLogoImage()" style="width: 100%; padding: 8px; background: var(--input-bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; cursor: pointer;">
<option value="https://www.metrohealth.org/globalassets/metrohealth-images/life-flight/metro-aviation-logo.jpg">Metro Aviation</option>
<option value="https://www.globalmedicalresponse.com/img/gmr-logo-web.png">Global Medical Response (GMR)</option>
<option value="https://phoenixchildrens.org/sites/default/files/2025-04/airmethods-logo_0.png">Air Methods</option>
<option value="https://www.phiairmedical.com/wp-content/uploads/sites/3/2021/07/PHI-Air-Medical_YLW_WHT.png">PHI Air Medical</option>
<option value="https://placehold.co/400x120/ffffff/0f9d58?text=CUSTOM+OPERATOR&font=montserrat">Custom Operator</option>
</select>
</div>
</div>
<div style="background: var(--section-bg); padding: 10px; border-radius: 8px; border: 1px solid var(--border);">
<strong style="font-size: 10px; text-transform: uppercase; color: var(--primary); display: block; margin-bottom: 10px;">3. Right Half Layout</strong>
<div class="segmented-control" style="width: 100%; display: flex; box-sizing: border-box;" id="layout-btn-group">
<input type="radio" name="rightLayout" id="rl-blank" value="blank" checked onchange="setRightLayout('blank')">
<label for="rl-blank" style="flex: 1; text-align: center; font-size: 10px; padding: 6px; margin: 0;">Blank</label>
<input type="radio" name="rightLayout" id="rl-duplicate" value="duplicate" onchange="setRightLayout('duplicate')">
<label for="rl-duplicate" style="flex: 1; text-align: center; font-size: 10px; padding: 6px; margin: 0;">Duplicate</label>
<input type="radio" name="rightLayout" id="rl-notes" value="notes" onchange="setRightLayout('notes')">
<label for="rl-notes" style="flex: 1; text-align: center; font-size: 10px; padding: 6px; margin: 0;">Free Text</label>
</div>
</div>
<script>
function setRightLayout(mode) {
const rightSide = document.getElementById('notes-side');
if (mode === 'blank') {
rightSide.innerHTML = '';
} else if (mode === 'duplicate') {
rightSide.innerHTML = document.getElementById('card-side').innerHTML;
} else if (mode === 'notes') {
rightSide.innerHTML = '<div class="notes-header">Flight Notes</div><div class="notes-textarea" contenteditable="true" style="outline: none; min-height: 50%;">Enter free text, frequencies, or flight log details here...</div>';
}
}
</script>
<div style="margin-top: auto; display: flex; flex-direction: column; gap: 8px;">
<button class="btn-sidebar" style="margin-top: 0;" onclick="generateKneeboard()">Reset Layout</button>
<button class="btn-sidebar" style="margin-top: 0; background: var(--primary); color: white; border: none;" onclick="saveTemplate()">Save Template</button>
<button class="btn-sidebar" style="margin-top: 0; background: var(--success); color: white; border: none;" onclick="window.print()">Print Card</button>
<button class="btn-sidebar" style="margin-top: 0; background: var(--danger); color: white; border: none;" onclick="closePreview()">Close</button>
</div>
</div>
<div class="print-landscape-sheet">
<div class="print-page" id="card-side">
<div class="print-header">
<div class="print-logo-box" style="padding: 2px;">
<img id="print-logo-img" src="https://www.metrohealth.org/globalassets/metrohealth-images/life-flight/metro-aviation-logo.jpg" style="max-width: 100%; max-height: 45px; object-fit: contain; display: block; margin: 0 auto;">
</div>
<div class="print-title-box">
<div class="print-title">IIMC procedure for 30 NM radius.<br>MSA Chart oriented to MAG N</div>
</div>
<div class="print-meta-box">
<div class="print-meta">Location: <span id="print-loc-1">---</span><br><span style="color: #40a0c6; text-decoration: underline;">Expires: <span id="print-exp-1">---</span></span></div>
</div>
</div>
<div class="print-body">
<div class="print-diagram-section">
<div class="print-freq-box">
<u>ATC FREQ: <span id="print-freq-1">---</span></u><br>
<span id="print-ctr-1" style="font-weight: bold;">---</span>
</div>
<div class="print-circle-container" id="print-wheel-1">
<div class="print-center-text">
<div id="print-center-label-1">---</div>
<div>MSA: <span id="print-msa-1">---</span></div>
</div>
</div>
</div>
<div class="print-instructions-section">
<div class="print-avoid"><i><u>AVOID</u> - Be aware of the WX conditions and be prepared for the possibility of IIMC or loss of visual reference. Always maintain situational awareness and pay close attention to weather changes.</i></div>
<div class="print-section-title"><i><u>RECOVER</u></i></div>
<div class="print-recover">
<ul>
<li>Attitude (Level the wings on the attitude indicator)</li>
<li>Heading (Maintain the aircraft heading, turning only to avoid known obstacles</li>
<li>Power (Adjust engine power to applicable climb power)</li>
<li>Airspeed (Adjust airspeed to climb airspeed, after the aircraft is stabilized</li>
</ul>
<div class="print-note"><b>NOTE:</b> Once established on instruments above 60kts, engage A/P upper modes</div>
<ul>
<li>Climb to the Minimum Safe Altitude</li>
<li>De-goggle when safely able (if applicable)</li>
<li>Contact appropriate ATC or use Guard (121.5) and <b>DECLARE AN EMERGENCY</b></li>
<li>Set transponder to squawk "7700"</li>
<li>Request vectors to VFR conditions or if no VFR, request IFR clearance to nearest appropriate landing facility with an approach.</li>
<li>Brief other personnel on board of situation (if applicable)</li>
</ul>
</div>
</div>
</div>
</div>
<div class="print-notes" id="notes-side"></div>
</div>
</div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" defer></script>
<script>
function toggleVersionHistory() {
const overlay = document.getElementById('historyOverlay');
const box = document.getElementById('versionHistory');
const isShowing = overlay.style.display === 'block';
overlay.style.display = isShowing ? 'none' : 'block';
box.style.display = isShowing ? 'none' : 'block';
}
let globalAirports = null;
let globalObstacles = null;
let globalMeta = null;
let globalTerrain = null;
let updateTimeout = null;
let currentCalc = null; // Stores calculation state for the map preview
document.addEventListener('DOMContentLoaded', async () => {
// Fetch Metadata for cycle dates
try {
const metaRes = await fetch('data/metadata.json?nocache=' + new Date().getTime());
globalMeta = await metaRes.json();
} catch (e) { console.warn("metadata.json not found."); }
// Load Databases
fetch('data/airports.json?nocache=' + new Date().getTime()).then(r => r.json()).then(data => {
globalAirports = data;
let datePart = (globalMeta && globalMeta.apt_date) ? globalMeta.apt_date : "Unknown";
document.getElementById('apt-status').innerText = "Verified (Eff. " + datePart + " | " + Object.keys(data).length + " airports/heliports found)";
document.getElementById('apt-dot').className = 'status-dot ready';
});
fetch('data/obstacles.json?nocache=' + new Date().getTime()).then(r => r.json()).then(data => {
globalObstacles = data;
let datePart = (globalMeta && globalMeta.dof_date) ? globalMeta.dof_date : "Unknown";
document.getElementById('obs-status').innerText = "Verified (Eff. " + datePart + " | " + data.length + " obstacles)";
document.getElementById('obs-dot').className = 'status-dot ready';
});
// Load USGS Terrain Grid
fetch('data/terrain.json')
.then(r => { if (!r.ok) throw new Error("HTTP " + r.status); return r.json(); })
.then(data => {
globalTerrain = data;
document.getElementById('usgs-status').innerText = "Verified (Offline Copernicus 30m Grid)";
document.getElementById('usgs-status').style.color = "var(--text)";
document.getElementById('usgs-dot').className = 'status-dot ready';
triggerLiveUpdate();
})
.catch(e => {
document.getElementById('usgs-status').innerText = "Error: terrain.json missing";
document.getElementById('usgs-status').style.color = "var(--danger)";
console.error("Terrain grid fetch failed:", e);
});
// Initialize offline World Magnetic Model
import('https://esm.sh/magvar')
.then(module => {
window.wmmModule = module; // Cache globally for instant access
document.getElementById('mag-status').innerText = "Verified (WMM 2025-2030 Epoch)";
document.getElementById('mag-status').style.color = "var(--text)";
document.getElementById('mag-dot').className = 'status-dot ready';
})
.catch(e => {
document.getElementById('mag-status').innerText = "Error: WMM import failed";
document.getElementById('mag-status').style.color = "var(--danger)";
console.error("MagVar module fetch failed:", e);
});
}); // <--- Add this closing parenthesis and semicolon here
function toggleCenterInput() {
const mode = document.querySelector('input[name="centerMode"]:checked').value;
document.getElementById('faaWrap').style.display = (mode === 'faa') ? 'block' : 'none';
document.getElementById('coordWrap').style.display = (mode === 'coord') ? 'block' : 'none';
triggerLiveUpdate();
}
function triggerLiveUpdate() {
updateFacilityName();
clearTimeout(updateTimeout);
updateTimeout = setTimeout(() => {
updateWheel(); // Forces the center badge to grab the newest text
calculateIIMC(); // Runs the math and draws the new halos
}, 700);
}
function handleLocationChange() {
// If Custom Sectors are ON, forcefully turn them OFF and wipe the slate clean for safety
const toggleBtn = document.getElementById('ui-sector-toggle');
if (toggleBtn && toggleBtn.checked) {
toggleBtn.checked = false;
syncSectors(toggleBtn);
wheelSectors = [0];
window.currentSectors = [];
draggingHandle = null;
}
// Proceed with the normal live update
triggerLiveUpdate();
}
// RESTORED AND UPGRADED FUNCTION
function toggleSectorUI() {
// Read from the hidden baseline radios synced to the EFB toggle switch
const customToggle = document.getElementById('sm-custom');
if (!customToggle) return; // Safety check
const mode = customToggle.checked ? 'custom' : 'single';
// Dynamically unhide the compact Add/Remove button wrapper
const btnWrapper = document.getElementById('sector-btn-wrapper');
if (btnWrapper) btnWrapper.style.display = mode === 'custom' ? 'flex' : 'none';
// Toggle the helper text
const helperText = document.getElementById('sector-helper-text');
if (helperText) helperText.style.display = mode === 'custom' ? 'block' : 'none';
// Snap the visual wheel to match the math state
if (mode === 'custom') {
if (wheelSectors.length <= 1) wheelSectors = [0, 90, 180, 270];
} else {
wheelSectors = [0]; // Collapse to a single 360° ring without drag handles
}
updateWheel();
// Rely on the proven 700ms sequence to ensure the SVG canvas is fully painted before drawing text
triggerLiveUpdate();
}
function parseCoordinate(str) {
str = str.trim().toUpperCase();
if(!str) return NaN;
// Explicitly check for South, West, or a leading negative sign
let mult = (str.includes('S') || str.includes('W') || str.startsWith('-')) ? -1 : 1;
// Strip N, S, E, W, and the minus sign so we are left with pure numbers and decimals
str = str.replace(/[NSWE\-]/g, '').trim();
// Split on anything that is NOT a digit or a decimal point (like spaces or degree symbols)
let parts = str.split(/[^\d\.]+/).filter(p => p);
if(parts.length === 1) return parseFloat(parts[0]) * mult;
if(parts.length === 2) return (parseFloat(parts[0]) + parseFloat(parts[1])/60) * mult;
if(parts.length >= 3) return (parseFloat(parts[0]) + parseFloat(parts[1])/60 + parseFloat(parts[2])/3600) * mult;
return NaN;
}
function updateFacilityName() {
if(!globalAirports) return;
const mode = document.querySelector('input[name="centerMode"]:checked').value;
if (mode === 'faa') {
let id = document.getElementById('centerpoint').value.toUpperCase().trim();
let center = globalAirports[id] || ((id.length === 4 && id.startsWith('K')) ? globalAirports[id.substring(1)] : undefined);
const nameDiv = document.getElementById('facilityName');
if (center) {
nameDiv.innerText = "Facility: " + center.name;
nameDiv.style.color = "var(--success)";
} else {
nameDiv.innerText = id.length > 0 ? "ID NOT FOUND" : "";
nameDiv.style.color = "var(--danger)";
}
} else {
let clat = parseCoordinate(document.getElementById('latInput').value);
let clon = parseCoordinate(document.getElementById('lonInput').value);
const helperDiv = document.getElementById('coordHelper');
if (isNaN(clat) || isNaN(clon)) {
helperDiv.innerText = "Accepts decimal or DMS";
helperDiv.style.color = "var(--link)";
} else if (clat < -90 || clat > 90 || clon < -180 || clon > 180) {
helperDiv.innerText = "OUT OF BOUNDS: Lat [-90, 90], Lon [-180, 180]";
helperDiv.style.color = "var(--danger)";
} else {
helperDiv.innerText = `Valid coords: ${clat.toFixed(4)}, ${clon.toFixed(4)}`;
helperDiv.style.color = "var(--success)";
}
}
}
function haversineNM(lat1, lon1, lat2, lon2) {
const R = 3440.065;
const dLat = (lat2 - lat1) * Math.PI / 180;
const dLon = (lon2 - lon1) * Math.PI / 180;
const a = Math.pow(Math.sin(dLat/2), 2) + Math.cos(lat1*Math.PI/180)*Math.cos(lat2*Math.PI/180)*Math.pow(Math.sin(dLon/2), 2);
return 2 * R * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
}
// NEW: Math helpers for Sector calculations
function calculateBearing(lat1, lon1, lat2, lon2) {
const l1 = lat1 * Math.PI / 180;
const l2 = lat2 * Math.PI / 180;
const dLon = (lon2 - lon1) * Math.PI / 180;
const y = Math.sin(dLon) * Math.cos(l2);
const x = Math.cos(l1) * Math.sin(l2) - Math.sin(l1) * Math.cos(l2) * Math.cos(dLon);
return (Math.atan2(y, x) * 180 / Math.PI + 360) % 360;
}
function isBearingInSector(bearing, startDeg, endDeg) {
if (startDeg === 0 && endDeg === 360) return true; // Single Radius mode
if (startDeg < endDeg) return bearing >= startDeg && bearing < endDeg;
return bearing >= startDeg || bearing < endDeg; // Handles slices crossing North (360/0)
}
// NEW: Multi-Sector capable terrain scanner
async function getPeakTerrain(lat, lon, radiusNM, sectors) {
// Default to a single 360-degree sector if none are provided
if (!sectors) sectors = [{ id: 'single', start: 0, end: 360 }];
if (!globalTerrain) return sectors.map(s => ({ msl: 0, lat, lon, sectorId: s.id }));
// Calculate grid search boundaries accounting for spherical Earth convergence
const latOffset = radiusNM / 60.0;
const lonOffset = (radiusNM / 60.0) / Math.abs(Math.cos(lat * (Math.PI / 180)));
const minLat = lat - latOffset;
const maxLat = lat + latOffset;
const minLon = lon - lonOffset;
const maxLon = lon + lonOffset;
// Initialize an array of peak records, one for each requested sector
let peaks = sectors.map(s => ({ msl: 0, lat: lat, lon: lon, sectorId: s.id, start: s.start, end: s.end }));
// Convert bounds to integers (x10) to prevent floating point drift and skipped edges
const startLatInt = Math.floor(minLat * 10);
const endLatInt = Math.ceil(maxLat * 10);
const startLonInt = Math.floor(minLon * 10);
const endLonInt = Math.ceil(maxLon * 10);
// Iterate through the grid sectors that fall within the bounding box
for (let latInt = startLatInt; latInt <= endLatInt; latInt++) {
for (let lonInt = startLonInt; lonInt <= endLonInt; lonInt++) {
const currentLat = latInt / 10;
let currentLon = lonInt / 10;
// NEW: Antimeridian Wrapping (Aleutian Islands / Dateline Fix)
if (currentLon > 180) currentLon -= 360;
if (currentLon < -180) currentLon += 360;
// Format the key to match our terrain.json dictionary (e.g., "39.2_-106.3")
const key = `${currentLat.toFixed(1)}_${currentLon.toFixed(1)}`;
const sectorElev = globalTerrain[key];
if (sectorElev) {
// Handle both old integer format and new exact-coordinate array format
const isArray = Array.isArray(sectorElev);
const elev = isArray ? sectorElev[0] : sectorElev;
const peakLat = isArray ? sectorElev[1] : currentLat;
const peakLon = isArray ? sectorElev[2] : currentLon;
// Double check if this specific peak is actually within the circular radius
const dist = haversineNM(lat, lon, peakLat, peakLon);
const buffer = isArray ? 0 : 4; // Keep 4NM buffer only for old generic grid points
if (dist <= radiusNM + buffer) {
const brg = calculateBearing(lat, lon, peakLat, peakLon);
// Compete for the highest elevation in whichever sector(s) this grid point falls into
sectors.forEach((s, idx) => {
if (isBearingInSector(brg, s.start, s.end)) {
if (elev > peaks[idx].msl) {
peaks[idx].msl = elev;
peaks[idx].lat = peakLat;
peaks[idx].lon = peakLon;
}
}
});
}
}
}
}
return peaks;
}
// NEW: Calculate Magnetic Declination using offline Client-Side WMM (2025-2030 Epoch)
async function getMagVar(lat, lon) {
try {
// Use the globally cached module to ensure instant offline math
const module = window.wmmModule || await import('https://esm.sh/magvar');
const dec = module.magvar(lat, lon);
return parseFloat(dec);
} catch (e) {
console.warn("Offline WMM calculation failed, defaulting to 0° (True North).", e);
return 0;
}
}
async function calculateIIMC() {
if(!globalAirports || !globalObstacles) return;
const mode = document.querySelector('input[name="centerMode"]:checked').value;
const sectorMode = document.querySelector('input[name="sectorMode"]');
const isCustomSectors = sectorMode ? document.querySelector('input[name="sectorMode"]:checked').value === 'custom' : false;
// RED CELL FIX 1: Radius RAM Exhaustion Check
let radius = parseFloat(document.getElementById('radius').value);
if(isNaN(radius) || radius < 1) radius = 1;
if(radius > 150) radius = 150; // Hard cap to prevent browser memory crashes
// Update the UI if we auto-clamped the value
if (document.getElementById('radius').value != radius) document.getElementById('radius').value = radius;
let centerTarget = null;
let isInvalid = false;
if (mode === 'faa') {
let id = document.getElementById('centerpoint').value.toUpperCase().trim();
if (id.length > 0) {
centerTarget = globalAirports[id] || ((id.length === 4 && id.startsWith('K')) ? globalAirports[id.substring(1)] : undefined);
if(!centerTarget) isInvalid = true;
} else {
return; // Empty input, wait for user to type
}
} else {
let clat = parseCoordinate(document.getElementById('latInput').value);
let clon = parseCoordinate(document.getElementById('lonInput').value);
if (isNaN(clat) || isNaN(clon) || clat < -90 || clat > 90 || clon < -180 || clon > 180) {
isInvalid = true;
} else {
centerTarget = { lat: clat, lon: clon, primary_freq: "None", center_freq: "None", name: "Custom Coordinates", center_id: "" };
}
}
// RED CELL FIX 2: The "Ghost Card" Prevention
if (isInvalid) {
document.getElementById('audit-container').innerHTML = '<div class="audit-sector-card"><div class="audit-text" style="color: var(--danger); font-weight: bold;">ERROR: Invalid Location Parameters. Fix inputs to calculate MSA.</div></div>';
document.getElementById('sectorUI').style.display = 'none'; // Hide wheel when empty/invalid
currentCalc = null; // Lock out the Map Preview & PDF Print to prevent stale data usage
return;
}
// Show the wheel container once we have a valid location
document.getElementById('sectorUI').style.display = 'block';