Skip to content

Commit 9111808

Browse files
make path infobox available for habitat flights
1 parent 00a12f3 commit 9111808

File tree

1 file changed

+64
-38
lines changed

1 file changed

+64
-38
lines changed

js/tracker.js

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,25 @@ var mapInfoBox_handle_path = function(event) {
13011301
};
13021302

13031303
var mapInfoBox_handle_path_fetch = function(id,vehicle) {
1304-
$.getJSON("http://spacenear.us/tracker/datanew.php?mode=single&format=json&position_id=" + id, function(data) {
1304+
var ishabitat = id.length == 64
1305+
1306+
if(ishabitat) {
1307+
var url = 'http://habitat.habhub.org/habitat/' + id;
1308+
} else {
1309+
var url = "http://spacenear.us/tracker/datanew.php?mode=single&format=json&position_id=" + id;
1310+
}
1311+
1312+
$.getJSON(url, function(data) {
1313+
if(ishabitat) {
1314+
var encap = {positions: { position: [] }};
1315+
1316+
if(!data.hasOwnProperty('error')) {
1317+
data._id = data._id.substring(58);
1318+
encap.positions.position.push(habitat_doc_to_snus(data));
1319+
data = encap;
1320+
}
1321+
}
1322+
13051323
if('positions' in data && data.positions.position.length === 0) {
13061324
mapInfoBox.setContent("not found");
13071325
mapInfoBox.open(map);
@@ -2333,48 +2351,13 @@ function habitat_translation_layer(json_result, prefix) {
23332351
result.fetch_timestamp = Date.now();
23342352
$("#stTimer").attr("data-timestamp", result.fetch_timestamp);
23352353

2336-
var blacklist = {
2337-
altitude: 1,
2338-
date: 1,
2339-
latitude: 1,
2340-
longitude: 1,
2341-
payload: 1,
2342-
sentence_id: 1,
2343-
time: 1,
2344-
};
2345-
23462354
for(var i in json_result) {
23472355
var doc = json_result[i].doc;
2348-
if(doc.data.latitude === 0 && doc.data.longitude === 0) continue;
2349-
2350-
var row = {
2351-
'position_id': 0,
2352-
'vehicle': prefix + doc.data.payload,
2353-
'server_time': doc.data._parsed.time_parsed,
2354-
'sequence': doc.data.sentence_id,
2355-
'gps_lat': doc.data.latitude,
2356-
'gps_lon': doc.data.longitude,
2357-
'gps_alt': doc.data.altitude,
2358-
'callsign': "HABITAT ARCHIVE",
2359-
'data': {}
2360-
};
2361-
2362-
try {
2363-
row.gps_time = "20" + doc.data.date.replace(/([0-9]{2})/g, "$1-") + doc.data.time;
2364-
} catch (e) {
2365-
row.gps_time = row.server_time;
2366-
}
23672356

2368-
// move all other properties as data
2369-
for(var x in doc.data) {
2370-
// skip internal and reserved vars
2371-
if(x[0] == '_' || blacklist.hasOwnProperty(x)) continue;
2357+
if(doc.data.latitude === 0 && doc.data.longitude === 0) continue;
23722358

2373-
row.data[x] = doc.data[x];
2374-
}
2375-
row.data = JSON.stringify(row.data);
2359+
var row = habitat_doc_to_snus(doc, prefix);
23762360

2377-
// append the packet
23782361
result.positions.position.push(row);
23792362
}
23802363

@@ -2386,6 +2369,49 @@ function habitat_translation_layer(json_result, prefix) {
23862369
}, 500);
23872370
}
23882371

2372+
var habitat_field_blacklist = {
2373+
altitude: 1,
2374+
date: 1,
2375+
latitude: 1,
2376+
longitude: 1,
2377+
payload: 1,
2378+
sentence_id: 1,
2379+
time: 1,
2380+
};
2381+
2382+
function habitat_doc_to_snus(doc, prefix) {
2383+
prefix = prefix || '';
2384+
2385+
var row = {
2386+
'position_id': doc._id,
2387+
'vehicle': prefix + doc.data.payload,
2388+
'server_time': doc.data._parsed.time_parsed,
2389+
'sequence': doc.data.sentence_id,
2390+
'gps_lat': doc.data.latitude,
2391+
'gps_lon': doc.data.longitude,
2392+
'gps_alt': doc.data.altitude,
2393+
'callsign': "HABITAT ARCHIVE",
2394+
'data': {}
2395+
};
2396+
2397+
try {
2398+
row.gps_time = "20" + doc.data.date.replace(/([0-9]{2})/g, "$1-") + doc.data.time;
2399+
} catch (e) {
2400+
row.gps_time = row.server_time;
2401+
}
2402+
2403+
// move all other properties as data
2404+
for(var x in doc.data) {
2405+
// skip internal and reserved vars
2406+
if(x[0] == '_' || habitat_field_blacklist.hasOwnProperty(x)) continue;
2407+
2408+
row.data[x] = doc.data[x];
2409+
}
2410+
row.data = JSON.stringify(row.data);
2411+
2412+
return row;
2413+
}
2414+
23892415
var habitat_payload_step_data;
23902416

23912417
function habitat_payload_step(remove_current) {

0 commit comments

Comments
 (0)