Skip to content

Commit f1b564c

Browse files
committed
support infobox for old data
1 parent 12ae105 commit f1b564c

File tree

1 file changed

+175
-85
lines changed

1 file changed

+175
-85
lines changed

js/tracker.js

Lines changed: 175 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,114 +2162,204 @@ function mapInfoBox_handle_path_fetch(id,vehicle) {
21622162
var date = new Date(parseInt(id)).toISOString()
21632163
var url = newdata_url + "?duration=0&serial=" + vehicle.callsign + "&datetime=" + date;
21642164

2165-
$.getJSON(url, function(data) {
2166-
if (Object.keys(data).length === 0) {
2165+
$.ajax({
2166+
type: "GET",
2167+
url: url,
2168+
dataType: "json",
2169+
success: function(data) {
2170+
mapInfoBox_handle_path_new(data, vehicle)
2171+
},
2172+
error: function() {
2173+
mapInfoBox_handle_path_old(vehicle, id)
2174+
}
2175+
});
2176+
};
2177+
2178+
function mapInfoBox_handle_path_old(vehicle, id) {
2179+
var url = "https://api.v2.sondehub.org/sonde/" + vehicle.callsign;
2180+
var index = vehicle["positions_ids"][vehicle["positions_ts"].indexOf(id)].substring(vehicle.callsign.length + 1);
2181+
2182+
$.ajax({
2183+
type: "GET",
2184+
url: url,
2185+
dataType: "json",
2186+
success: function(data) {
2187+
for (var i = 0; i < data.length; i++) {
2188+
if (data[i]["datetime"] == index) {
2189+
data = data[i];
2190+
div = document.createElement('div');
2191+
2192+
html = "<div style='line-height:16px;position:relative;'>";
2193+
html += "<div>"+data.serial+"<span style=''>("+data.datetime+")</span></div>";
2194+
html += "<hr style='margin:5px 0px'>";
2195+
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(data.lat, 5) + ',&nbsp;' + roundNumber(data.lon, 5)+"</div>";
2196+
2197+
var imp = offline.get('opt_imperial');
2198+
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(data.alt)) : parseInt(data.alt)).toLocaleString("us");
2199+
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
2200+
2201+
html += "<div><b>Altitude:&nbsp;</b>"+text_alt+"</div>";
2202+
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(data.datetime))+"</div>";
2203+
2204+
var value = vehicle.path_length;
2205+
2206+
html += "<div><b>Distance:&nbsp;</b>";
2207+
2208+
if(offline.get('opt_imperial')) {
2209+
html += Math.round(value*0.000621371192) + "&nbsp;mi";
2210+
} else {
2211+
html += Math.round(value/10)/100 + "&nbsp;km";
2212+
}
2213+
2214+
html += "</div>";
2215+
html += "<div><b>Duration:&nbsp;</b>" + format_time_friendly(vehicle.start_time, convert_time(vehicle.curr_position.gps_time)) + "</div>";
2216+
2217+
html += "<hr style='margin:5px 0px'>";
2218+
2219+
if (data.hasOwnProperty("humidity")) {
2220+
html += "<div><b>Relative Humidity:&nbsp;</b>" + data.humidity + " %</div>";
2221+
};
2222+
if (data.hasOwnProperty("temp")) {
2223+
html += "<div><b>Temperature External:&nbsp;</b>" + data.temp + "°C</div>";
2224+
};
2225+
if (data.hasOwnProperty("comment")) {
2226+
html += "<div><b>Comment:&nbsp;</b>" + data.comment + "</div>";
2227+
};
2228+
2229+
html += "<hr style='margin:0px;margin-top:5px'>";
2230+
html += "<div style='font-size:11px;'>"
2231+
2232+
if (data.hasOwnProperty("uploader_callsign")) {
2233+
html += "<div>" + data.uploader_callsign + "</div>";
2234+
};
2235+
2236+
div.innerHTML = html;
2237+
2238+
mapInfoBox.setContent(div);
2239+
mapInfoBox.openOn(map);
2240+
2241+
setTimeout(function() {
2242+
div.parentElement.style.overflow = "";
2243+
div.parentElement.style.overflowWrap = "break-word";
2244+
}, 16);
2245+
}
2246+
}
2247+
},
2248+
error: function() {
21672249
mapInfoBox.setContent("not&nbsp;found");
21682250
mapInfoBox.openOn(map);
21692251
return;
2170-
}
2252+
}
2253+
});
2254+
}
2255+
2256+
function mapInfoBox_handle_path_new(data, vehicle) {
2257+
if (Object.keys(data).length === 0) {
2258+
mapInfoBox.setContent("not&nbsp;found");
2259+
mapInfoBox.openOn(map);
2260+
return;
2261+
}
21712262

2172-
data = data[vehicle.callsign][date];
2263+
data = data[vehicle.callsign][date];
21732264

2174-
div = document.createElement('div');
2265+
div = document.createElement('div');
21752266

2176-
html = "<div style='line-height:16px;position:relative;'>";
2177-
html += "<div>"+data.serial+"<span style=''>("+date+")</span></div>";
2178-
html += "<hr style='margin:5px 0px'>";
2179-
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(data.lat, 5) + ',&nbsp;' + roundNumber(data.lon, 5)+"</div>";
2267+
html = "<div style='line-height:16px;position:relative;'>";
2268+
html += "<div>"+data.serial+"<span style=''>("+date+")</span></div>";
2269+
html += "<hr style='margin:5px 0px'>";
2270+
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(data.lat, 5) + ',&nbsp;' + roundNumber(data.lon, 5)+"</div>";
21802271

2181-
var imp = offline.get('opt_imperial');
2182-
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(data.alt)) : parseInt(data.alt)).toLocaleString("us");
2183-
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
2272+
var imp = offline.get('opt_imperial');
2273+
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(data.alt)) : parseInt(data.alt)).toLocaleString("us");
2274+
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
21842275

