Skip to content

Commit 72113f8

Browse files
authored
Merge pull request projecthorus#23 from LukePrior/testing
API Fix + Nyan mode
2 parents b8d42fe + 4b946a8 commit 72113f8

File tree

2 files changed

+126
-29
lines changed

2 files changed

+126
-29
lines changed

js/app.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ function lhash_update(history_step) {
3535
$("header .search input[type='text']").val(wvar.query);
3636
}
3737

38+
// other vars
39+
if(wvar.nyan) {
40+
hash += "&nyan=1";
41+
}
42+
3843
hash = encodeURI(hash);
3944
// set state
4045
if(history_supported) {
@@ -80,6 +85,7 @@ function load_hash(no_refresh) {
8085
zoom: true,
8186
focus: "",
8287
query: "",
88+
nyan: false,
8389
};
8490

8591
parms.forEach(function(v) {
@@ -124,7 +130,7 @@ function load_hash(no_refresh) {
124130
});
125131

126132
// check if we should force refresh
127-
['mode','query'].forEach(function(k) {
133+
['mode','query','nyan'].forEach(function(k) {
128134
if(wvar[k] != def[k]) refresh = true;
129135
});
130136

js/tracker.js

Lines changed: 119 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ var balloon_index = 0;
3636
var balloon_colors_name = ["red", "blue", "green", "yellow", "purple", "orange", "cyan"];
3737
var balloon_colors = ["#f00", "blue", "green", "#FDFC30", "#c700e6", "#ff8a0f", "#0fffca"];
3838

39+
var nyan_color_index = 0;
40+
var nyan_colors = ['nyan', 'nyan-coin', 'nyan-mon', 'nyan-pirate', 'nyan-cool', 'nyan-tothemax', 'nyan-pumpkin', 'nyan-afro', 'nyan-coin', 'nyan-mummy'];
41+
var rainbow = ["#ff0000", "#fc9a00", "#f6ff00", "#38ff01", "#009aff","#0000ff"];
42+
3943
var map = null;
4044
var overlay = null;
4145
var layer_clouds = null;
4246

4347
var notamOverlay = null;
4448

49+
var svgRenderer = L.svg();
50+
4551
var modeList = [
4652
// "Position",
4753
"1 hour",
@@ -353,6 +359,7 @@ function clean_refresh(text, force, history_step) {
353359

354360
car_index = 0;
355361
balloon_index = 0;
362+
nyan_color_index = 0;
356363
stopFollow(force);
357364

358365
// add loading spinner in the vehicle list
@@ -366,6 +373,7 @@ function clean_refresh(text, force, history_step) {
366373
lhash_update(history_step);
367374

368375
clearTimeout(periodical);
376+
clearTimeout(periodical_focus);
369377
clearTimeout(periodical_receivers);
370378
clearTimeout(periodical_recoveries);
371379

@@ -384,8 +392,6 @@ function load() {
384392
preferCanvas: true,
385393
});
386394

387-
var svgRenderer = L.svg();
388-
389395
map.addControl(new L.Control.Fullscreen({ position: 'bottomleft' }));
390396

391397
new L.Control.Zoom({ position: 'bottomright' }).addTo(map);
@@ -888,6 +894,9 @@ function stopFollow(no_data_reset) {
888894
wvar.focus = "";
889895
}
890896

897+
//stop detailed data
898+
clearTimeout(periodical_focus);
899+
891900
// clear graph
892901
if(plot) plot = $.plot(plot_holder, {}, plot_options);
893902
updateGraph(null, true);
@@ -917,7 +926,8 @@ function followVehicle(vcallsign, noPan, force) {
917926
}
918927

919928
if(follow_vehicle != vcallsign || force) {
920-
refresh(vcallsign);
929+
clearTimeout(periodical_focus);
930+
refreshSingle(vcallsign, true);
921931
focusVehicle(vcallsign);
922932

923933
follow_vehicle = vcallsign;
@@ -1850,7 +1860,8 @@ function addPosition(position) {
18501860
listScroll.refresh();
18511861
listScroll.scrollToElement(_vehicle_idname);
18521862
followVehicle($(_vehicle_idname).attr('data-vcallsign'));
1853-
refresh(_vehicle_id);
1863+
clearTimeout(periodical_focus);
1864+
refreshSingle(_vehicle_id, true);
18541865
};
18551866

18561867
marker.shadow = marker_shadow;
@@ -1900,7 +1911,7 @@ function addPosition(position) {
19001911
});
19011912
}
19021913
}
1903-
this.setIcon(img);
1914+
if (!wvar.nyan) {this.setIcon(img);};
19041915
};
19051916
marker.setAltitude = function(alt) {
19061917
//var pos = overlay.getProjection().fromLatLngToDivPixel(this.shadow.getLatLng());
@@ -2069,6 +2080,41 @@ function addPosition(position) {
20692080

20702081
// deep copy yaxes config for graph
20712082
plot_options.yaxes.forEach(function(v) { vehicle_info.graph_yaxes.push($.extend({}, v)); });
2083+
2084+
//nyan cat (very important feature)
2085+
if(wvar.nyan && vehicle_info.vehicle_type == "balloon") {
2086+
var nyan = nyan_colors[nyan_color_index] + ".gif";
2087+
nyan_color_index = (nyan_color_index + 1) % nyan_colors.length;
2088+
var nyanw = (nyan_color_index == 4) ? 104 : 55;
2089+
2090+
nyanIcon = new L.icon ({
2091+
iconUrl: host_url + markers_url + nyan,
2092+
iconSize: [nyanw,39],
2093+
iconAnchor: [26,20],
2094+
});
2095+
2096+
vehicle_info.marker.setIcon(nyanIcon);
2097+
2098+
vehicle_info.image_src = host_url + markers_url + "hab_nyan.gif";
2099+
vehicle_info.image_src_offset = [-34,-70];
2100+
2101+
var k;
2102+
for(k in vehicle_info.polyline) {
2103+
map.removeLayer(vehicle_info.polyline[k]);
2104+
}
2105+
2106+
vehicle_info.polyline = [];
2107+
2108+
for(k in rainbow) {
2109+
vehicle_info.polyline.push(new L.Polyline(point, {
2110+
zIndexOffset: (Z_PATH - (k * 1)),
2111+
color: rainbow[k],
2112+
opacity: 1,
2113+
weight: (k*4) + 2,
2114+
}).addTo(map));
2115+
vehicle_info.polyline[k].bringToBack();
2116+
}
2117+
}
20722118

20732119
vehicle_info.kill = function() {
20742120
$(".vehicle"+vehicle_info.uuid).remove();
@@ -2507,15 +2553,15 @@ function graphAddPosition(vcallsign, new_data) {
25072553
}
25082554

25092555
var ajax_positions = null;
2556+
var ajax_positions_single = null;
25102557
var ajax_inprogress = false;
2558+
var ajax_inprogress_single = false;
25112559

2512-
function refresh(serial) {
2560+
function refresh() {
25132561
if(ajax_inprogress) {
2514-
if (serial === undefined) {
2515-
clearTimeout(periodical);
2516-
periodical = setTimeout(refresh, 2000);
2517-
return;
2518-
}
2562+
clearTimeout(periodical);
2563+
periodical = setTimeout(refresh, 2000);
2564+
return;
25192565
}
25202566

25212567
ajax_inprogress = true;
@@ -2530,11 +2576,7 @@ function refresh(serial) {
25302576
var mode = wvar.mode.toLowerCase();
25312577
mode = (mode == "position") ? "latest" : mode.replace(/ /g,"");
25322578

2533-
if (serial === undefined) {
2534-
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=" + position_id + "&vehicles=" + encodeURIComponent(wvar.query);
2535-
} else {
2536-
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=0&vehicles=" + encodeURIComponent(serial);
2537-
}
2579+
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=" + position_id + "&vehicles=" + encodeURIComponent(wvar.query);
25382580

25392581
ajax_positions = $.ajax({
25402582
type: "GET",
@@ -2544,10 +2586,7 @@ function refresh(serial) {
25442586
success: function(response, textStatus) {
25452587
$("#stText").text("loading |");
25462588
response.fetch_timestamp = Date.now();
2547-
if (serial === undefined) {update(response);} else {
2548-
//vehicles[serial].kill();
2549-
update(response, true);
2550-
}
2589+
update(response);
25512590
$("#stText").text("");
25522591
$("#stTimer").attr("data-timestamp", response.fetch_timestamp);
25532592
},
@@ -2569,6 +2608,50 @@ function refresh(serial) {
25692608
});
25702609
}
25712610

2611+
function refreshSingle(serial, first) {
2612+
if(ajax_inprogress_single) {
2613+
clearTimeout(periodical_focus);
2614+
if (first) {
2615+
periodical_focus = setTimeout(refreshSingle, 2000, serial, first);
2616+
} else {
2617+
periodical_focus = setTimeout(refreshSingle, 2000, serial);
2618+
}
2619+
return;
2620+
}
2621+
2622+
if (first === undefined) {
2623+
first = false;
2624+
}
2625+
2626+
ajax_inprogress_single = true;
2627+
2628+
var mode = wvar.mode.toLowerCase();
2629+
mode = (mode == "position") ? "latest" : mode.replace(/ /g,"");
2630+
2631+
if (first){
2632+
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=0&vehicles=" + encodeURIComponent(serial);
2633+
} else {
2634+
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=" + position_id + "&vehicles=" + encodeURIComponent(serial);
2635+
}
2636+
2637+
ajax_positions_single = $.ajax({
2638+
type: "GET",
2639+
url: data_url,
2640+
data: data_str,
2641+
dataType: "json",
2642+
success: function(response, textStatus) {
2643+
response.fetch_timestamp = Date.now();
2644+
if (!first) {update(response, false);} else {
2645+
update(response, true);
2646+
}
2647+
},
2648+
complete: function(request, textStatus) {
2649+
clearTimeout(periodical_focus);
2650+
periodical_focus = setTimeout(refreshSingle, timer_seconds_focus * 1000, serial);
2651+
}
2652+
});
2653+
}
2654+
25722655
function refreshReceivers() {
25732656
// if options to hide receivers is selected do nothing
25742657
if(offline.get('opt_hide_receivers')) return;
@@ -2828,13 +2911,15 @@ function habitat_doc_step(hab_docs) {
28282911
}
28292912

28302913

2831-
var periodical, periodical_receivers, periodical_recoveries;
2914+
var periodical, periodical_focus, periodical_receivers, periodical_recoveries;
28322915
var periodical_predictions = null;
28332916
var timer_seconds = 5;
2917+
var timer_seconds_focus = 1;
28342918

28352919
function startAjax() {
28362920
// prevent insane clicks to start numerous requests
28372921
clearTimeout(periodical);
2922+
clearTimeout(periodical_focus);
28382923
clearTimeout(periodical_receivers);
28392924
clearTimeout(periodical_recoveries);
28402925
clearTimeout(periodical_predictions);
@@ -2853,6 +2938,8 @@ function stopAjax() {
28532938
clearTimeout(periodical);
28542939
if(ajax_positions) ajax_positions.abort();
28552940

2941+
clearTimeout(periodical_focus);
2942+
28562943
clearTimeout(periodical_predictions);
28572944
periodical_predictions = null;
28582945
if(ajax_predictions) ajax_predictions.abort();
@@ -3211,7 +3298,11 @@ function update(response, flag) {
32113298
// if no vehicles are found, this will remove the spinner and put a friendly message
32123299
$("#main .empty").html("<span>No vehicles :(</span>");
32133300

3214-
ajax_inprogress = false;
3301+
if (flag === undefined) {
3302+
ajax_inprogress = false;
3303+
} else {
3304+
ajax_inprogress_single = false;
3305+
}
32153306

32163307
return;
32173308
}
@@ -3273,11 +3364,7 @@ function update(response, flag) {
32733364
if(vehicle === undefined) return;
32743365

32753366
if(vehicle.updated) {
3276-
if (flag) {
3277-
updatePolyline(vcallsign, true);
3278-
} else {
3279-
updatePolyline(vcallsign);
3280-
}
3367+
updatePolyline(vcallsign, flag);
32813368

32823369
updateVehicleInfo(vcallsign, vehicle.curr_position);
32833370

@@ -3313,7 +3400,11 @@ function update(response, flag) {
33133400

33143401
if(periodical_predictions === null) refreshPredictions();
33153402

3316-
ajax_inprogress = false;
3403+
if (flag === undefined) {
3404+
ajax_inprogress = false;
3405+
} else {
3406+
ajax_inprogress_single = false;
3407+
}
33173408
}
33183409
};
33193410

0 commit comments

Comments
 (0)