+
+var geofake = {
+ tracking: false,
+ lastPos: {x: undefined, y: undefined},
+ watchPosition: function(aSuccessCallback, aErrorCallback, aPrefObject) {
+ this.tracking = true;
+ var watchCall = function() {
+ // calc new position in lat/lon degrees
+ // 90° on Earth surface are ~10,000 km at the equator,
+ // so try moving at most 10m at a time
+ if (geofake.lastPos.x)
+ geofake.lastPos.x += (Math.random() - .5) * 90 / 1000000
+ else
+ geofake.lastPos.x = 48.208174
+ if (geofake.lastPos.y)
+ geofake.lastPos.y += (Math.random() - .5) * 90 / 1000000
+ else
+ geofake.lastPos.y = 16.373819
+ aSuccessCallback({timestamp: Date.now(),
+ coords: {latitude: geofake.lastPos.x,
+ longitude: geofake.lastPos.y,
+ 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) {
+ if (gDebug)
+ 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 = gGeolocation.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) {
+ gGeolocation.clearWatch(gGeoWatchID);
+ }
+}
+
+function clearTrack() {
+ gTrack = [];
+ gTrackStore.clear();
+ drawMap();
+}