Skip to content

Commit f734407

Browse files
author
xss
committed
Flattern ctx loop. Move chase car to buffer
1 parent 20a9448 commit f734407

File tree

1 file changed

+53
-69
lines changed

1 file changed

+53
-69
lines changed

js/tracker.js

Lines changed: 53 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4091,7 +4091,7 @@ function updateChase(r) {
40914091
response.positions.position = dataTemp;
40924092
response.fetch_timestamp = Date.now();
40934093
if (response.positions.position.length > 0) {
4094-
update(response);
4094+
live_data_buffer.positions.position.push.apply(live_data_buffer.positions.position,response.positions.position)
40954095
}
40964096
}
40974097

@@ -4498,101 +4498,85 @@ function update(response, none) {
44984498
lastPPointer: lastPositions.positions.position,
44994499
idx: 0,
45004500
max: response.positions.position.length,
4501-
step: function(ctx) {
4502-
var draw_idx = -1;
4501+
run: function(ctx) {
4502+
while(ctx.idx < ctx.max){
4503+
var draw_idx = -1;
45034504

4504-
var i = ctx.idx;
4505-
var max = i + 5000;
4506-
max = (max >= ctx.max) ? ctx.max : max;
4505+
var i = ctx.idx;
4506+
var max = i + 5000;
4507+
max = (max >= ctx.max) ? ctx.max : max;
45074508

4508-
for (; i < max ; i++) {
4509-
var row = ctx.positions[i];
4509+
for (; i < max ; i++) {
4510+
var row = ctx.positions[i];
45104511

4511-
// set the position based on the last record (oldest) returned from the server. Only provide minute accuracy to allow better hit rate with cloudfront
4512-
this_position_id = new Date(row.gps_time);
4512+
// set the position based on the last record (oldest) returned from the server. Only provide minute accuracy to allow better hit rate with cloudfront
4513+
this_position_id = new Date(row.gps_time);
45134514

4514-
if (new Date(position_id) < this_position_id || position_id == 0){
4515-
if (new Date() > this_position_id) {
4516-
this_position_id.setSeconds(0)
4517-
this_position_id.setMilliseconds(0)
4518-
position_id = this_position_id.toISOString()
4515+
if (new Date(position_id) < this_position_id || position_id == 0){
4516+
if (new Date() > this_position_id) {
4517+
this_position_id.setSeconds(0)
4518+
this_position_id.setMilliseconds(0)
4519+
position_id = this_position_id.toISOString()
4520+
}
45194521
}
4520-
}
45214522

4522-
if (!row.picture) {
4523-
addPosition(row);
4524-
got_positions = true;
4523+
if (!row.picture) {
4524+
addPosition(row);
4525+
got_positions = true;
4526+
}
45254527
}
4526-
}
45274528

4528-
ctx.idx = max;
4529+
ctx.idx = max;
45294530

4530-
if(ctx.idx < ctx.max) {
4531-
//setTimeout(function() {
4532-
ctx.step(ctx);
4533-
//}, 4);
4534-
} else {
4535-
ctx.list = Object.keys(vehicles);
4536-
//setTimeout(function() {
4537-
ctx.draw(ctx);
4538-
// }, 16);
4539-
}
4540-
},
4541-
draw: function(ctx) {
4542-
if(ctx.list.length < 1) {
4543-
//setTimeout(function() {
4544-
ctx.end(ctx);
4545-
// }, 16);
4546-
return;
45474531
}
45484532

4549-
// pop a callsign from the top
4550-
var vcallsign = ctx.list.shift();
4551-
var vehicle = vehicles[vcallsign];
4533+
ctx.list = Object.keys(vehicles);
4534+
4535+
// draw loop
4536+
while(ctx.list.length >= 1){
4537+
// pop a callsign from the top
4538+
var vcallsign = ctx.list.shift();
4539+
var vehicle = vehicles[vcallsign];
45524540

4553-
if(vehicle === undefined) return;
4541+
if(vehicle === undefined) return;
45544542

4555-
if(vehicle.updated) {
4556-
updatePolyline(vcallsign);
4557-
4558-
updateVehicleInfo(vcallsign, vehicle.curr_position);
4543+
if(vehicle.updated) {
4544+
updatePolyline(vcallsign);
4545+
4546+
updateVehicleInfo(vcallsign, vehicle.curr_position);
45594547

4560-
// remember last position for each vehicle
4561-
ctx.lastPPointer.push(vehicle.curr_position);
4548+
// remember last position for each vehicle
4549+
ctx.lastPPointer.push(vehicle.curr_position);
45624550

4563-
if(listScroll) listScroll.refresh();
4564-
if(zoomed_in && follow_vehicle == vcallsign && !manual_pan) panTo(follow_vehicle);
4565-
if (follow_vehicle == vcallsign) {
4566-
update_lookangles(follow_vehicle);
4567-
drawLOSPaths(vcallsign);
4551+
if(listScroll) listScroll.refresh();
4552+
if(zoomed_in && follow_vehicle == vcallsign && !manual_pan) panTo(follow_vehicle);
4553+
if (follow_vehicle == vcallsign) {
4554+
update_lookangles(follow_vehicle);
4555+
drawLOSPaths(vcallsign);
4556+
}
45684557
}
45694558
}
4559+
// ctx.end
45704560

4571-
// step to the next callsign
4572-
// setTimeout(function() {
4573-
ctx.draw(ctx);
4574-
//}, 16);
4575-
},
4576-
end: function(ctx) {
4561+
// update graph is current vehicles is followed
4562+
if(follow_vehicle !== null &&
4563+
vehicles.hasOwnProperty(follow_vehicle) &&
4564+
vehicles[follow_vehicle].graph_data_updated) updateGraph(follow_vehicle, false);
45774565

4578-
// update graph is current vehicles is followed
4579-
if(follow_vehicle !== null &&
4580-
vehicles.hasOwnProperty(follow_vehicle) &&
4581-
vehicles[follow_vehicle].graph_data_updated) updateGraph(follow_vehicle, false);
4582-
4583-
if (got_positions && !zoomed_in && Object.keys(vehicles).length) {
4566+
if (got_positions && !zoomed_in && Object.keys(vehicles).length) {
45844567
if (vehicles.hasOwnProperty(wvar.query) && wvar.query !== "") {
45854568
zoom_on_payload();
45864569
}
45874570
// TODO: Zoom to geolocation position
45884571

4589-
}
4572+
}
4573+
4574+
if(periodical_predictions === null) refreshPredictions();
4575+
},
45904576

4591-
if(periodical_predictions === null) refreshPredictions();
4592-
}
45934577
};
45944578

4595-
ctx_init.step(ctx_init);
4579+
ctx_init.run(ctx_init);
45964580
}
45974581

45984582
function zoom_on_payload() {

0 commit comments

Comments
 (0)