Skip to content

Commit 937009e

Browse files
path infobox will show all info for that position
* clicking anywhere on the path will snap to the nearest datum and brining the all data about that position. Including the existing duration and distance.
1 parent 061235a commit 937009e

File tree

3 files changed

+116
-12
lines changed

3 files changed

+116
-12
lines changed

cache.manifest-dev

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CACHE MANIFEST
22
# version {VERSION}
33

44
# gogole maps files
5-
http://maps.gstatic.com/cat_js/maps-api-v3/api/js/16/16/%7Bmain,common,controls,ga,geometry,infowindow,kml,map,marker,onion,overlay,poly,stats,util,weather,weather_impl%7D.js
5+
http://maps.gstatic.com/cat_js/maps-api-v3/api/js/17/18/%7Bmain,common,controls,ga,geometry,infowindow,kml,map,marker,onion,overlay,poly,stats,util,weather,weather_impl%7D.js
66
http://fonts.googleapis.com/css?family=Roboto:300,400,500,700
77
http://maps.gstatic.com/mapfiles/undo_poly.png
88
http://maps.gstatic.com/mapfiles/mv/imgs8.png
@@ -58,6 +58,7 @@ img/markers/target-orange.png
5858
img/markers/target-purple.png
5959
img/markers/target-red.png
6060
img/markers/target-yellow.png
61+
img/hab-spinner.gif
6162
css/mobile.css
6263
js/mobile.js
6364
js/init_plot.js

img/hab-spinner.gif

6.58 KB
Loading

js/tracker.js

