create hackish way to save GPX tracks and make the map only shift when we get enough...
authorRobert Kaiser <kairo@kairo.at>
Mon, 19 Dec 2011 01:00:05 +0000 (02:00 +0100)
committerRobert Kaiser <kairo@kairo.at>
Mon, 19 Dec 2011 01:00:05 +0000 (02:00 +0100)
index.html
js/map.js
js/ui.js

index 8c889fc97226fa641d59cb4956b42be899451ec3..2b4dd1333f91ce515ebfd8a261cdcd87ac47fe33 100644 (file)
@@ -54,6 +54,8 @@
 <span id="zoomLevel">Z</span>
 <input type="button" id="zoomOutButton" value="-"
        onclick="zoomOut();"><br/>
+<input type="button" id="saveButton" value="Save Track"
+       onclick="saveTrack();"><br/>
 <input type="button" id="settingsButton" value="Settings"
        onclick="toggleSettings();">
 <fieldset id="settings"><legend>Settings</legend>
index 1ce622642e52fe54dd09aeacdd42695381f0cb95..4cd4ea7b809ea786d1ca1dbdbd1ee8be86ab6e24 100644 (file)
--- a/js/map.js
+++ b/js/map.js
@@ -418,9 +418,12 @@ function startTracking() {
         drawTrackPoint(position.coords.latitude, position.coords.longitude);
         if (gCenterPosition) {
           var posCoord = gps2xy(position.coords.latitude, position.coords.longitude);
-          gPos.x = posCoord.x;
-          gPos.y = posCoord.y;
-          drawMap();
+          if (Math.abs(gPos.x - posCoord.x) > gCanvas.width * gZoomFactor / 4 ||
+              Math.abs(gPos.y - posCoord.y) > gCanvas.height * gZoomFactor / 4) {
+            gPos.x = posCoord.x;
+            gPos.y = posCoord.y;
+            drawMap();
+          }
         }
       },
       function(error) {
index 0171e274e35508352a68a64d2ab5c9d3bebc52be..187a84d6663b674619ab7a710ea562990dbc7aff 100644 (file)
--- a/js/ui.js
+++ b/js/ui.js
@@ -62,3 +62,38 @@ function toggleSettings() {
     fs.style.display = "none";
   }
 }
+
+function makeISOString(aTimestamp) {
+  // ISO time format is YYYY-MM-DDTHH:mm:ssZ
+  var tsDate = new Date(aTimestamp);
+  return tsDate.getUTCFullYear() + "-" +
+         (tsDate.getUTCMonth() < 10 ? "0" : "") + tsDate.getUTCMonth() + "-" +
+         (tsDate.getUTCDate() < 10 ? "0" : "") + tsDate.getUTCDate() + "T" +
+         (tsDate.getUTCHours() < 10 ? "0" : "") + tsDate.getUTCHours() + ":" +
+         (tsDate.getUTCMinutes() < 10 ? "0" : "") + tsDate.getUTCMinutes() + ":" +
+         (tsDate.getUTCSeconds() < 10 ? "0" : "") + tsDate.getUTCSeconds() + "Z";
+}
+
+function saveTrack() {
+  if (gTrack.length) {
+    var out = '<?xml version="1.0" encoding="UTF-8" ?>' + "\n\n";
+    out += '<gpx version="1.0" creator="Lantea" xmlns="http://www.topografix.com/GPX/1/0">' + "\n";
+    out += '  <trk>' + "\n";
+    out += '    <trkseg>' + "\n";
+    for (var i = 0; i < gTrack.length; i++) {
+      out += '      <trkpt lat="' + gTrack[i].coords.latitude + '" lon="' +
+                                    gTrack[i].coords.longitude + '">' + "\n";
+      if (gTrack[i].coords.altitude) {
+        out += '        <ele>' + gTrack[i].coords.altitude + '</ele>' + "\n";
+      }
+      out += '        <time>' + makeISOString(gTrack[i].time) + '</time>' + "\n";
+      out += '      </trkpt>' + "\n";
+      gTrack[i].coords.latitude, gTrack[i].coords.longitude;
+    }
+    out += '    </trkseg>' + "\n";
+    out += '  </trk>' + "\n";
+    out += '</gpx>' + "\n";
+    var outDataURI = "data:application/octet-stream," + encodeURIComponent(out);
+    window.open(outDataURI, 'GPX Track');
+  }
+}