2185-
html += "<div><b>Altitude:&nbsp;</b>"+text_alt+"</div>";
2186-
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(date))+"</div>";
2276+
html += "<div><b>Altitude:&nbsp;</b>"+text_alt+"</div>";
2277+
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(date))+"</div>";
21872278

2188-
var value = vehicle.path_length;
2279+
var value = vehicle.path_length;
21892280

2190-
html += "<div><b>Distance:&nbsp;</b>";
2281+
html += "<div><b>Distance:&nbsp;</b>";
21912282

2192-
if(offline.get('opt_imperial')) {
2193-
html += Math.round(value*0.000621371192) + "mi";
2194-
} else {
2195-
html += Math.round(value/10)/100 + "&nbsp;km";
2196-
}
2283+
if(offline.get('opt_imperial')) {
2284+
html += Math.round(value*0.000621371192) + "&nbsp;mi";
2285+
} else {
2286+
html += Math.round(value/10)/100 + "&nbsp;km";
2287+
}
21972288

2198-
html += "</div>";
2199-
html += "<div><b>Duration:&nbsp;</b>" + format_time_friendly(vehicle.start_time, convert_time(vehicle.curr_position.gps_time)) + "</div>";
2289+
html += "</div>";
2290+
html += "<div><b>Duration:&nbsp;</b>" + format_time_friendly(vehicle.start_time, convert_time(vehicle.curr_position.gps_time)) + "</div>";
22002291

2201-
html += "<hr style='margin:5px 0px'>";
2292+
html += "<hr style='margin:5px 0px'>";
22022293

2203-
if (data.hasOwnProperty("batt")) {
2204-
html += "<div><b>Battery Voltage:&nbsp;</b>" + data.batt + " V</div>";
2205-
};
2206-
if (data.hasOwnProperty("tx_frequency")) {
2207-
html += "<div><b>TX Frequency:&nbsp;</b>" + data.tx_frequency + " MHz</div>";
2208-
} else if (data.hasOwnProperty("frequency")) {
2209-
html += "<div><b>Frequency:&nbsp;</b>" + data.frequency + " MHz</div>";
2210-
};
2211-
if (data.hasOwnProperty("humidity")) {
2212-
html += "<div><b>Relative Humidity:&nbsp;</b>" + data.humidity + " %</div>";
2213-
};
2214-
if (data.hasOwnProperty("manufacturer")) {
2215-
html += "<div><b>Manufacturer:&nbsp;</b>" + data.manufacturer + "</div>";
2216-
};
2217-
if (data.hasOwnProperty("sats")) {
2218-
html += "<div><b>Satellites:&nbsp;</b>" + data.sats + "</div>";
2219-
};
2220-
if (data.hasOwnProperty("temp")) {
2221-
html += "<div><b>Temperature External:&nbsp;</b>" + data.temp + "°C</div>";
2222-
};
2223-
if (data.hasOwnProperty("subtype")) {
2224-
html += "<div><b>Sonde Type:&nbsp;</b>" + data.subtype + "</div>";
2225-
} else if (data.hasOwnProperty("type")) {
2226-
html += "<div><b>Sonde Type:&nbsp;</b>" + data.type + "</div>";
2227-
};
2228-
if (data.hasOwnProperty("pressure")) {
2229-
html += "<div><b>Pressure:&nbsp;</b>" + data.pressure + " Pa</div>";
2230-
};
2231-
if (data.hasOwnProperty("xdata")) {
2232-
html += "<div><b>XDATA:&nbsp;</b>" + data.xdata + "</div>";
2233-
};
2294+
if (data.hasOwnProperty("batt")) {
2295+
html += "<div><b>Battery Voltage:&nbsp;</b>" + data.batt + " V</div>";
2296+
};
2297+
if (data.hasOwnProperty("tx_frequency")) {
2298+
html += "<div><b>TX Frequency:&nbsp;</b>" + data.tx_frequency + " MHz</div>";
2299+
} else if (data.hasOwnProperty("frequency")) {
2300+
html += "<div><b>Frequency:&nbsp;</b>" + data.frequency + " MHz</div>";
2301+
};
2302+
if (data.hasOwnProperty("humidity")) {
2303+
html += "<div><b>Relative Humidity:&nbsp;</b>" + data.humidity + " %</div>";
2304+
};
2305+
if (data.hasOwnProperty("manufacturer")) {
2306+
html += "<div><b>Manufacturer:&nbsp;</b>" + data.manufacturer + "</div>";
2307+
};
2308+
if (data.hasOwnProperty("sats")) {
2309+
html += "<div><b>Satellites:&nbsp;</b>" + data.sats + "</div>";
2310+
};
2311+
if (data.hasOwnProperty("temp")) {
2312+
html += "<div><b>Temperature External:&nbsp;</b>" + data.temp + "°C</div>";
2313+
};
2314+
if (data.hasOwnProperty("subtype")) {
2315+
html += "<div><b>Sonde Type:&nbsp;</b>" + data.subtype + "</div>";
2316+
} else if (data.hasOwnProperty("type")) {
2317+
html += "<div><b>Sonde Type:&nbsp;</b>" + data.type + "</div>";
2318+
};
2319+
if (data.hasOwnProperty("pressure")) {
2320+
html += "<div><b>Pressure:&nbsp;</b>" + data.pressure + " Pa</div>";
2321+
};
2322+
if (data.hasOwnProperty("xdata")) {
2323+
html += "<div><b>XDATA:&nbsp;</b>" + data.xdata + "</div>";
2324+
};
22342325

