- var loopCnt = 0;
- var getPersistentPrefs = function() {
- if (mainDB) {
- gWaitCounter++;
- gPrefs.get("position", function(aValue) {
- if (aValue) {
- gPos = aValue;
- gWaitCounter--;
- }
- });
- gWaitCounter++;
- gPrefs.get("center_map", function(aValue) {
- if (aValue === undefined)
- document.getElementById("centerCheckbox").checked = true;
- else
- document.getElementById("centerCheckbox").checked = aValue;
- setCentering(document.getElementById("centerCheckbox"));
- gWaitCounter--;
- });
- gWaitCounter++;
- gPrefs.get("tracking_enabled", function(aValue) {
- if (aValue === undefined)
- document.getElementById("trackCheckbox").checked = true;
- else
- document.getElementById("trackCheckbox").checked = aValue;
- gWaitCounter--;
- });
- gWaitCounter++;
- gTrackStore.getList(function(aTPoints) {
- if (gDebug)
- document.getElementById("debug").textContent = aTPoints.length + " points loaded.";
- if (aTPoints.length) {
- gTrack = aTPoints;
+ gAction.addEventListener("prefload-done", initGL, false);
+
+ console.log("map vars set, loading prefs...");
+ loadPrefs();
+}
+
+function loadPrefs(aEvent) {
+ if (aEvent && aEvent.type == "prefs-step") {
+ console.log("wait: " + gWaitCounter);
+ if (gWaitCounter == 0) {
+ gAction.removeEventListener(aEvent.type, loadPrefs, false);
+ gMapPrefsLoaded = true;
+ console.log("prefs loaded.");
+
+ gTrackCanvas.addEventListener("mouseup", mapEvHandler, false);
+ gTrackCanvas.addEventListener("mousemove", mapEvHandler, false);
+ gTrackCanvas.addEventListener("mousedown", mapEvHandler, false);
+ gTrackCanvas.addEventListener("mouseout", mapEvHandler, false);
+
+ gTrackCanvas.addEventListener("touchstart", mapEvHandler, false);
+ gTrackCanvas.addEventListener("touchmove", mapEvHandler, false);
+ gTrackCanvas.addEventListener("touchend", mapEvHandler, false);
+ gTrackCanvas.addEventListener("touchcancel", mapEvHandler, false);
+ gTrackCanvas.addEventListener("touchleave", mapEvHandler, false);
+
+ gTrackCanvas.addEventListener("wheel", mapEvHandler, false);
+
+ document.getElementById("body").addEventListener("keydown", mapEvHandler, false);
+
+ document.getElementById("copyright").innerHTML =
+ gMapStyles[gActiveMap].copyright;
+
+ gLoadingTile = new Image();
+ gLoadingTile.src = "style/loading.png";
+ gLoadingTile.onload = function() {
+ var throwEv = new CustomEvent("prefload-done");
+ gAction.dispatchEvent(throwEv);
+ };
+ }
+ }
+ else {
+ if (aEvent)
+ gAction.removeEventListener(aEvent.type, loadPrefs, false);
+ gAction.addEventListener("prefs-step", loadPrefs, false);
+ gWaitCounter++;
+ gPrefs.get("position", function(aValue) {
+ if (aValue) {
+ gPos = aValue;
+ }
+ gWaitCounter--;
+ var throwEv = new CustomEvent("prefs-step");
+ gAction.dispatchEvent(throwEv);
+ });
+ gWaitCounter++;
+ gPrefs.get("center_map", function(aValue) {
+ if (aValue === undefined)
+ document.getElementById("centerCheckbox").checked = true;
+ else
+ document.getElementById("centerCheckbox").checked = aValue;
+ setCentering(document.getElementById("centerCheckbox"));
+ gWaitCounter--;
+ var throwEv = new CustomEvent("prefs-step");
+ gAction.dispatchEvent(throwEv);
+ });
+ gWaitCounter++;
+ gPrefs.get("tracking_enabled", function(aValue) {
+ if (aValue === undefined)
+ document.getElementById("trackCheckbox").checked = true;
+ else
+ document.getElementById("trackCheckbox").checked = aValue;
+ gWaitCounter--;
+ var throwEv = new CustomEvent("prefs-step");
+ gAction.dispatchEvent(throwEv);
+ });
+ gWaitCounter++;
+ var trackLoadStarted = false;
+ var redrawBase = 100;
+ gTrackStore.getListStepped(function(aTPoint) {
+ if (aTPoint) {
+ // Add in front and return new length.
+ var tracklen = gTrack.unshift(aTPoint);
+ // Redraw track periodically, larger distance the longer it gets.
+ // Initial paint will do initial track drawing.
+ if (tracklen % redrawBase == 0) {
+ drawTrack();
+ redrawBase = tracklen;