-
Notifications
You must be signed in to change notification settings - Fork 1
/
demof.html
552 lines (455 loc) · 22.1 KB
/
demof.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
<!DOCTYPE html public "-//W3C//DTD HTML 4.0 Strict//en">
<html>
<head>
<title>Crossfeed JSON Test Corner</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<script type="text/javascript" src="http://static.fgx.ch/js/jquery-1.8.3/jquery-1.8.3.min.js"></script>
<!--
,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 Yves Sablonier, Zurich
.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 this links:
http://openlayers.org, http://jquery.org
........................................................................................
-->
<link rel="stylesheet" href="./css/stylesheet.css" type="text/css">
<link rel="stylesheet" href="http://static.fgx.ch/js/OpenLayers-2.12/theme/default/style.css" type="text/css">
<script src="http://static.fgx.ch/js/OpenLayers-2.11/OpenLayers.js"></script>
<script type="text/javascript">
// disable ajax caching
$.ajaxSetup({cache: false});
// ----------------------------------------------------------------------------------------------
// Openlayers
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
// Creating the map
// ----------------------------------------------------------------------------------------------
var map;
var planeStyle = new OpenLayers.Style(
{
pointRadius: 1,
strokeWidth: 0.0,
graphicWidth: "30", graphicHeight: "30", graphicOpacity: 0.99,
rotation: "${hdg}",
labelAlign: "center",
labelXOffset: "0",
labelYOffset: "0"
}
,{
rules: [
new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.LESS_THAN,
property: "spd_kts",
value: 10
}),
symbolizer: {
externalGraphic: "images/plane_gray_30x30.png"
}
}),
new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.GREATER_THAN,
property: "spd_kts",
value: 9
}),
symbolizer: {
externalGraphic: "images/plane_red_30x30.png"
}
}),
new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.GREATER_THAN,
property: "select",
value: 0
}),
symbolizer: {
externalGraphic: "images/plane_green_30x30.png"
}
})
]}
);
var labelStyle = new OpenLayers.Style(
{
externalGraphic: "images/label_background.gif",
graphicWidth: "${labelWidth}", graphicHeight: "13", graphicOpacity: 0.99,
graphicXOffset: "${labelOffset}", graphicYOffset: 14,
fillColor: "#000000",
fillOpacity: 0.0,
strokeWidth: 0.0,
label : "${callsign}",
fontColor: "#CCCCCC", fontSize: "11px", fontFamily: "\"DejaVuSansMonoBold\",monospace", fontWeight: "normal",
labelAlign: "center",
labelXOffset: "0",
labelYOffset: "-22"
}
);
var planes = new OpenLayers.Layer.Vector("Planes", {styleMap: planeStyle});
var planesLabel = new OpenLayers.Layer.Vector("Callsign", {styleMap: labelStyle});
function init(){
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
map.addLayers([layer,planes,planesLabel]);
map.addControl(new OpenLayers.Control.Permalink('permalink'));
map.addControl(new OpenLayers.Control.MousePosition());
map.setCenter(new OpenLayers.LonLat(1.0, 50.0), 5);
if (zoom.length == 0) { zoom = 5; } // set default ZOOM
var centerpoint;
if (lon.length && lat.length) { // if URL contains lon,lat points
centerpoint = new OpenLayers.LonLat(lon,lat); // user center point
} else {
centerpoint = new OpenLayers.LonLat(1.0,50.0); // get a default center
}
map.setCenter(centerpoint,zoom);
}
// Planes and Labels are doubled, it’s not possible to set a background for
// a label in OpenLayers yet. This is a snag. Because we want rotation we can’t
// have a point graphic with label integrated.
function addPlanes(mapfid, lon, lat, hdg, spd_kts) {
var point = new OpenLayers.Geometry.Point(lon,lat)
var feature = new OpenLayers.Feature.Vector(point);
// that does the trick, the feature gets the fid
// as feature ID
feature.id = mapfid;
if (selected == mapfid) {
feature.attributes.select = 1;
}
feature.attributes.hdg = hdg;
feature.attributes.spd_kts = spd_kts;
planes.addFeatures(feature);
}
function addLabels(mapfid, callsign, lon, lat) {
var pointLabel = new OpenLayers.Geometry.Point(lon,lat)
var labelFeature = new OpenLayers.Feature.Vector(pointLabel);
labelFeature.id = "label"+mapfid;
labelFeature.attributes.callsign = callsign.toUpperCase();
// This calculates label background width and offset
labelWidth = 8*callsign.length
labelOffset = labelWidth/2*-1.0
labelFeature.attributes.labelWidth = labelWidth;
labelFeature.attributes.labelOffset = labelOffset;
planesLabel.addFeatures(labelFeature);
}
function removePlanes(fid) {
planes.removeFeatures(planes.getFeatureById(fid));
planesLabel.removeFeatures(planesLabel.getFeatureById("label"+fid));
}
function removePlaneOnly(fid) {
planes.removeFeatures(planes.getFeatureById(fid));
}
// now re-drawing of the features, just move what’s already here
function updatePlanes(mapfid, lon, lat, hdg, spd_kts) {
//planes.getFeatureById(mapfid).move(new OpenLayers.LonLat(lon,lat));
removePlaneOnly(mapfid)
addPlanes(mapfid, lon, lat, hdg, spd_kts)
planesLabel.getFeatureById("label"+mapfid).move(new OpenLayers.LonLat(lon,lat));
}
// In case we zoom to one plane we center the map
// In case it there are more than one plane selected we zoom to bounds. Hah!
function zoomToBoundsSelected(selected) {
bounds = new OpenLayers.Bounds();
if (selected.length>1) {
for (i=0;i<selected.length;i++) {
lon = planesLabel.getFeatureById("label"+selected[i]).geometry.x
lat = planesLabel.getFeatureById("label"+selected[i]).geometry.y
bounds.extend(new OpenLayers.LonLat(lon,lat))
bounds.toBBOX();
}
map.zoomToExtent(bounds);
}else{
lon = planesLabel.getFeatureById("label"+selected[0]).geometry.x
lat = planesLabel.getFeatureById("label"+selected[0]).geometry.y
map.setCenter(new OpenLayers.LonLat(lon, lat), 9);
}
}
// ----------------------------------------------------------------------------------------------
// jQuery
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
// This is needed to NOT remove the flights from the first load
// ----------------------------------------------------------------------------------------------
var firstload = 1
var isdown = 0
// ----------------------------------------------------------------------------------------------
// Init vars
// ----------------------------------------------------------------------------------------------
var datamap = [];
var removal = [];
var selected = [];
// ----------------------------------------------------------------------------------------------
// Creating the main table
// ----------------------------------------------------------------------------------------------
// Some strings to construct the table, and a nodata value just in case ...
var tableheader = "<table><tr class='table_header'><td class='fid' style='display: none;'><p>FID</p>'"+
"</td><td><p>Callsign</p></td><td class='lon' style='display: none'><p>Longitude</p></td>"+
"<td class='lat' style='display: none'><p>Latitude</p></td><td><p>Heading</p></td><td><p>Altitude"+
"</p></td><td><p>Speed</p></td></tr>"
var nodata = "<tr class='flightrow'><td class='fid'>FID<td class='callsign'><p>No data ...<td class='lon'><p>\
<td class='lat'><td class='hdg'><p><td class='alt_ft'><p><td class='speed'><p>"
$(document).ready(function() {
$(tableheader).appendTo('#header_flights')
$("<table cellspacing='0' cellpadding='0' id='flights' />")
.appendTo("#content_flights");
$('#flights').hide().show(300);
});
// ----------------------------------------------------------------------------------------------
// Adding flights
// ----------------------------------------------------------------------------------------------
function addFlight(flight) {
// Add flight to the map
var fid = flight.children('.fid').text()
var callsign = flight.children('.callsign').text()
var lon = flight.children('.lon').text()
var lat = flight.children('.lat').text()
var hdg = flight.children('.hdg').text()
var spd_kts = flight.children('.spd_kts').text()
addPlanes(fid, lon, lat, hdg, spd_kts)
addLabels(fid, callsign, lon, lat)
// Add flight to the table
//console.log(flight)
$('#flights').append(flight);
}
// ----------------------------------------------------------------------------------------------
// Removing flights
// ----------------------------------------------------------------------------------------------
function removeFlights() {
// Remove features from table
$.each(removal, function(i, val) {
$.each($('.flightrow'), function(i, row) {
if (($(row).get(0).id) == val) {
$(row).hide(1000, function(){ $(row).remove(); });
}
});
});
// Remove features from the map
$.each(removal, function(i, val) {
//console.log("Map Remove: "+val)
removePlanes(val)
});
}
// ----------------------------------------------------------------------------------------------
// Loading the JSON data
// ----------------------------------------------------------------------------------------------
// Function has a fixed timeout (5 secs)
function loadFlights() {
$(document).ready(function() {
$('.fid').hide()
$('.latitude').hide()
$('.longitude').hide()
// reset the arrays
var data;
var flightshere = [];
var flightsdata = [];
var datafids = [];
removal = [];
// Local test with a static file
$.getJSON('data.json', function(data) {
// Server test with live data, has to be proxied when in case of breaking
// the same origin policy
//$.getJSON('proxy.php?url=http://crossfeed.fgx.ch/data&mode=native', function(data) {
//$.getJSON('crossfeed.php', function(data) {
// Get the data and push it in an array
jQuery.each(data.flights, function() {
// Defining the flight row
var flightrow = "<tr class='flightrow' id='"+this.fid+"'>"+
"<td class='fid' style='display: none'><p>"+this.fid+
"<td class='callsign'><p>"+this.callsign.toUpperCase()+
"<td class='lon' style='display: none'><p>"+this.lon+
"<td class='lat' style='display: none'><p>"+this.lat+
"<td class='hdg'><p>"+this.hdg+
"<td class='alt_ft'><p>"+this.alt_ft+
"<td class='spd_kts'><p>"+this.spd_kts+"</tr>"
flightsdata.push($(flightrow))
datafids.push(JSON.stringify(this.fid))
});
$('.flightrow').each( function() {
flightshere.push($(this).children('.fid').text())
});
// First load, append all data to the page
if (firstload > 0) {
$.each(flightsdata, function () {
addFlight($(this))
});
}
// ADD OR UPDATE: Not first load, so append only what's not already here
else{
$.each(flightsdata, function(i) {
var checkfidel = $(this).children('.fid').text()
if ($.inArray(checkfidel, selected) >= 0) {
$(this).addClass('back_greenB7F')
}else{
$(this).removeClass('back_greenB7F')
}
// Update vars
var checkfid = $(this).children('.fid').text()
var lat = $(this).children('.lat').text()
var lon = $(this).children('.lon').text()
var hdg = $(this).children('.hdg').text()
var spd_kts = $(this).children('.spd_kts').text()
// Update check
if ($.inArray(checkfidel, flightshere) > -1) {
// Update table
var checkfid2 = "\[id=\""+checkfid+"\"\]"
if (spd_kts < 10) {$(this).addClass('gray666')}
$(checkfid2).replaceWith($(this))
// Update the map
// For openlayers we have to change lat/lon order, grmbl
updatePlanes(checkfid, lon, lat, hdg, spd_kts)
}
else{
//console.log("Flight to add: "+flightsdata[i].children('.callsign').text())
if (spd_kts < 10) {$(this).addClass('gray666')}
addFlight($(this))
}
});
}
// REMOVE: Have a look what needs to be removed and add it to the removal array
$('.fid').each( function() {
var fidrem = $(this).children().text()
if ($.inArray(fidrem, datafids) < 0) {
removal.push(fidrem)
}
if ($.inArray(fidrem, flightsdata) > -1) {
}
});
removeFlights();
// Showing the heading with background image
$('.hdg').each( function() {
var value = $(this).children('p').text()
if (between(value,0,22) || between(value,293,360)) {
$(this).addClass('hdg_n')
}
if (between(value,23,67)) {
$(this).addClass('hdg_ne')
}
if (between(value,68,112)) {
$(this).addClass('hdg_e')
}
if (between(value,113,157)) {
$(this).addClass('hdg_se')
}
if (between(value,158,202)) {
$(this).addClass('hdg_s')
}
if (between(value,203,247)) {
$(this).addClass('hdg_sw')
}
if (between(value,248,292)) {
$(this).addClass('hdg_w')
}
});
$('.flightrow').hover(
function() {
$(this).addClass('back_grayCCC')
},
function() {
$(this).removeClass('back_grayCCC')
}
);
// Select a flight in the list
$('.flightrow').click(
function() {
var check = $(this).children('.fid').text()
if ($.inArray(check, selected) < 0) {
$(this).addClass('back_greenB7F')
selected.push(check)
zoomToBoundsSelected(selected)
}else{
$(this).removeClass('back_greenB7F')
var index = selected.indexOf($(this).children('.fid').text());
selected.splice(index,1);
$(this).removeClass('back_greenB7F')
}
});
// Refresh was 4 sec, like an old radar ;-)
setTimeout("loadFlights()",1000);
}); // end of data load
}); // end of document ready
} // end of loadFlights
// ----------------------------------------------------------------------------------------------
// initial loading in document body now, but we set first load flag here
// ----------------------------------------------------------------------------------------------
firstload = 0
// ----------------------------------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------------------------------
// Check number between
function between(x, min, max) {
return x >= min && x <= max;
}
// Array IE workaround from Mozilla, fastest implementation
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
"use strict";
if (this == null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (len === 0) {
return -1;
}
var n = 0;
if (arguments.length > 1) {
n = Number(arguments[1]);
if (n != n) { // shortcut for verifying if it's NaN
n = 0;
} else if (n != 0 && n != Infinity && n != -Infinity) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
}
if (n >= len) {
return -1;
}
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
for (; k < len; k++) {
if (k in t && t[k] === searchElement) {
return k;
}
}
return -1;
}
}
// The good old GUP function by Geoff McLane
function gup( name ) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
</script>
<style type="text/css">
</style>
</head>
<body>
<div id="wrapper">
<div id="header_flights"></div>
<div id="content_flights"></div>
</div>
<div id="map"></div>
<!-- This gives IE compatibility with the OpenLayers map init function -->
<script type="text/javascript" defer="defer">
var lat = gup('lat');
var lon = gup('lon');
var zoom = gup('zoom');
init(lon,lat,zoom);
loadFlights();
</script>
</body>
</html>