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);
});
}
}
}
}
}
+ drawTrack();
+}
+
+function drawTrack() {
gLastDrawnPoint = null;
gCurPosMapCache = undefined;
gTrackContext.clearRect(0, 0, gTrackCanvas.width, gTrackCanvas.height);
function clearTrack() {
gTrack = [];
gTrackStore.clear();
- drawMap({left: 0, right: 0, top: 0, bottom: 0});
+ drawTrack();
}
var gTileService = {
}
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
}
},
+ 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;