-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsatvisibility.js
50 lines (45 loc) · 1.99 KB
/
satvisibility.js
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
function isVisualPass(sat_id, latitude, longtitude) {
var result = false;
$.ajax({
data: {cmd:"visual",
id: sat_id,
obs_lat: latitude,
obs_lng: longtitude,
obs_alt:"0",
days:"1",
min:"180"},
url: '../handle_api_requests.php',
method: 'POST', // or GET
async: false,
success: function(msg) {
var response = JSON.parse(msg);
console.log(response);
if (response.info.passescount>0) {
for (var i=0; i<response.info.passescount; i++) {
var start = response.passes[i].startUTC;
var end = response.passes[i].endUTC;
var now = math.floor(Date.now()/1000);
result |= (now-start>0 && end-now>0) || (start-now>0 && start-now<300); //is live or starts soon (5min)
}
} else {
result = false;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("Status: " + textStatus + "Error: " + errorThrown);
result = false;
}
});
return result;
}
function parseURL() {
var url = document.location.href;
var params = url.split("?")[1].split("&");
var data = {};
var tmp;
for (var i = 0, l = params.length; i < l; i++) {
tmp = params[i].split('=');
data[tmp[0]] = tmp[1];
}
return data;
}