+
+var geofake = {
+ tracking: false,
+ watchPosition: function(aSuccessCallback, aErrorCallback, aPrefObject) {
+ this.tracking = true;
+ var watchCall = function() {
+ aSuccessCallback({timestamp: Date.now(),
+ coords: {latitude: 48.208174 +
+ (Math.random() - .5) / 5,
+ longitude: 16.373819 +
+ (Math.random() - .5) / 5,
+ accuracy: 20}});
+ if (geofake.tracking)
+ setTimeout(watchCall, 1000);
+ };
+ setTimeout(watchCall, 1000);
+ return "foo";
+ },
+ clearWatch: function(aID) {
+ this.tracking = false;
+ }
+}
+
+function setCentering(aCheckbox) {
+ if (gMapPrefsLoaded && mainDB)
+ gPrefs.set("center_map", aCheckbox.checked);
+ gCenterPosition = aCheckbox.checked;
+}
+
+function setTracking(aCheckbox) {
+ if (gMapPrefsLoaded && mainDB)
+ gPrefs.set("tracking_enabled", aCheckbox.checked);
+ if (aCheckbox.checked)
+ startTracking();
+ else
+ endTracking();
+}
+
+function startTracking() {
+ var loopCnt = 0;
+ var getStoredTrack = function() {
+ if (mainDB)
+ gTrackStore.getList(function(aTPoints) {
+ //document.getElementById("debug").textContent = aTPoints.length + " points loaded.";
+ if (aTPoints.length) {
+ gTrack = aTPoints;
+ }
+ });
+ else
+ setTimeout(getStoredTrack, 100);
+ loopCnt++;
+ if (loopCnt > 20)
+ return;
+ };
+ getStoredTrack();
+ if (navigator.geolocation) {
+ //gGeoWatchID = geofake.watchPosition(
+ gGeoWatchID = navigator.geolocation.watchPosition(
+ function(position) {
+ // Coords spec: https://developer.mozilla.org/en/XPCOM_Interface_Reference/NsIDOMGeoPositionCoords
+ var tPoint = {time: position.timestamp,
+ coords: position.coords,
+ beginSegment: !gLastTrackPoint};
+ gTrack.push(tPoint);
+ gTrackStore.push(tPoint);
+ drawTrackPoint(position.coords.latitude, position.coords.longitude);
+ if (gCenterPosition) {
+ var posCoord = gps2xy(position.coords.latitude,
+ position.coords.longitude);
+ 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) {
+ // Ignore erros for the moment, but this is good for debugging.
+ // See https://developer.mozilla.org/en/Using_geolocation#Handling_errors
+ document.getElementById("debug").textContent = error.message;
+ },
+ {enableHighAccuracy: true}
+ );
+ }
+}
+
+function endTracking() {
+ if (gGeoWatchID) {
+ //geofake.clearWatch(gGeoWatchID);
+ navigator.geolocation.clearWatch(gGeoWatchID);
+ }
+}
+
+function clearTrack() {
+ gTrack = [];
+ gTrackStore.clear();
+ drawMap();
+}