
function MapTracker() {
	this.saveTrackUrl = MACEConstants.componentsURL + "tracker/php/saveTrack.php";
} 

MapTracker.prototype.save = function(params) {
	params.action = "map";
	$.getJSON(this.saveTrackUrl, params, function (result) {
   		if(result.success) {
   			console.log("Saved track : " + result.actionID);
   		}
   		else {
			console.log("Saving track failed!"  + result.actionID);
   		}
   	});
}

MapTracker.prototype.trackSearch = function(query) {
	console.log("MapTracker: search: " + query);
	this.save({
		"type": "search",
		"query": query
	});
} 

MapTracker.prototype.trackViewArea = function(maceGeoBoundary) {
	console.log("MapTracker: viewArea: " + maceGeoBoundary);
	this.save({
		"type": "viewArea",
		"lat1": maceGeoBoundary.nwLat,
		"lng1": maceGeoBoundary.nwLng,
		"lat2": maceGeoBoundary.seLat,
		"lng2": maceGeoBoundary.seLng
	});
}

MapTracker.prototype.trackMoveTo = function(maceGeoBoundary) {
	this.trackViewArea(maceGeoBoundary);
}

MapTracker.prototype.trackZoom = function(oldLevel, newLevel) {
	console.log("MapTracker: zoom: " + oldLevel + " -> " + newLevel);
	this.save({
		"type": "zoom",
		"oldLevel": oldLevel,
		"newLevel": newLevel
	});
}

MapTracker.prototype.trackSetPosition = function(maceLocation) {
	console.log("MapTracker: setPos: " + maceLocation);
	this.save({
		"type": "setPos",
		"contentId": maceLocation.positionedContent.id,
		"lat1": maceLocation.newGLatLng ? maceLocation.newGLatLng.lat() : null,
		"lng1": maceLocation.newGLatLng ? maceLocation.newGLatLng.lng() : null,
		"lat2": maceLocation.originalGLatLng ? maceLocation.originalGLatLng.lat() : null,
		"lng2": maceLocation.originalGLatLng ? maceLocation.originalGLatLng.lng() : null
	});
}

MapTracker.prototype.trackSavePosition = function(maceLocation) {
	console.log("MapTracker: savePos: " + maceLocation);
	// store whether add or edit
	this.save({
		"type": "savePos",
		"contentId": maceLocation.positionedContent.id,
		"lat1": maceLocation.newGLatLng ? maceLocation.newGLatLng.lat() : null,
		"lng1": maceLocation.newGLatLng ? maceLocation.newGLatLng.lng() : null,
		"lat2": maceLocation.originalGLatLng ? maceLocation.originalGLatLng.lat() : null,
		"lng2": maceLocation.originalGLatLng ? maceLocation.originalGLatLng.lng() : null
	});
}

MapTracker.prototype.trackViewPositionDetail = function(maceLocation) {
	console.log("MapTracker: viewPos: " + maceLocation);
}

MapTracker.prototype.trackOpenContent = function(contentId) {
	console.log("MapTracker: openContent: " + contentId);
}