2235-
html += "<hr style='margin:0px;margin-top:5px'>";
2236-
html += "<div style='font-size:11px;'>"
2326+
html += "<hr style='margin:0px;margin-top:5px'>";
2327+
html += "<div style='font-size:11px;'>"
22372328

2238-
var callsign_list = [];
2329+
var callsign_list = [];
22392330

2240-
for (var i = 0; i < data.uploaders.length; i++) {
2241-
_new_call = data.uploaders[i].uploader_callsign;
2242-
tempFields = [];
2243-
if(data.uploaders[i].hasOwnProperty('snr')) {
2244-
tempFields.push(data.uploaders[i].snr.toFixed(0) + " dB");
2245-
}
2246-
if(data.uploaders[i].hasOwnProperty('rssi')) {
2247-
tempFields.push(data.uploaders[i].rssi.toFixed(0) + " dBm");
2248-
}
2249-
if(data.uploaders[i].hasOwnProperty('frequency')) {
2250-
tempFields.push(data.uploaders[i].frequency + " MHz");
2251-
}
2252-
if(tempFields.length > 0) {
2253-
_new_call += " (" + tempFields.join(", ") + ")";
2254-
}
2255-
callsign_list.push(_new_call); // catch cases where there are no fields
2331+
for (var i = 0; i < data.uploaders.length; i++) {
2332+
_new_call = data.uploaders[i].uploader_callsign;
2333+
tempFields = [];
2334+
if(data.uploaders[i].hasOwnProperty('snr')) {
2335+
tempFields.push(data.uploaders[i].snr.toFixed(0) + " dB");
2336+
}
2337+
if(data.uploaders[i].hasOwnProperty('rssi')) {
2338+
tempFields.push(data.uploaders[i].rssi.toFixed(0) + " dBm");
2339+
}
2340+
if(data.uploaders[i].hasOwnProperty('frequency')) {
2341+
tempFields.push(data.uploaders[i].frequency + " MHz");
2342+
}
2343+
if(tempFields.length > 0) {
2344+
_new_call += " (" + tempFields.join(", ") + ")";
22562345
}
2346+
callsign_list.push(_new_call); // catch cases where there are no fields
2347+
}
22572348

2258-
callsign_list = callsign_list.join("<br /> ");
2349+
callsign_list = callsign_list.join("<br /> ");
22592350

2260-
html += callsign_list + "</div>";
2351+
html += callsign_list + "</div>";
22612352

2262-
div.innerHTML = html;
2353+
div.innerHTML = html;
22632354

2264-
mapInfoBox.setContent(div);
2265-
mapInfoBox.openOn(map);
2355+
mapInfoBox.setContent(div);
2356+
mapInfoBox.openOn(map);
22662357

2267-
setTimeout(function() {
2268-
div.parentElement.style.overflow = "";
2269-
div.parentElement.style.overflowWrap = "break-word";
2270-
}, 16);
2271-
});
2272-
};
2358+
setTimeout(function() {
2359+
div.parentElement.style.overflow = "";
2360+
div.parentElement.style.overflowWrap = "break-word";
2361+
}, 16);
2362+
}
22732363

22742364
function mapInfoBox_handle_prediction(event) {
22752365
var data = event.target.pdata;

0 commit comments

Comments
 (0)