Skip to content

Commit 2f9a377

Browse files
authored
Merge pull request #27 from LukePrior/testing
Support for displaying old sonde + fixes
2 parents 10beb0d + 6cc0f5b commit 2f9a377

File tree

2 files changed

+136
-28
lines changed

2 files changed

+136
-28
lines changed

css/main.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ header .search form input[type='submit'] {
441441
border: 1px solid #ccc;
442442
cursor: pointer;
443443
z-index: 5;
444+
text-align: center;
444445
}
445446

446447
#main .row .data .vbutton.active {

js/tracker.js

Lines changed: 135 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ function clean_refresh(text, force, history_step) {
334334
history_step = !!history_step;
335335

336336
if(text == wvar.mode && !force) return false;
337-
if(ajax_inprogress) return false;
338-
339337
stopAjax();
340338

341339
// reset mode if, invalid mode is specified
@@ -813,7 +811,6 @@ function updateAltitude(vcallsign) {
813811
} else if(position.gps_alt > 55000) {
814812
position.gps_alt = 55000;
815813
}
816-
vehicle.marker.setAltitude(pixel_altitude);
817814
}
818815

819816
function updateZoom() {
@@ -1224,11 +1221,11 @@ function updateVehicleInfo(vcallsign, newPosition) {
12241221
//'<span>' + vcallsign + ' <i class="icon-target"></i></span>' +
12251222
'<canvas class="graph"></canvas>' +
12261223
'<i class="arrow"></i></div>' +
1227-
'<div class="data">' +
1224+
'<div class="data" style="min-height:' + (vehicle.image_src_size[1]+95) + 'px">' +
12281225
'<img class="'+((vehicle.vehicle_type=="car")?'car':'')+'" src="'+image+'" />' +
1229-
'<span class="vbutton path '+((vehicle.polyline_visible) ? 'active' : '')+'" data-vcallsign="'+vcallsign+'"' +
1230-
' style="top:'+(vehicle.image_src_size[1]+55)+'px">Path</span>' +
1231-
'<span class="sbutton" onclick="shareVehicle(\'' + vcallsign + '\')">Share</span>' +
1226+
'<span class="vbutton path '+((vehicle.polyline_visible) ? 'active' : '')+'" data-vcallsign="'+vcallsign+'"' + ' style="top:'+(vehicle.image_src_size[1]+55)+'px">Path</span>' +
1227+
((vehicle.vehicle_type!="car") ? '<span class="sbutton" onclick="shareVehicle(\'' + vcallsign + '\')" style="top:'+(vehicle.image_src_size[1]+85)+'px">Share</span>' : '') +
1228+
((vehicle.vehicle_type!="car") ? '<span class="sbutton" onclick="window.open(\'https://sondehub.org/card/' + vcallsign + '\')" style="top:'+(vehicle.image_src_size[1]+115)+'px">Card</span>' : '') +
12321229
((vcallsign in hysplit) ? '<span class="vbutton hysplit '+((hysplit[vcallsign].getMap()) ? 'active' : '')+'"' +
12331230
' data-vcallsign="'+vcallsign+'" style="top:'+(vehicle.image_src_size[1]+55+21+10)+'px">HYSPLIT</span>' : '') +
12341231
((vcallsign.substr(0, 6) in ssdv) ? '<a class="vbutton active" href="//ssdv.habhub.org/' + vcallsign.substr(0, 6) + '"' +
@@ -1642,7 +1639,6 @@ function mapInfoBox_handle_path_fetch(id,vehicle) {
16421639
var callsign_list = []
16431640
for(var rxcall in data.callsign){
16441641
if(data.callsign.hasOwnProperty(rxcall)) {
1645-
_new_call += "<b>Received via:&nbsp;</b> ";
16461642
_new_call = rxcall;
16471643
if(data.callsign[rxcall].hasOwnProperty('snr')){
16481644
if(data.callsign[rxcall].snr){
@@ -1945,11 +1941,6 @@ function addPosition(position) {
19451941
}
19461942
if (!wvar.nyan) {this.setIcon(img);};
19471943
};
1948-
marker.setAltitude = function(alt) {
1949-
//var pos = overlay.getProjection().fromLatLngToDivPixel(this.shadow.getLatLng());
1950-
//pos.y -= alt;
1951-
//this.setLatLng(overlay.getProjection().fromDivPixelToLatLng(pos));
1952-
};
19531944

19541945
// Add landing marker if the payload provides a predicted landing position.
19551946
if (position.data.hasOwnProperty('pred_lat') && position.data.hasOwnProperty('pred_lon')){
@@ -2588,8 +2579,10 @@ function graphAddPosition(vcallsign, new_data) {
25882579

25892580
var ajax_positions = null;
25902581
var ajax_positions_single = null;
2582+
var ajax_positions_old = null;
25912583
var ajax_inprogress = false;
25922584
var ajax_inprogress_single = false;
2585+
var ajax_inprogress_old = "none";
25932586

25942587
function refresh() {
25952588
if(ajax_inprogress) {
@@ -2598,6 +2591,14 @@ function refresh() {
25982591
return;
25992592
}
26002593

2594+
if (ajax_inprogress_old == wvar.query) {
2595+
if (vehicles.hasOwnProperty(wvar.query)) {
2596+
return;
2597+
}
2598+
}
2599+
2600+
document.getElementById("timeperiod").disabled = false;
2601+
26012602
ajax_inprogress = true;
26022603

26032604
$("#stText").text("checking |");
@@ -2620,7 +2621,17 @@ function refresh() {
26202621
success: function(response, textStatus) {
26212622
$("#stText").text("loading |");
26222623
response.fetch_timestamp = Date.now();
2623-
update(response);
2624+
if (wvar.query != null) {
2625+
if (JSON.stringify(response).indexOf(wvar.query) == -1) {
2626+
//check using new API
2627+
ajax_inprogress = false;
2628+
refreshSingleOld(wvar.query);
2629+
} else {
2630+
update(response);
2631+
}
2632+
} else {
2633+
update(response);
2634+
}
26242635
$("#stText").text("");
26252636
$("#stTimer").attr("data-timestamp", response.fetch_timestamp);
26262637
},
@@ -2633,9 +2644,13 @@ function refresh() {
26332644
$("#stText").text("no connection |");
26342645
$("#stTimer").attr("data-timestamp", data.fetch_timestamp);
26352646
}
2647+
2648+
ajax_inprogress = false;
26362649
},
26372650
complete: function(request, textStatus) {
2638-
document.getElementById("timeperiod").disabled = false;
2651+
if (ajax_inprogress_old != wvar.query) {
2652+
document.getElementById("timeperiod").disabled = false;
2653+
}
26392654
clearTimeout(periodical);
26402655
if (Object.keys(vehicles).length > 1) {
26412656
navigator.setAppBadge(Object.keys(vehicles).length); //show number of vehicles on PWA taskbar
@@ -2657,6 +2672,12 @@ function refreshSingle(serial, first) {
26572672
}
26582673
return;
26592674
}
2675+
2676+
if (ajax_inprogress_old == wvar.query) {
2677+
if (vehicles.hasOwnProperty(wvar.query)) {
2678+
return;
2679+
}
2680+
}
26602681

26612682
if (first === undefined) {
26622683
first = false;
@@ -2689,7 +2710,86 @@ function refreshSingle(serial, first) {
26892710
periodical_focus = setTimeout(refreshSingle, timer_seconds_focus * 1000, serial);
26902711
}
26912712
});
2692-
}
2713+
}
2714+
2715+
function refreshSingleOld(serial) {
2716+
2717+
if (ajax_inprogress_old == wvar.query) {
2718+
if (vehicles.hasOwnProperty(wvar.query)) {
2719+
return;
2720+
}
2721+
}
2722+
2723+
document.getElementById("timeperiod").disabled = true;
2724+
2725+
var data_url = "https://api.v2.sondehub.org/sonde/" + encodeURIComponent(serial);
2726+
2727+
ajax_inprogress_old = serial;
2728+
2729+
ajax_positions_old = $.ajax({
2730+
type: "GET",
2731+
url: data_url,
2732+
dataType: "json",
2733+
success: function(data, textStatus) {
2734+
var response = {};
2735+
response.positions = {};
2736+
var dataTemp = [];
2737+
for (var i = data.length - 1; i >= 0; i--) {
2738+
if (data[i].hasOwnProperty('subtype')) {
2739+
if (data[i].subtype != "SondehubV1") {
2740+
var dataTempEntry = {};
2741+
var station = data[i].uploader_callsign
2742+
dataTempEntry.callsign = {};
2743+
dataTempEntry.callsign[station] = {};
2744+
dataTempEntry.callsign[station].snr = data[i].snr;
2745+
dataTempEntry.callsign[station].rssi = data[i].rssi;
2746+
dataTempEntry.gps_alt = data[i].alt;
2747+
dataTempEntry.gps_heading = data[i].heading;
2748+
dataTempEntry.gps_lat = data[i].lat;
2749+
dataTempEntry.gps_lon = data[i].lon;
2750+
dataTempEntry.gps_time = data[i].datetime;
2751+
dataTempEntry.server_time = data[i].datetime;
2752+
dataTempEntry.vehicle = data[i].serial;
2753+
dataTempEntry.position_id = data[i].serial + "-" + data[i].datetime;
2754+
dataTempEntry.data = {};
2755+
if (data[i].batt) {
2756+
dataTempEntry.data.batt = data[i].batt;
2757+
}
2758+
if (data[i].burst_timer) {
2759+
dataTempEntry.data.burst_timer = data[i].burst_timer;
2760+
}
2761+
if (data[i].frequency) {
2762+
dataTempEntry.data.burst_timer = data[i].frequency;
2763+
}
2764+
if (data[i].humidity) {
2765+
dataTempEntry.data.humidity = data[i].humidity;
2766+
}
2767+
if (data[i].manufacturer) {
2768+
dataTempEntry.data.manufacturer = data[i].manufacturer;
2769+
}
2770+
if (data[i].sats) {
2771+
dataTempEntry.data.sats = data[i].sats;
2772+
}
2773+
if (data[i].temp) {
2774+
dataTempEntry.data.temperature_external = data[i].temp;
2775+
}
2776+
if (data[i].type) {
2777+
dataTempEntry.data.type = data[i].type;
2778+
dataTempEntry.type = data[i].type;
2779+
}
2780+
if (data[i].pressure) {
2781+
dataTempEntry.data.pressure = data[i].pressure;
2782+
}
2783+
dataTemp.push(dataTempEntry)
2784+
}
2785+
}
2786+
}
2787+
response.positions.position = dataTemp;
2788+
response.fetch_timestamp = Date.now();
2789+
update(response, "old");
2790+
}
2791+
});
2792+
}
26932793

26942794
function refreshReceivers() {
26952795
// if options to hide receivers is selected do nothing
@@ -2978,6 +3078,9 @@ function stopAjax() {
29783078
if(ajax_positions) ajax_positions.abort();
29793079

29803080
clearTimeout(periodical_focus);
3081+
if(ajax_positions_single) ajax_positions_single.abort();
3082+
3083+
if(ajax_positions_old) ajax_positions_old.abort();
29813084

29823085
clearTimeout(periodical_predictions);
29833086
periodical_predictions = null;
@@ -3339,16 +3442,18 @@ function update(response, flag) {
33393442
!response.positions.position ||
33403443
!response.positions.position.length) {
33413444

3342-
// if no vehicles are found, this will remove the spinner and put a friendly message
3343-
$("#main .empty").html("<span>No vehicles :(</span>");
3445+
if (flag != "old") {
3446+
// if no vehicles are found, this will remove the spinner and put a friendly message
3447+
$("#main .empty").html("<span>No vehicles :(</span>");
33443448

3345-
if (flag === undefined) {
3346-
ajax_inprogress = false;
3347-
} else {
3348-
ajax_inprogress_single = false;
3349-
}
3449+
if (flag === undefined) {
3450+
ajax_inprogress = false;
3451+
} else {
3452+
ajax_inprogress_single = false;
3453+
}
33503454

3351-
return;
3455+
return;
3456+
}
33523457
}
33533458

33543459
ssdv = (!response.ssdv) ? {} : response.ssdv;
@@ -3444,10 +3549,12 @@ function update(response, flag) {
34443549

34453550
if(periodical_predictions === null) refreshPredictions();
34463551

3447-
if (flag === undefined) {
3448-
ajax_inprogress = false;
3449-
} else {
3450-
ajax_inprogress_single = false;
3552+
if (flag != "old") {
3553+
if (flag === undefined) {
3554+
ajax_inprogress = false;
3555+
} else {
3556+
ajax_inprogress_single = false;
3557+
}
34513558
}
34523559
}
34533560
};

0 commit comments

Comments
 (0)