Skip to content

Commit b05509c

Browse files
gently load vehicles on start
1 parent acd87b2 commit b05509c

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed

cache.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CACHE MANIFEST
2-
# version 157
2+
# version 158
33

44
# gogole maps files
55
http://maps.google.com/maps/api/js?v=3.10&sensor=false&key=AIzaSyCOqkcNey4CCyG4X0X5qxHAhCgD8g5DwXg

js/tracker.js

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ var Z_CAR = 11;
4545
var Z_SHADOW = 12;
4646
var Z_PAYLOAD = 13;
4747

48+
var bootstrapped = false;
49+
var zoom_timer;
50+
4851
// localStorage vars
4952
var ls_receivers = false;
5053
var ls_pred = false;
@@ -640,7 +643,11 @@ function addPosition(position) {
640643
optimized: false,
641644
zIndex: Z_PAYLOAD,
642645
position: point,
643-
icon: image_src,
646+
icon: {
647+
url: image_src,
648+
size: new google.maps.Size(46,84),
649+
scaledSize: new google.maps.Size(46,84)
650+
},
644651
title: position.vehicle,
645652
});
646653
marker.shadow = marker_shadow;
@@ -1129,6 +1136,7 @@ function refreshUI() {
11291136
}
11301137

11311138
var status = "";
1139+
var bs_idx = 0;
11321140

11331141
function update(response) {
11341142
if (response == null || !response.positions) {
@@ -1156,22 +1164,44 @@ function update(response) {
11561164
var lastPPointer = lastPositions.positions.position;
11571165

11581166
for (var i = 0, ii = vehicle_names.length; i < ii; i++) {
1159-
updatePolyline(i);
1160-
updateVehicleInfo(i, vehicles[i].curr_position);
1167+
if(!bootstrapped) {
1168+
setTimeout(function() {
1169+
var idx = bs_idx;
1170+
bs_idx += 1;
1171+
updatePolyline(idx);
1172+
updateVehicleInfo(idx, vehicles[idx].curr_position);
1173+
1174+
if(listScroll) listScroll.refresh();
1175+
1176+
// update the altitude profile, only if its a balloon
1177+
if(vehicles[idx].vehicle_type != "car") {
1178+
var graph_src = graph_url.replace("{AA}",vehicles[idx].alt_max); // top range, buttom is always 0
1179+
graph_src += GChartEncodeData(vehicles[idx].alt_list, vehicles[i].alt_max); // encode datapoint to preserve bandwith
1180+
1181+
// update img element
1182+
$('.vehicle'+idx+' .graph').attr('src', graph_src);
1183+
}
1184+
}, 400*i);
1185+
} else {
1186+
updatePolyline(i);
1187+
updateVehicleInfo(i, vehicles[i].curr_position);
11611188

1162-
// update the altitude profile, only if its a balloon
1163-
if(vehicles[i].vehicle_type != "car") {
1164-
var graph_src = graph_url.replace("{AA}",vehicles[i].alt_max); // top range, buttom is always 0
1165-
graph_src += GChartEncodeData(vehicles[i].alt_list, vehicles[i].alt_max); // encode datapoint to preserve bandwith
1189+
// update the altitude profile, only if its a balloon
1190+
if(vehicles[i].vehicle_type != "car") {
1191+
var graph_src = graph_url.replace("{AA}",vehicles[i].alt_max); // top range, buttom is always 0
1192+
graph_src += GChartEncodeData(vehicles[i].alt_list, vehicles[i].alt_max); // encode datapoint to preserve bandwith
11661193

1167-
// update img element
1168-
$('.vehicle'+i+' .graph').attr('src', graph_src);
1169-
}
1194+
// update img element
1195+
$('.vehicle'+i+' .graph').attr('src', graph_src);
1196+
}
11701197

1171-
// remember last position for each vehicle
1172-
lastPPointer.push(vehicles[i].curr_position);
1198+
// remember last position for each vehicle
1199+
lastPPointer.push(vehicles[i].curr_position);
1200+
}
11731201
}
11741202

1203+
bootstrapped = true;
1204+
11751205
// update graph is current vehicles is followed
11761206
if(follow_vehicle != -1 && vehicles[follow_vehicle].graph_data_updated) updateGraph(follow_vehicle, false);
11771207

@@ -1187,6 +1217,20 @@ function update(response) {
11871217
if (got_positions && !zoomed_in) {
11881218
if(vehicles.length == 0) return;
11891219

1220+
zoom_timer = setInterval(function() {
1221+
if(bootstrapped && bs_idx+1 == vehicle_names.length) {
1222+
zoom_on_payload();
1223+
clearInterval(zoom_timer);
1224+
}
1225+
},100);
1226+
1227+
zoomed_in = true;
1228+
}
1229+
1230+
if(listScroll) listScroll.refresh();
1231+
}
1232+
1233+
function zoom_on_payload() {
11901234
// find a the first balloon
11911235
var i = -1, ii = vehicles.length;
11921236
while(++i < ii && !vehicles[i].marker_shadow);
@@ -1214,11 +1258,6 @@ function update(response) {
12141258
// scroll list to the expanded element
12151259
listScroll.refresh();
12161260
listScroll.scrollToElement('.portrait .vehicle'+i);
1217-
1218-
zoomed_in = true;
1219-
}
1220-
1221-
if(listScroll) listScroll.refresh();
12221261
}
12231262

12241263
function isInt(n) {

0 commit comments

Comments
 (0)