-
Notifications
You must be signed in to change notification settings - Fork 1
/
nav.html
1625 lines (1548 loc) · 60.6 KB
/
nav.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 PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>
Nav display test 9
</title><!--
,MMN, ...................................................................................
,MMM, CROSSFEED CLIENT MAPPING TESTSUITE: FULL SCREEN MAP
JMMN,
.gg, MMMM, These files are written for testing and develop
.MMN .....jMMMMa....... the crossfeed client (written by Geoff McLane) of FlightGear
.TMMMMMMMMMMMMMMMMMMMMMMM@ Multiplayer Server (written by Oliver Schroeder).
.MMF `?WMMMM"7??!` See http://www.fgx.ch for more information.
?""` dMMM' (c) 2013 Geoff R. McLane, Paris
.MMM' Licence: GPLv2 or later
.MMM' http://www.gnu.org/licenses/gpl.txt
.MMM' ............................................
Please do not remove this copyright and license information from this source in any case.
For OpenLayers (FreeBSD license) and jQuery (MIT license) please follow these links:
http://openlayers.org, http://jquery.org
........................................................................................
20131123 - v0.0.9 - Change to loading ALL icao.json together
20131122 - v0.0.8 - Do not like using label.js for tooltips so cancelled that, and anyway it had seemed
to stop working! see add_hover_tooltip
20131111 - Found a tooltip that works, class in js/label.js
20131106 - Version 0.0.1 - Initial cut.
<script src="js/OpenLayers.js"
type="text/javascript">
</script>
-->
<script src="js/OpenLayers-2.14-dev.js"
type="text/javascript">
</script>
<script src="js/OpenStreetMap.js"
type="text/javascript">
</script>
<script src='js/three.min.js'
type="text/javascript">
</script>
<script src="js/jquery-2.0.3.js"
type="text/javascript">
</script>
<script src="js/geodesic.js"
type="text/javascript">
</script>
<script src="js/label.js"
type="text/javascript">
</script>
<style type="text/css">
html, body, #map {
margin: 0;
width: 100%;
height: 100%;
}
#status_line {
position: absolute;
font-size: 12px;
bottom: 1em;
left: 10em;
width: 800px;
z-index: 1000;
vertical-align: middle;
border: 1px solid #000000;
background-color: white;
}
.nob {
border: 0;
padding: 0;
}
.olMarkerLabel {
font-size: small;
color: black;
background-color: #FFFFCC;
width: 150px;
padding: 1px;
border: 1px black solid;
z-index: 1000;
}
</style>
<script type="text/javascript">
// CONSTANTS
var NM2KM = 1.852;
var startTime = new Date();
var FGx = FGx || {};
// Start position for the map (hardcoded here for simplicity,
// but maybe get this from the URL params)
// IN this case Orly (LFPO)
//var def_lat = 48.72698;
//var def_lon = 2.370448;
//var def_zoom = 12;
// "icao":"YGIL","name":"Gilgandra","lat":-31.696845765,"lon":148.63677076,
//var def_lat = -31.696845765;
//var def_lon = 148.63677076;
//var def_zoom = 10;
// 3451 YSSY Sydney Intl (-33.949273,151.181346833333) tile=e150s30
//var def_lat = -33.949273;
//var def_lon = 151.18134683;
//var def_zoom = 12;
// 300 KDFW Dallas Fort Worth Intl (32.8971108914286,-97.0365474157143) tile=w090n30
//var def_lat = 32.8971108914286;
//var def_lon = -97.0365474157143;
//var def_zoom = 12;
// 413 AL77 [H] Montgomery Regional Medical Center (32.37513805,-86.29719112) tile=w080n30
// 3,32.22227778,-086.31972222,270,11210,130,3.0,MGM,,,"MONTGOMERY VORTAC"
//var def_lat = 32.22227778;
//var def_lon = -086.31972222;
//var def_zoom = 12;
// example with 4 helipads
// 1336 HAUP [H] Heliport d Aubagne - Agora (43.286578,5.604074) tile=e000n40
// http://pro2home.dnsdynamic.com/map-test/nav.html?zoom=11&lat=43.28807&lon=5.59683&layers=BTTTT
//var def_lat = 43.28807;
//var def_lon = 5.59683;
//var def_zoom = 11;
// 0 KSFO San Francisco Intl (37.61867421125,-122.37500760875)
var def_lat = 37.59746; // 37.61867421125;
var def_lon = -122.31939; // -122.37500760875;
var def_zoom = 12;
var def_hdg = 297.9;
var def_spd = 320; //160;
var def_dist = 15; // km
var def_to = 500;
var def_cs = 'GHOST';
var curr_lat = 37.59746; // 37.61867421125;
var curr_lon = -122.31939; // -122.37500760875;
var curr_hdg = 297.9;
var curr_spd = 320; // 160;
var curr_dist = 15;
var timeout = 500; //1000; // ms to next event
var curr_cs = 'GHOST';
var planeTime;
var intervalID = 0;
var add_marker = false;
var max_ils_rng = 15; // was 10, but...
var add_hover_tooltip = false;
var show_waiting = false;
var circle_style = {
strokeColor: '#0000ff',
strokeOpacity: 0.5,
strokeWidth: 2,
fill: false
};
var vor_style = {
strokeColor: '#ff0000',
strokeOpacity: 0.5,
strokeWidth: 2,
fill: false
};
var ndb_style = {
strokeColor: '#a0000ff',
strokeOpacity: 0.2,
strokeWidth: 1,
fill: true
};
var nav_style = {
strokeColor: '#000000',
strokeOpacity: 0.8,
strokeWidth: 2,
fill: false
};
var red_style = {
strokeColor: '#ff0000',
strokeOpacity: 0.5,
strokeWidth: 2,
fill: false
};
// Heliport
var green_style = {
strokeColor: '#004000',
strokeOpacity: 0.5,
strokeWidth: 2,
fill: false
};
var blue_style = {
strokeColor: '#0000ff',
strokeOpacity: 0.5,
strokeWidth: 2,
fill: false
};
var ils_style = {
strokeColor: '#ff0000',
strokeOpacity: 0.5,
strokeWidth: 1
};
var map; //complex object of type OpenLayers.Map
var markerLayer, vectorLayer, fromProjection, toProjection;
var mapnik, position, airportLabel;
var vor_icon, ndb_icon, air_icon, plane;
var navLength = 0; // total navaids loaded
var airportLength = 0; // total airports loaded
var airFound = []; // airports found within current screen bounds
var airPainted = []; // index of aiports painted
var navFound = []; // index of navaids found within current screen bounds
var navPainted = []; // index of navaids painted
var add_helipads = 1; // load HELIPADS
var helipadLength = 0;
var heliFound = []; // helipads found within current screen blunds
var heliPainted = [];
var ilsPainted = []; // array of ICAO of ILS painted
var curr_lat1, curr_lon1, curr_lat2, curr_lon2;
var curr_zoom = 0;
var curr_width, curr_height;
// ICAO json loading
// ============================================================
var jsonLoaded = {};
// new idea
var icaoDone = [];
var icaoRequests = 0;
// ==============================================================
var lineLayer;
var permControl;
var line_style = {
strokeColor: '#ff0000',
strokeOpacity: 0.5,
strokeWidth: 1
};
var doneAir = false;
var doneHeli = false;
var doneNavs = false;
var circuit;
var curr_leg = 0;
function valInArray(s,a ) {
var i, t;
var max = a.length;
for (i = 0; i < max; i++) {
t = a[i];
if ( s == t )
return true;
}
return false;
}
// generate a simple rectangular circuit, kept as a set of LatLon points
// in the curcuit array
function calculateCircuit() {
circuit = new Array();
var nhdg = curr_hdg;
// first leg is from curr_lat,curr_lon, on curr_hdg, for curr_dist
circuit[0] = new LatLon(curr_lat,curr_lon);
var p = getDirect( curr_lat, curr_lon, nhdg, curr_dist );
circuit[1] = new LatLon(p._lat,p._lon);
// second leg is from the new position, turn right 90 degrees for 0.5 curr_dist
nhdg += 90;
if (nhdg >= 360)
nhdg -= 360;
var p2 = getDirect( p._lat, p._lon, nhdg, curr_dist / 2);
circuit[2] = new LatLon(p2._lat,p2._lon);
// third leg, turn right 90 degrees, for curr_dist
nhdg += 90;
if (nhdg >= 360)
nhdg -= 360;
var p3 = getDirect( p2._lat, p2._lon, nhdg, curr_dist );
circuit[3] = new LatLon(p3._lat,p3._lon);
// last leg is back to original position
}
function init(cs,lat,lon,zoom,hdg,spd,dist,to) {
// fix lat, lon, zoom
if (cs.length == 0)
cs = def_cs;
if (lat.length)
lat = parseFloat(lat);
else
lat = def_lat;
if (lon.length)
lon = parseFloat(lon);
else
lon = def_lon;
if (zoom.length)
zoom = parseFloat(zoom)
else
zoom = def_zoom;
if (hdg.length)
hdg = parseFloat(hdg);
else
hdg = def_hdg;
if (spd.length)
spd = parseFloat(spd);
else
spd = def_spd;
if (dist.length)
dist = parseFloat(dist);
else
dist = def_dist;
if (to.length)
to = parseFloat(to);
else
to = def_to;
// get the map
map = new OpenLayers.Map("map", {
projection: new OpenLayers.Projection("EPSG:3857"),
// this sets wgs84/4326 as default for display coords
displayProjection: new OpenLayers.Projection("EPSG:4326") }
);
mapnik = new OpenLayers.Layer.OSM();
fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
position = new OpenLayers.LonLat(lon,lat).transform( fromProjection, toProjection);
var labelStyle = new OpenLayers.Style({
//externalGraphic: "images/label_background.gif",
externalGraphic: "images/background_trans.png",
graphicWidth: "${labelWidth}",
graphicHeight: "13",
graphicOpacity: 0.99,
graphicXOffset: "${labelOffset}",
graphicYOffset: 14,
fillColor: "#000000",
fillOpacity: 0.0,
strokeWidth: 0.0,
label : "${icao}",
//fontColor: "#CCCCCC",
fontColor: "#000000",
fontSize: "11px",
fontFamily: "\"DejaVuSansMonoBold\",monospace",
//fontWeight: "normal",
fontWeight: "bold",
labelAlign: "center",
labelXOffset: "0",
labelYOffset: "-22" });
airportLabel = new OpenLayers.Layer.Vector("Airport", {styleMap: labelStyle});
map.addLayers([mapnik,airportLabel]);
permControl = new OpenLayers.Control.Permalink('permalink');
map.addControl(permControl);
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.ScaleLine());
map.addControl(new OpenLayers.Control.LayerSwitcher());
markerLayer = new OpenLayers.Layer.Markers( "Markers" );
// markerLayer.setOpacity(0.5); // guestimate only
map.addLayer(markerLayer);
// for circle drawing
vectorLayer = new OpenLayers.Layer.Vector("Overlay");
map.addLayer(vectorLayer);
lineLayer = new OpenLayers.Layer.Vector("Line Layer");
map.addLayer(lineLayer);
// VOR-95x83.png
var vor_size = new OpenLayers.Size(95,83);
var vor_off = new OpenLayers.Pixel(-(vor_size.w/2), -vor_size.h);
vor_icon = new OpenLayers.Icon('img/VOR-95x83.png',vor_size,vor_off);
// NDB-95x95.png
var ndb_size = new OpenLayers.Size(95,95);
var ndb_off = new OpenLayers.Pixel(-(ndb_size.w/2), -ndb_size.h);
ndb_icon = new OpenLayers.Icon('img/NDB-95x95.png',ndb_size,ndb_off);
var air_size = new OpenLayers.Size(40,40);
var air_off = new OpenLayers.Pixel(-(air_size.w/2), -air_size.h/2);
air_icon = new OpenLayers.Icon('textures/fg_generic_craft.png',air_size,air_off);
if (add_marker) {
markerLayer.addMarker(new OpenLayers.Marker(position));
} else {
var radius = 1000; // TODO: what SIZE should the circle be? probably should DEPEND on zoom???
// distance to vertex, in map units
var sides = 30; // docs say '20 approximates a circle'... so ...
var point = new OpenLayers.Geometry.Point(position.lon, position.lat);
var circle = OpenLayers.Geometry.Polygon.createRegularPolygon(
point,
radius,
sides,
0 );
var featurecircle = new OpenLayers.Feature.Vector(circle, null, circle_style);
vectorLayer.addFeatures([featurecircle]);
plane = new OpenLayers.Marker(position, air_icon);
// from : http://coherent-labs.com/cryengine-3-minimap-made-with-coherent-ui/
plane.icon.imageDiv.style.webkitTransform = "rotate(" + hdg + "deg)";
markerLayer.addMarker(plane);
}
map.setCenter(position, zoom );
// establish current values
curr_lat = lat; // 37.61867421125;
curr_lon = lon; // -122.37500760875;
curr_hdg = hdg;
curr_spd = spd;
curr_dist = dist;
timeout = to;
curr_cs = cs;
calculateCircuit(); // calculate a circuit for the plane
// maybe after the first centering and zooming all done
// map.events.register(type, obj, listener);
map.events.register('zoomend', undefined, zoomChanged);
map.events.register('moveend', undefined, moveEnded);
// map.events.register('dragend', undefined, dragEnded); // this did nothing???
// in fact, seems from : http://dev.openlayers.org/releases/OpenLayers-2.11/doc/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.EVENT_TYPES
// there is no dragend event supported, and says 'moveend triggered after a drag, pan, or zoom completes'
}
function rotateFeature(feature, angle, origin) {
feature.geometry.rotate(angle, origin);
feature.layer.drawFeature(feature);
}
/**
* Object.size = function(obj)
* @param (object) Object to get the size of
* @return (int) Length of the object
*/
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
function getLatLonExt() {
var ext = map.getExtent();
//var stg = ext.toBBOX();
var left = ext.left;
var top = ext.top;
var right = ext.right;
var bott = ext.bottom;
var tl = new OpenLayers.LonLat(left,top).transform( toProjection, fromProjection );
var br = new OpenLayers.LonLat(right,bott).transform( toProjection, fromProjection );
var lat1 = tl.lat;
var lon1 = tl.lon;
var lat2 = br.lat;
var lon2 = br.lon;
// expand this to a minimum of 0.1 degrees span - WHY? not sure!
var av;
if ((lat1 - lat2) < 0.1) {
av = (lat1 + lat2) / 2;
lat1 = av + 0.05;
lat2 = av - 0.05;
}
if ((lon2 - lon1) < 0.1) {
av = ( lon1 + lon2 ) / 2;
lon1 = av - 0.05;
lon2 = av + 0.05;
}
var lle = {};
lle.tllat = lat1;
lle.tllon = lon1;
lle.brlat = lat2;
lle.brlon = lon2;
var mlat = (lat1 + lat2) / 2;
var mlon = (lon1 + lon2) / 2;
lle.width = getDistance( mlat, lon1, mlat, lon2 );
lle.height = getDistance( lat1, mlon, lat2, mlon );
return lle;
}
function searchNavAids2( lat1, lon1, lat2, lon2 ) {
var max = FGx.navaids.length;
var i, nav, nlat, nlon, id, cnt;
var navs = [];
for (i = 1; i < max; i++) {
nav = FGx.navaids[i];
nlat = parseFloat(nav[1]);
nlon = parseFloat(nav[2]);
if ((nlat <= lat1)&&(nlat >= lat2)&&
(nlon >= lon1)&&(nlon <= lon2)) {
// found.push(nav); // why the whole record
navs.push(i); // just need an index
}
}
return navs; // return array of indexex found
}
function searchAirports2( lat1, lon1, lat2, lon2 ) {
var max = FGx.airports.length;
var i, air, nlat, nlon, id, cnt;
var airs= [];
for (i = 1; i < max; i++) {
air = FGx.airports[i];
nlat = parseFloat(air[2]);
nlon = parseFloat(air[3]);
if ((nlat <= lat1)&&(nlat >= lat2)&&
(nlon >= lon1)&&(nlon <= lon2)) {
// found.push(nav); // why the whole record
airs.push(i); // just need an index
}
}
return airs; // return the found
}
function compArrays( arrA, arrB ) {
// check if lengths are different
if ( arrA.length !== arrB.length ) return false;
// slice so we do not effect the original
// sort makes sure they are in order
// join makes it a string so we can do a string compare
var cA = arrA.slice().sort().join(",");
var cB = arrB.slice().sort().join(",");
return cA === cB;
}
function processChange(evt) {
setGLobalBounds(); // establish BOUND of current map
var newNavs = searchNavAids( curr_lat1, curr_lon1, curr_lat2, curr_lon2 );
var newAirs = searchAirports( curr_lat1, curr_lon1, curr_lat2, curr_lon2 );
var newHeli = searchHelipads( curr_lat1, curr_lon1, curr_lat2, curr_lon2 );
showStatus();
getAirJson(newAirs,newHeli,newNavs);
}
function zoomChanged() {
processChange(1);
}
// sometime can have 2 or more of these...
function moveEnded() {
processChange(2);
}
// These events can 'sometimes' be seen at startup also
// And 'sometimes' they come as a pair?!?
function zoomChanged_test() {
var zoom = map.getZoom();
// alert("Zoom changed to "+zoom);
// TODO: Need to redraw the features according to this NEW zoom level
var lle = getLatLonExt();
var navs = searchNavAids2( lle.tllat, lle.tllon, lle.brlat, lle.brlon );
var airs = searchAirports2( lle.tllat, lle.tllon, lle.brlat, lle.brlon );
// is there any significant change
var compn = compArrays( navs, navFound );
var compa = compArrays( airs, airFound );
var msg = 'DIFFERENT';
var adddbg = false;
if (compn && compa) {
msg = 'SAME';
console.log("zoomChanged: "+zoom+" TL="+lle.tllat+","+lle.tllon+" BR="+lle.brlat+","+lle.brlon+" ~ w="+lle.width+" h="+lle.height+" km. "+msg);
} else {
console.log("zoomChanged: "+zoom+" TL="+lle.tllat+","+lle.tllon+" BR="+lle.brlat+","+lle.brlon+" ~ w="+lle.width+" h="+lle.height+" km."+msg);
if (adddbg) {
if (!compn) {
msg = "Nav1: "+navs.slice().sort().join(',');
console.log(msg);
msg = "Nav2: "+navFound.slice().sort().join(',');
console.log(msg);
}
if (!compa) {
msg = "Air1: "+airs.slice().sort().join(',');
console.log(msg);
msg = "Air2: "+airFound.slice().sort().join(',');
console.log(msg);
}
}
}
}
// sometime can have 2 or more of these...
function moveEnded_test() {
// TODO: Need to redraw the features according to this NEW zoom level
var zoom = map.getZoom();
var lle = getLatLonExt();
var navs = searchNavAids2( lle.tllat, lle.tllon, lle.brlat, lle.brlon );
var airs = searchAirports2( lle.tllat, lle.tllon, lle.brlat, lle.brlon );
var compn = compArrays( navs, navFound );
var compa = compArrays( airs, airFound );
var msg = 'DIFFERENT';
var adddbg = false;
if (compn && compa) {
msg = 'SAME';
console.log("moveEnded: "+zoom+" TL="+lle.tllat+","+lle.tllon+" BR="+lle.brlat+","+lle.brlon+" ~ w="+lle.width+" h="+lle.height+" km. "+msg);
} else {
console.log("moveEnded: "+zoom+" TL="+lle.tllat+","+lle.tllon+" BR="+lle.brlat+","+lle.brlon+" ~ w="+lle.width+" h="+lle.height+" km."+msg);
if (adddbg) {
if (!compn) {
msg = "Nav1: "+navs.slice().sort().join(',');
console.log(msg);
msg = "Nav2: "+navFound.slice().sort().join(',');
console.log(msg);
}
if (!compa) {
msg = "Air1: "+airs.slice().sort().join(',');
console.log(msg);
msg = "Air2: "+airFound.slice().sort().join(',');
console.log(msg);
}
}
}
}
// NEVER SEEN - removed register above
//function dragEnded() {
// // TODO: Need to redraw the features according to this NEW zoom level
// var zoom = map.getZoom();
// var lle = getLatLonExt();
// console.log("dragEnded: "+zoom+" TL="+lle.tllat+","+lle.tllon+" BR="+lle.brlat+","+lle.brlon+" ~ w="+lle.width+" h="+lle.height+" km.");
//}
/**
* function addLabel(icao, lon, lat);
* @param (string) ICAO to paint
* @param (number) Degree of longitude
* @param (number) Degree of latitude
* Add a label for an airport contianing ICAO
*/
function addLabel(icao, lon, lat) {
var point = new OpenLayers.Geometry.Point(lon,lat).transform( fromProjection, toProjection);
var labelFeature = new OpenLayers.Feature.Vector(point);
labelFeature.id = "label"+icao;
labelFeature.attributes.icao = icao;
// This calculates label background width and offset
labelWidth = 8 * icao.length;
labelOffset = labelWidth / 2 * -1.0;
labelFeature.attributes.labelWidth = labelWidth;
labelFeature.attributes.labelOffset = labelOffset;
airportLabel.addFeatures(labelFeature);
}
/**
* function requestFile( fname, callback );
* @param (string) File name to load
* @param (function) Callback funtion on state change
* ========== load data files ========
*/
function requestFile( fname, callback ) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open( 'GET', fname, true );
xmlhttp.onreadystatechange = callback;
xmlhttp.send( null );
}
/**
* function searchNavAids( lat1, lon1, lat2, lon2, type );
* @param (Float) Degrees of hightest (N) latitude
* @param (Float) Degrees of least (W) longitude
* @param (Float) Degrees of lowest (S) latitude
* @param (Float) Degrees of most (E) longitude
*/
function searchNavAids( lat1, lon1, lat2, lon2 ) {
var max = FGx.navaids.length;
var i, nav, nlat, nlon, id, cnt;
newFound = [];
for (i = 1; i < max; i++) {
nav = FGx.navaids[i];
nlat = parseFloat(nav[1]);
nlon = parseFloat(nav[2]);
if ((nlat <= lat1)&&(nlat >= lat2)&&
(nlon >= lon1)&&(nlon <= lon2)) {
// found.push(nav); // why the whole record
if (!valInArray(i,navFound)) {
navFound.push(i); // just need an index
newFound.push(i);
}
}
}
return newFound; // return the found
}
/**
* function searchAirports( lat1, lon1, lat2, lon2 );
* Top Left corner
* @param (number) Maximum latitude
* @param (number) Minimum longitude
* Bottom Right corner
* @param (number) Minimum latitude
* @param (number) Maximum longitude
* @return (array) Array of indexes of airports within bounding box
* search airports from a -icao.CSV file
* 0 1 2 3 4 5
* icao,"name", lat, lon, runways,ils
* 00C,"Animas Air Park",37.203178,-107.8691945,1, 0
*/
function searchAirports( lat1, lon1, lat2, lon2 ) {
var max = FGx.airports.length;
var i, air, nlat, nlon, id, cnt;
var newFound = [];
for (i = 1; i < max; i++) {
air = FGx.airports[i];
nlat = parseFloat(air[2]);
nlon = parseFloat(air[3]);
if ((nlat <= lat1)&&(nlat >= lat2)&&
(nlon >= lon1)&&(nlon <= lon2)) {
// found.push(nav); // why the whole record
if (!valInArray(i,airFound)) {
airFound.push(i); // just need an index
newFound.push(i);
}
}
}
return newFound; // return the NEW found
}
/**
* function searchHelipads( lat1, lon1, lat2, lon2 );
* Top Left corner
* @param (number) Maximum latitude
* @param (number) Minimum longitude
* Bottom Right corner
* @param (number) Minimum latitude
* @param (number) Maximum longitude
* @return (array) Array of indexes of airports within bounding box
* search airports from a -heli.CSV file
* 0 1 2 3 4 5
* icao,"name", lat, lon, runways,ils
* 00E, "[h] Apache Junction",33.49421222,-111.64124806,0, 0
*/
function searchHelipads( lat1, lon1, lat2, lon2 ) {
var max = FGx.helipads.length;
var i, air, nlat, nlon, id, cnt;
newFound = [];
for (i = 1; i < max; i++) {
air = FGx.helipads[i];
nlat = parseFloat(air[2]);
nlon = parseFloat(air[3]);
if ((nlat <= lat1)&&(nlat >= lat2)&&
(nlon >= lon1)&&(nlon <= lon2)) {
if (!valInArray(i,heliFound)) {
heliFound.push(i); // just need an index
newFound.push(i);
}
}
}
return newFound; // return the found
}
/**
* function getNavPosition(i)
* @param (integer) Index into navaids loaded
* @return (LonLat) OpenLayers LonLat of navaid
*/
function getNavPosition(i) {
var nav = FGx.navaids[i];
var nlat = parseFloat(nav[1]);
var nlon = parseFloat(nav[2]);
var pos = new OpenLayers.LonLat(nlon,nlat).transform( fromProjection, toProjection );
return pos;
}
function paintLine( lat1, lon1, lat2, lon2, style )
{
var points = new Array(
new OpenLayers.Geometry.Point(lon1,lat1).transform( fromProjection, toProjection ),
new OpenLayers.Geometry.Point(lon2,lat2).transform( fromProjection, toProjection )
);
var line = new OpenLayers.Geometry.LineString(points);
var lineFeature = new OpenLayers.Feature.Vector(line, null, style);
lineLayer.addFeatures([lineFeature]);
}
function paintVORRose( nlat, nlon ) {
var p1, p2, hdg, dist1, dist2;
dist1 = 3.25;
dist2 = 0.4;
for (hdg = 0; hdg < 360; hdg += 10) {
if ((hdg == 0)||(hdg == 90)||(hdg == 180)||(hdg == 270))
dist2 = 0.4;
else
dist2 = 3.0;
p1 = getDirect( nlat, nlon, hdg, dist1 ); // outter point
p2 = getDirect( nlat, nlon, hdg, dist2 ); // inner point
paintLine( p2._lat, p2._lon, p1._lat, p1._lon, blue_style );
}
}
function paintNDBRose( nlat, nlon ) {
var p1, p2, hdg, dist1, dist2;
dist1 = 3.25;
dist2 = 0.4;
for (hdg = 0; hdg < 360; hdg += 45) {
if ((hdg == 0)||(hdg == 90)||(hdg == 180)||(hdg == 270))
dist2 = 0.4;
else
dist2 = 3.0;
p1 = getDirect( nlat, nlon, hdg, dist1 ); // outter point
p2 = getDirect( nlat, nlon, hdg, dist2 ); // inner point
paintLine( p2._lat, p2._lon, p1._lat, p1._lon, blue_style );
}
}
/**
* function paintNavaids( navs );
* @param (array) Navaids found in bounding box
* Add a display of certain types of navaids onto the map
* TODO: Lots of experimenting... ended up just adding an image in most cases
*/
function paintNavaids( navs ) {
var cnt = navs.length;
var i, j, pos, ind, typ, nav;
var icon, marker;
var point, circle, featurecircle;
var nlat, nlon;
var z = curr_zoom;
//if (z < 5) {
// return 0;
//}
var radius = 500; // TODO: what SIZE should the circle be? probably should DEPEND on zoom???
var sides = 20; // docs say '20 approximates a circle'... so ...
var style = circle_style;
var add = true;
var img = '';
var painted = 0;
var done = false;
for (i = 0; i < cnt; i++) {
ind = navs[i];
if (valInArray(ind,navPainted))
continue; // already painted
navPainted.push(ind);
nav = FGx.navaids[ind];
typ = parseInt(nav[0]);
nlat = parseFloat(nav[1]);
nlon = parseFloat(nav[2]);
pos = getNavPosition(ind);
radius = 200;
style = nav_style;
add = true;
img = '';
done = false;
if (typ == 2) {
if (z < 8)
img = 'NDB-50x50.gif';
else
img = 'NDB-95x95.gif';
//markerLayer.addMarker(new OpenLayers.Marker(pos,ndb_icon.clone));
radius = 400;
style = ndb_style;
//style = circle_style;
add = false;
} else if (typ == 3) {
// Three types of VOR, VORTAC, VOR-DME, and good old VOR - check name
//markerLayer.addMarker(new OpenLayers.Marker(pos,vor_icon.clone));
radius = 500;
style = vor_style;
if (z < 8)
img = 'VOR-50x43.gif'; // 'standard' VOR
else
img = 'VOR-95x83.gif'; // 'standard' VOR
var name = nav[10]; // get the 'name'
var fnd = name.match(/VORTAC/g);
if (fnd !== null) {
if (z < 8)
img = 'VORTAC-50x43.gif';
else
img = 'VORTAC-97x85.gif';
} else {
fnd = name.match(/DME/g);
if (fnd !== null) {
if (z < 8)
img = 'VOR-DME-50x43.gif';
else
img = 'VOR-DME-95x83.gif';
}
}
add = false;
} else if ((typ == 4)||(typ == 5)||(typ == 6)) {
// Localiser and Glideslope components of ILS (LDA, SDF)
// this will come from the ICAO.json file
add = false;
} else if ((typ == 7)||(typ == 8)||(typ == 9)) {
// OM, MM, IM markers
radius = 200;
style = nav_style;
if (z > 7) {
if (typ == 7)
img = 'OM.png';
else if (typ == 8)
img = 'MM.png';
else
img = 'IM.png';
}
add = false;
} else if (typ == 12) {
// DME of ILS
radius = 600;
style = circle_style;
add = false;
} else if (typ == 13) {
radius = 600;
style = circle_style;
add = false;
}
done = false;
if (img.length) {
icon = new OpenLayers.Icon('img/'+img);
marker = new OpenLayers.Marker(pos, icon);
markerLayer.addMarker(marker);
painted++;
done = true;
} else if (add) {
point = new OpenLayers.Geometry.Point(pos.lon, pos.lat);
circle = OpenLayers.Geometry.Polygon.createRegularPolygon(
point,
radius,
sides,
0 );
featurecircle = new OpenLayers.Feature.Vector(circle, null, style);
vectorLayer.addFeatures([featurecircle]);
painted++;
done = true;
}
if (done) {
radius = 600;
if ((typ == 2)||(typ == 3))
style = blue_style;
else
style = red_style;
point = new OpenLayers.Geometry.Point(pos.lon, pos.lat);
circle = OpenLayers.Geometry.Polygon.createRegularPolygon(
point,
radius,
sides,
0 );
featurecircle = new OpenLayers.Feature.Vector(circle, null, style);
vectorLayer.addFeatures([featurecircle]);
if ((typ == 2)||(typ == 3)) {
radius = 5000; // this should be according to the range maybe, and/or zoom
style = blue_style;
point = new OpenLayers.Geometry.Point(pos.lon, pos.lat);
circle = OpenLayers.Geometry.Polygon.createRegularPolygon(
point,
radius,
sides,
0 );
featurecircle = new OpenLayers.Feature.Vector(circle, null, style);
vectorLayer.addFeatures([featurecircle]);
//if (typ == 3) {
if (z >= 8) {
if (typ == 3)
paintVORRose( nlat, nlon );
else
paintNDBRose( nlat, nlon );
}
}
}
}
return painted;
}
function paintRunway(rwy) {
var rwy_style = {
strokeColor: '#600000',
strokeOpacity: 0.5,
strokeWidth: 4
};
var len_m, wid_m, hdg, surf, rwy1, lat1, lon1, rwy2, lat2, lon2;
var points, line, lineFeature;
len_m = rwy.len_m;
wid_m = rwy.wid_m;
hdg = rwy.hdg;
surf = rwy.surf;
rwy1 = rwy.rwy1;
lat1 = rwy.lat1;
lon1 = rwy.lon1;
rwy2 = rwy.rwy2;
lat2 = rwy.lat2;
lon2 = rwy.lon2;
points = new Array(
new OpenLayers.Geometry.Point(lon1,lat1).transform( fromProjection, toProjection ),
new OpenLayers.Geometry.Point(lon2,lat2).transform( fromProjection, toProjection )
);
line = new OpenLayers.Geometry.LineString(points);
lineFeature = new OpenLayers.Feature.Vector(line, null, rwy_style);
lineLayer.addFeatures([lineFeature]);
}
/**
* function paintAirports( airs, navs );
* @param (array) Airports found in bounding box
* @param (array) Navaids found in bounding box - NOT USED
* Add a display of an airport onto the map
* At this time the ICAO json file may not be loaded, else maybe
* add outlines of the runways, a nice circle and H for helipads
*
*/
function paintAirports( airs ) {
var max = airs.length;
var i, ind, air, cnt, alat, alon, icao, pos, point, circle, feat;
var data, rwysa, helia, rada, nava, name, j, maxj, rwy;
cnt = 0;
var z = curr_zoom;
for (i = 0; i < max; i++) {
ind = airs[i];
if (valInArray(ind,airPainted))
continue; // already painted
airPainted.push(ind);
air = FGx.airports[ind];
icao = air[0];
alat = parseFloat(air[2]);
alon = parseFloat(air[3]);
if (icao in jsonLoaded) {
data = jsonLoaded[icao];
// now have LOTS of information about the airport
name = data.name;
helia = data.helipads;
rada = data.radios;
nava = data.navaids;
// paint runways
rwysa = data.runways;