From 6ddefbf98ebff13592de1d87a3bfc2796ac06d84 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Thu, 25 Jul 2013 02:51:54 +0200 Subject: [PATCH] reset upload status when starting upload; load track in reverse order and once we have the most recent point in async mode so that loading app with long track is sped up --- js/map.js | 33 ++++++++++++++++++++++++--------- js/ui.js | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/js/map.js b/js/map.js index 41a413d..3cc00c5 100644 --- a/js/map.js +++ b/js/map.js @@ -162,15 +162,26 @@ function loadPrefs(aEvent) { gAction.dispatchEvent(throwEv); }); gWaitCounter++; - gTrackStore.getList(function(aTPoints) { - if (gDebug) - console.log(aTPoints.length + " points loaded."); - if (aTPoints.length) { - gTrack = aTPoints; + var trackLoadStarted = false; + gTrackStore.getListStepped(function(aTPoint) { + if (aTPoint) { + // Add in front and return new length. + var tracklen = gTrack.unshift(aTPoint); + // Redraw track every 100 values (initial paint will do first anyhow). + if (tracklen % 100 == 0) + drawTrack(); + } + else { + // Last point received. + drawTrack(); + } + if (!trackLoadStarted) { + // We have the most recent point, if present, rest will load async. + trackLoadStarted = true; + gWaitCounter--; + var throwEv = new CustomEvent("prefs-step"); + gAction.dispatchEvent(throwEv); } - gWaitCounter--; - var throwEv = new CustomEvent("prefs-step"); - gAction.dispatchEvent(throwEv); }); } } @@ -355,6 +366,10 @@ function drawMap(aPixels, aOverdraw) { } } } + drawTrack(); +} + +function drawTrack() { gLastDrawnPoint = null; gCurPosMapCache = undefined; gTrackContext.clearRect(0, 0, gTrackCanvas.width, gTrackCanvas.height); @@ -756,7 +771,7 @@ function endTracking() { function clearTrack() { gTrack = []; gTrackStore.clear(); - drawMap({left: 0, right: 0, top: 0, bottom: 0}); + drawTrack(); } var gTileService = { diff --git a/js/ui.js b/js/ui.js index 560f48c..f0d2b18 100644 --- a/js/ui.js +++ b/js/ui.js @@ -307,11 +307,19 @@ function saveTrackDump() { } function uploadTrack() { + // Hide all areas in the dialog. var dia = document.getElementById("dialogArea"); var areas = dia.children; for (var i = 0; i <= areas.length - 1; i++) { areas[i].style.display = "none"; } + // Reset all the fields in the status area. + document.getElementById("uploadStatusCloseButton").disabled = true; + document.getElementById("uploadInProgress").style.display = "block"; + document.getElementById("uploadSuccess").style.display = "none"; + document.getElementById("uploadErrorMsg").textContent = ""; + document.getElementById("uploadError").style.display = "none"; + // Now show the status area. document.getElementById("uploadStatus").style.display = "block"; // See http://wiki.openstreetmap.org/wiki/Api06#Uploading_traces @@ -445,6 +453,24 @@ var gTrackStore = { } }, + getListStepped: function(aCallback) { + if (!mainDB) + return; + var transaction = mainDB.transaction([this.objStore]); + var objStore = transaction.objectStore(this.objStore); + // Use cursor in reverse direction (so we get the most recent position first) + objStore.openCursor(null, "prev").onsuccess = function(event) { + var cursor = event.target.result; + if (cursor) { + aCallback(cursor.value); + cursor.continue(); + } + else { + aCallback(null); + } + }; + }, + push: function(aValue, aCallback) { if (!mainDB) return; -- 2.35.3