From ad48e6f825d3194cef5b523cee9ff233fc7df293 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Tue, 3 Mar 2015 17:13:52 +0100 Subject: [PATCH] Phi: use new pagedPathForHistory for the Map --- webgui/main.js | 2 +- webgui/topics/Map.js | 34 +++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/webgui/main.js b/webgui/main.js index f28857f79..459c99fd6 100644 --- a/webgui/main.js +++ b/webgui/main.js @@ -405,6 +405,6 @@ require([ }; - ko.applyBindings(new PhiViewModel()); + ko.applyBindings(new PhiViewModel(),document.getElementById('wrapper')); }); diff --git a/webgui/topics/Map.js b/webgui/topics/Map.js index 3431f4a13..f26c826c7 100644 --- a/webgui/topics/Map.js +++ b/webgui/topics/Map.js @@ -6,16 +6,43 @@ define([ var self = this; var trackLayer = new L.GeoJSON(null, {}); + + trackLayer.maxTrackPoints = 1000; + + trackLayer.track = { + "type" : "Feature", + "geometry" : { + "type" : "LineString", + "coordinates" : [] + }, + "properties" : { + "type" : "FlightHistory", + "last" : 0 + } + } + trackLayer.update = function(id) { var self = this; if (id != self.updateId) return; - var url = "/flighthistory/track.json"; + var url = "/flighthistory/track.json?count=" + self.maxTrackPoints + "&last=" + trackLayer.track.properties.last; var jqxhr = $.get(url).done(function(data) { self.clearLayers(); - self.addData(data); + Array.prototype.push.apply(trackLayer.track.geometry.coordinates, data.geometry.coordinates); + if (data.properties) { + trackLayer.track.properties.last = data.properties.last || 0; + } + self.addData(trackLayer.track); + + // update fast until we have all points + var updateDelay = data.geometry.coordinates.length < self.maxTrackPoints ? 120000 : 200; + + setTimeout(function() { + self.update(id) + }, updateDelay); + }).fail(function() { var r = confirm("Error loading flight history. Retry?"); if (!r) @@ -23,9 +50,6 @@ define([ }).always(function() { }); - setTimeout(function() { - self.update(id) - }, 10000); } trackLayer.updateId = 0;