Lines changed: 114 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ function load() {
374374

375375
position_id = 0;
376376

377+
mapInfoBox.close();
378+
377379
// clear vehicles
378380
var callsign;
379381
for(callsign in vehicles) {
@@ -489,7 +491,7 @@ function guess_name(key) {
489491
return title_case(key.replace(/_/g, " "));
490492
}
491493

492-
function habitat_data(jsondata) {
494+
function habitat_data(jsondata, alternative) {
493495
var keys = {
494496
"ascentrate": "Ascent Rate",
495497
"battery_percent": "Battery",
@@ -570,7 +572,11 @@ function habitat_data(jsondata) {
570572
if (suffixes[k] !== undefined)
571573
suffix = suffixes[k];
572574

573-
output += "<dt>" + v + suffix + "</dt><dd>" + name + "</dd>";
575+
if(typeof alternative == 'boolean' && alternative) {
576+
output += "<div><b>" + name + ":&nbsp;</b>" + v + suffix + "</div>";
577+
} else {
578+
output += "<dt>" + v + suffix + "</dt><dd>" + name + "</dd>";
579+
}
574580
}
575581
return output;
576582
}
@@ -714,9 +720,9 @@ function formatDate(date,utc) {
714720

715721
if(typeof utc != "undefined") {
716722
z = date.getTimezoneOffset() / -60;
717-
return a+'-'+b+'-'+c+' '+e+':'+f+':'+g+" UTC"+((z<0)?"-":"+")+z;
723+
return a+'-'+b+'-'+c+'&nbsp;'+e+':'+f+':'+g+"&nbsp;UTC"+((z<0)?"-":"+")+z;
718724
} else {
719-
return a+'-'+b+'-'+c+' '+e+':'+f+':'+g;
725+
return a+'-'+b+'-'+c+'&nbsp;'+e+':'+f+':'+g;
720726
}
721727
}
722728

@@ -934,7 +940,7 @@ function redrawPrediction(vcallsign) {
934940
clickable: true,
935941
draggable: false,
936942
});
937-
google.maps.event.addListener(vehicle.prediction_polyline, 'click', mapInfoBox_handle_path);
943+
google.maps.event.addListener(vehicle.prediction_polyline, 'click', mapInfoBox_handle_prediction_path);
938944
}
939945

940946
vehicle.prediction_polyline.path_length = path_length;
@@ -1093,24 +1099,118 @@ function drawAltitudeProfile(c1, c2, series, alt_max) {
10931099
}
10941100

10951101
// infobox
1096-
var mapInfoBox = new google.maps.InfoWindow();
1102+
var mapInfoBox = new google.maps.InfoWindow({
1103+
maxWidth: 260
1104+
});
10971105

1098-
var mapInfoBox_handle_path = function(event) {
1099-
var value = ("path_length" in this) ? this.path_length : this.vehicle.path_length;
1106+
var mapInfoBox_handle_prediction_path = function(event) {
1107+
var value = this.path_length;
11001108

11011109
if(offline.get('opt_imperial')) {
11021110
value = Math.round(value*0.000621371192) + " miles";
11031111
} else {
11041112
value = Math.round(value/10)/100 + " km";
11051113
}
11061114

1107-
var duration = ("vehicle" in this) ? "\n<b>Duration:</b> " + format_time_friendly(this.vehicle.start_time, convert_time(this.vehicle.curr_position.gps_time)) : '';
1108-
1109-
mapInfoBox.setContent("<pre><b>Length:</b> " + value + duration + "</pre>");
1115+
mapInfoBox.setContent("<pre><b>Length:</b> " + value + "</pre>");
11101116
mapInfoBox.setPosition(event.latLng);
11111117
mapInfoBox.open(map);
11121118
};
11131119

1120+
var mapInfoBox_handle_path = function(event) {
1121+
var vehicle = this.vehicle;
1122+
var target = event.latLng;
1123+
var p = vehicle.positions;
1124+
1125+
var p1_dist = 0;
1126+
var p2_dist = google.maps.geometry.spherical.computeDistanceBetween(p[0], target);
1127+
1128+
var mindiff = Number.MAX_VALUE;
1129+
var minidx = 0;
1130+
var dist, diff;
1131+
1132+
// find the closest existing point to snap to
1133+
for(var i = 1, ii = p.length; i < ii; i++ ) {
1134+
p1_dist = p2_dist;
1135+
p2_dist = google.maps.geometry.spherical.computeDistanceBetween(p[i], target);
1136+
dist = google.maps.geometry.spherical.computeDistanceBetween(p[i], p[i-1]);
1137+
diff = Math.abs(dist - (p1_dist + p2_dist));
1138+
1139+
if(diff >= 0 && mindiff > diff) {
1140+
mindiff = diff;
1141+
minidx = i;
1142+
}
1143+
}
1144+
1145+
p1_dist = google.maps.geometry.spherical.computeDistanceBetween(p[minidx-1], target);
1146+
p2_dist = google.maps.geometry.spherical.computeDistanceBetween(p[minidx], target);
1147+
1148+
var point = (p1_dist < p2_dist) ? p[minidx-1] : p[minidx];
1149+
var id = (p1_dist < p2_dist) ? vehicle.positions_ids[minidx-1] : vehicle.positions_ids[minidx];
1150+
1151+
mapInfoBox.setContent("<img style='width:18px;height:18px' src='img/hab-spinner.gif' />");
1152+
mapInfoBox.setPosition(point);
1153+
mapInfoBox.setMap(map);
1154+
mapInfoBox.open(map);
1155+
1156+
mapInfoBox_handle_path_fetch(id, vehicle);
1157+
};
1158+
1159+
var mapInfoBox_handle_path_fetch = function(id,vehicle) {
1160+
$.getJSON("http://spacenear.us/tracker/datanew.php?mode=single&format=json&position_id=" + id, function(data) {
1161+
data = data.positions.position[0];
1162+
1163+
if(data.length === 0) {
1164+
box.setContent("unable to find data");
1165+
return;
1166+
}
1167+
1168+
div = document.createElement('div');
1169+
1170+
html = "<div style='white-space: nowrap'>";
1171+
html += "<img style='position:absolute;top:-46px;left:-35px;width:46px;height:84px' src='"+vehicle.image_src+"' />";
1172+
html += "<div>"+data.vehicle+"<span style='float:right'>("+data.position_id+")</span></div><hr style='margin:0'>";
1173+
html += "<div><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(data.gps_lat, 6) + ',&nbsp;' + roundNumber(data.gps_lon, 6)+"</div>";
1174+
1175+
var imp = offline.get('opt_imperial');
1176+
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(data.gps_alt)) : parseInt(data.gps_alt)).toLocaleString("us");
1177+
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
1178+
1179+
html += "<div><b>Altitude:&nbsp;</b>"+text_alt+"</div>";
1180+
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(data.gps_time))+"</div>";
1181+
1182+
var value = vehicle.path_length;
1183+
1184+
html += "<div><b>Distance:&nbsp;</b>";
1185+
1186+
if(offline.get('opt_imperial')) {
1187+
html += Math.round(value*0.000621371192) + "mi";
1188+
} else {
1189+
html += Math.round(value/10)/100 + "&nbsp;km";
1190+
}
1191+
1192+
html += "</div>";
1193+
html += "<div><b>Duration:&nbsp;</b>" + format_time_friendly(vehicle.start_time, convert_time(vehicle.curr_position.gps_time)) + "</div>";
1194+
1195+
if(Object.keys(JSON.parse(data.data)).length) {
1196+
html += "<hr style='margin:0'>";
1197+
html += habitat_data(data.data, true);
1198+
}
1199+
1200+
html += "<hr style='margin:0'>";
1201+
html += "<div style='font-size:11px;'><b>Callsign(s):&nbsp;</b>"+data.callsign.replace(/,/g,', ')+"</div>";
1202+
1203+
div.innerHTML = html;
1204+
1205+
mapInfoBox.setContent(div);
1206+
1207+
setTimeout(function() {
1208+
div.parentElement.style.overflow = "";
1209+
div.parentElement.style.overflowWrap = "break-word";
1210+
}, 16);
1211+
});
1212+
};
1213+
11141214
var mapInfoBox_handle_prediction = function(event) {
11151215
var data = this.pdata;
11161216
var altitude;
@@ -1444,6 +1544,7 @@ function addPosition(position) {
14441544
num_positions: 0,
14451545
positions: [],
14461546
positions_ts: [],
1547+
positions_ids: [],
14471548
path_length: 0,
14481549
curr_position: position,
14491550
line: [],
@@ -1583,6 +1684,7 @@ function addPosition(position) {
15831684
} else {
15841685
vehicle.positions.push(new_latlng);
15851686
vehicle.positions_ts.push(new_ts);
1687+
vehicle.positions_ids.push(position.position_id);
15861688
vehicle.num_positions++;
15871689
}
15881690

@@ -1622,6 +1724,7 @@ function addPosition(position) {
16221724
// insert the new position into our arrays
16231725
vehicle.positions.splice(idx, 0, new_latlng);
16241726
vehicle.positions_ts.splice(idx, 0, new_ts);
1727+
vehicle.positions_ids.splice(idx, 0, position.position_id);
16251728
vehicle.num_positions++;
16261729

16271730
graphAddPosition(vcallsign, position);

0 commit comments

Comments
 (0)