move track to its own canvas, make painting current position actually work, delay...
[lantea.git] / js / ui.js
index 7fb08b15f66ccdb0fed2fd1fc7836bb4a994b36b..e347b99842732bcf3b1540e8308228acf44fe4db 100644 (file)
--- a/js/ui.js
+++ b/js/ui.js
@@ -7,6 +7,7 @@ var iDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || w
 var mainDB;
 
 var gUIHideCountdown = 0;
+var gWaitCounter = 0;
 
 window.onload = function() {
   var mSel = document.getElementById("mapSelector");
@@ -31,7 +32,7 @@ window.onload = function() {
     areas[i].addEventListener("touchleave", uiEvHandler, false);
   }
 
-  if (/Mozilla\/5.0 \(Mobile;/.test(navigator.useragent)) {
+  if (navigator.platform.length == "") {
     // For Firefox OS, don't display the "save" button.
     // Do this by setting the debugHide class for testing in debug mode.
     document.getElementById("saveTrackButton").classList.add("debugHide");
@@ -39,7 +40,24 @@ window.onload = function() {
 
   initDB();
   initMap();
-  resizeAndDraw();
+
+  var loopCnt = 0;
+  var waitForInitAndDraw = function() {
+    if ((gWaitCounter <= 0) || (loopCnt > 100)) {
+      if (gWaitCounter <= 0)
+        gWaitCounter = 0;
+      else
+        document.getElementById("debug").textContent = "Loading prefs failed.";
+
+      gMapPrefsLoaded = true;
+      resizeAndDraw();
+      setTracking(document.getElementById("trackCheckbox"));
+    }
+    else
+      setTimeout(waitForInitAndDraw, 100);
+    loopCnt++;
+  };
+  waitForInitAndDraw();
 }
 
 window.onresize = function() {