diff --git a/js/tracker.js b/js/tracker.js index 38759fd..4f8f3c4 100644 --- a/js/tracker.js +++ b/js/tracker.js @@ -4091,7 +4091,7 @@ function updateChase(r) { response.positions.position = dataTemp; response.fetch_timestamp = Date.now(); if (response.positions.position.length > 0) { - update(response); + live_data_buffer.positions.position.push.apply(live_data_buffer.positions.position,response.positions.position) } } @@ -4498,101 +4498,85 @@ function update(response, none) { lastPPointer: lastPositions.positions.position, idx: 0, max: response.positions.position.length, - step: function(ctx) { - var draw_idx = -1; + run: function(ctx) { + while(ctx.idx < ctx.max){ + var draw_idx = -1; - var i = ctx.idx; - var max = i + 5000; - max = (max >= ctx.max) ? ctx.max : max; + var i = ctx.idx; + var max = i + 5000; + max = (max >= ctx.max) ? ctx.max : max; - for (; i < max ; i++) { - var row = ctx.positions[i]; + for (; i < max ; i++) { + var row = ctx.positions[i]; - // set the position based on the last record (oldest) returned from the server. Only provide minute accuracy to allow better hit rate with cloudfront - this_position_id = new Date(row.gps_time); + // set the position based on the last record (oldest) returned from the server. Only provide minute accuracy to allow better hit rate with cloudfront + this_position_id = new Date(row.gps_time); - if (new Date(position_id) < this_position_id || position_id == 0){ - if (new Date() > this_position_id) { - this_position_id.setSeconds(0) - this_position_id.setMilliseconds(0) - position_id = this_position_id.toISOString() + if (new Date(position_id) < this_position_id || position_id == 0){ + if (new Date() > this_position_id) { + this_position_id.setSeconds(0) + this_position_id.setMilliseconds(0) + position_id = this_position_id.toISOString() + } } - } - if (!row.picture) { - addPosition(row); - got_positions = true; + if (!row.picture) { + addPosition(row); + got_positions = true; + } } - } - ctx.idx = max; + ctx.idx = max; - if(ctx.idx < ctx.max) { - //setTimeout(function() { - ctx.step(ctx); - //}, 4); - } else { - ctx.list = Object.keys(vehicles); - //setTimeout(function() { - ctx.draw(ctx); - // }, 16); - } - }, - draw: function(ctx) { - if(ctx.list.length < 1) { - //setTimeout(function() { - ctx.end(ctx); - // }, 16); - return; } - // pop a callsign from the top - var vcallsign = ctx.list.shift(); - var vehicle = vehicles[vcallsign]; + ctx.list = Object.keys(vehicles); + + // draw loop + while(ctx.list.length >= 1){ + // pop a callsign from the top + var vcallsign = ctx.list.shift(); + var vehicle = vehicles[vcallsign]; - if(vehicle === undefined) return; + if(vehicle === undefined) return; - if(vehicle.updated) { - updatePolyline(vcallsign); - - updateVehicleInfo(vcallsign, vehicle.curr_position); + if(vehicle.updated) { + updatePolyline(vcallsign); + + updateVehicleInfo(vcallsign, vehicle.curr_position); - // remember last position for each vehicle - ctx.lastPPointer.push(vehicle.curr_position); + // remember last position for each vehicle + ctx.lastPPointer.push(vehicle.curr_position); - if(listScroll) listScroll.refresh(); - if(zoomed_in && follow_vehicle == vcallsign && !manual_pan) panTo(follow_vehicle); - if (follow_vehicle == vcallsign) { - update_lookangles(follow_vehicle); - drawLOSPaths(vcallsign); + if(listScroll) listScroll.refresh(); + if(zoomed_in && follow_vehicle == vcallsign && !manual_pan) panTo(follow_vehicle); + if (follow_vehicle == vcallsign) { + update_lookangles(follow_vehicle); + drawLOSPaths(vcallsign); + } } } + // ctx.end - // step to the next callsign - // setTimeout(function() { - ctx.draw(ctx); - //}, 16); - }, - end: function(ctx) { + // update graph is current vehicles is followed + if(follow_vehicle !== null && + vehicles.hasOwnProperty(follow_vehicle) && + vehicles[follow_vehicle].graph_data_updated) updateGraph(follow_vehicle, false); - // update graph is current vehicles is followed - if(follow_vehicle !== null && - vehicles.hasOwnProperty(follow_vehicle) && - vehicles[follow_vehicle].graph_data_updated) updateGraph(follow_vehicle, false); - - if (got_positions && !zoomed_in && Object.keys(vehicles).length) { + if (got_positions && !zoomed_in && Object.keys(vehicles).length) { if (vehicles.hasOwnProperty(wvar.query) && wvar.query !== "") { zoom_on_payload(); } // TODO: Zoom to geolocation position - } + } + + if(periodical_predictions === null) refreshPredictions(); + }, - if(periodical_predictions === null) refreshPredictions(); - } }; - ctx_init.step(ctx_init); + ctx_init.run(ctx_init); } function zoom_on_payload() {