Index: src/webapp/webclient/js/GnuBoat.js
===================================================================
--- src/webapp/webclient/js/GnuBoat.js	(revision 563c04b540657b88fb842951eca1a7bac9086756)
+++ src/webapp/webclient/js/GnuBoat.js	(revision a50c18fef08b331ee0dc7d29dfe1dd5b3574d03f)
@@ -54,5 +54,5 @@
 {
 	if(GnuBoat.private.serverBaseUrl == null){
-		GnuBoat.displayMessage("No server set/found");
+		GnuBoat.displayMessage('<span class="error">No server set/found</span>');
 		return;
 	}
@@ -67,5 +67,5 @@
 {
 	if(GnuBoat.private.serverBaseUrl == null){
-		GnuBoat.displayMessage("No server set/found");
+		GnuBoat.displayMessage('<span class="error">No server set/found</span>');
 		return;
 	}
@@ -79,9 +79,10 @@
 {
 	if(GnuBoat.private.serverBaseUrl == null){
-		GnuBoat.displayMessage("No server set/found");
+		GnuBoat.displayMessage('<span class="error">No server set/found</span>');
 		return;
 	}
 	$("#logfilesForm").empty();
 	$.getJSON(GnuBoat.private.serverBaseUrl +"?request=logfiles", function(data){
+		GnuBoat.private.updateMapModus(data);
 		if(!Array.isArray(data) || data.length < 1){
 			$("<p>No Logfiles found!</p>").appendTo("#logfilesForm");
@@ -90,7 +91,7 @@
 		}
 		if(("error" in data) && data["error"] == 1){
-			alert("Failed to upload map: "+ data["errormessage"]);
-			$("#mapTileUploadProgress").hide();
-			$("#mapFileInput").show();
+			GnuBoat.displayMessage('<span class="error">Failed to get log files: '+ data["errormessage"] +'</span>');
+			$("<p>No Logfiles found!</p>").appendTo("#logfilesForm");
+			console.log(data);
 			return;
 		}
@@ -108,5 +109,5 @@
 {
 	if(GnuBoat.private.serverBaseUrl == null){
-		GnuBoat.displayMessage("No server set/found");
+		GnuBoat.displayMessage('<span class="error">No server set/found</span>');
 		return;
 	}
@@ -129,5 +130,5 @@
 {
 	if(GnuBoat.private.serverBaseUrl == null){
-		displayMessage("No server set/found");
+		displayMessage('<span class="error">No server set/found</span>');
 		return;
 	}
@@ -142,10 +143,10 @@
 		success: function(data){
 			if(("error" in data) && data["error"] == 1){
-				alert("Failed to upload map: "+ data["errormessage"]);
+				GnuBoat.displayMessage('<span class="error">Failed to upload map: '+ data["errormessage"] +'</span>');
 				$("#mapTileUploadProgress").hide();
 				$("#mapFileInput").show();
 				return;
 			}
-			alert("Map upload successfully");
+			GnuBoat.displayMessage('<span class="error">Map upload successfully</span>');
 			$("#mapTileUploadProgress").hide();
 			$("#mapFileInput").show();
@@ -153,5 +154,5 @@
 		},
 		error: function(jqXHR, exception, errorThrown){
-			alert("Failed to upload map (XHR): "+ exception);
+			GnuBoat.displayMessage('<span class="error">Failed to upload map (XHR): '+ exception +'</span>');
 			$("#mapTileUploadProgress").hide();
 			$("#mapFileInput").show();
@@ -167,4 +168,5 @@
 GnuBoat.initialize = function()
 {
+	$("#mapModusSelect").change(function(){ GnuBoat.private.mapModusChanged(); });
 	$("#mapTileUploadProgress").hide();
 	$("#logfilesReload").click(GnuBoat.logfilesLoad);
@@ -242,5 +244,5 @@
 {
 	if(GnuBoat.private.serverBaseUrl == null){
-		GnuBoat.displayMessage("No server set/found");
+		GnuBoat.displayMessage('<span class="error">No server set/found</span>');
 		return;
 	}
@@ -250,5 +252,5 @@
 	if(GnuBoat.private.timerDisplay == null)
 		GnuBoat.private.timerDisplay = setInterval(GnuBoat.displayDataGet, 10000);
-	GnuBoat.logfilesLoad();	
+	GnuBoat.logfilesLoad();
 	
 	GnuBoat.private.animate();
@@ -276,4 +278,5 @@
 	mapsMetadata: null,
 	mapBounds: null,
+	mapModusLive: true,
 	dataMappings: {
 		speedthroughwater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"},
@@ -302,4 +305,14 @@
 	displayDataSet: function(data)
 	{
+// 		if(!Array.isArray(data) || data.length < 1){
+// 			console.log("No data array returned!");
+// 			console.log(data);
+// 			return;
+// 		}
+		if(("error" in data) && data["error"] == 1){
+			GnuBoat.displayMessage('<span class="error">Failed to get display data and tracks: '+ data["errormessage"] +'</span>');
+			return;
+		}
+
 		var keysDisplay = [];
 		for(var key in GnuBoat.private.dataMappings){
@@ -307,9 +320,5 @@
 				keysDisplay.push(key);
 		}
-		if(!Array.isArray(data) && !(data instanceof Object)){
-			console.log("No data array returned!");
-			console.log(data);
-			return;
-		}
+
 		if(!("lastvalid" in data)){
 				console.log("No last valid values given!");
@@ -333,68 +342,12 @@
 		}
 		
-		if(!("track" in data)){
-				console.log("No track given!");
-		}
-		else{
-			if(GnuBoat.private.map == null){
-				console.log("No map in use");
-			}
-			else{
-				var track = data["track"];
-				var maximas = [];
-				var minimas = [];
-				var points = [];
-				var densityPoints = [];
-				
-				var keysMap = [];
-				for(var key in GnuBoat.private.dataMappings){
-					if(GnuBoat.private.dataMappings[key]["map"] === true)
-						keysMap.push(key);
-				}
-				for(var i = 0; i < keysMap.length; i++){
-					if(keysMap[i] == "gpsfix")
-						continue;
-					points[keysMap[i]] = [];
-				}
-				
-				// getting maximas, minimums for normalization and the tracks themselves
-				for(var time in track){
-					for(var i = 0; i < keysMap.length; i++){
-						var key = keysMap[i];
-						if(key == "gpsfix")
-							continue;
-						if(!(key in maximas))
-							maximas[key] = track[time][key]
-						else if(maximas[key] < track[time][key])
-							maximas[key] = track[time][key];
-						if(!(key in minimas))
-							minimas[key] = track[time][key]
-						else if(minimas[key] > track[time][key])
-							minimas[key] = track[time][key];
-						points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], track[time][key]));
-						densityPoints.push({latitude: track[time]["latitude"], longitude: track[time]["longitude"], depth: track[time]["waterdepth"]});
-					}
-				}
-				for(var i = 0; i < keysMap.length; i++){
-					var key = keysMap[i];
-					if(key == "gpsfix")
-						continue;
-					if(points[key].length > 0){
-						if(key in GnuBoat.private.mapPolylines)
-							GnuBoat.private.mapPolylines[key].setLatLngs(points[key]);
-						else{
-							GnuBoat.private.mapPolylines[key] = L.hotline(points[key], {weight: 3, outlineWidth: 0, min: minimas[key], max: maximas[key]});
-							if(GnuBoat.private.mapControl){
-								var name = GnuBoat.private.dataMappings[key]["titleLong"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +" ("+ GnuBoat.private.dataMappings[key]["titleShort"] +")";
-								GnuBoat.private.mapControl.addOverlay(GnuBoat.private.mapPolylines[key], name);
-							}
-							if(GnuBoat.private.dataMappings[key]["mapActive"] === true)
-								GnuBoat.private.mapPolylines[key].addTo(GnuBoat.private.map);
-						}
-					}
-				}
-				GnuBoat.private.drawDensityEstimation(densityPoints, maximas["waterdepth"], minimas["waterdepth"]);
-			}
-		}
+		// map displays logged data
+		if(!GnuBoat.private.mapModusLive)
+			return;
+		else if(!("track" in data)){
+			console.log("No track given!");
+			return;
+		}
+		GnuBoat.private.mapAddTracks(data["track"]);
 	},
 	
@@ -578,3 +531,134 @@
 		return result;
 	},
+	
+	updateMapModus: function(data)
+	{
+		var selected = $("#mapModusSelect").val();
+		$("#mapModusSelect").empty();
+		var selectedFound = false;
+		if(selected != null && Array.isArray(data)){
+			data.forEach(function(value, index){
+				if(value == selected)
+					selectedFound = true;
+			});
+		}
+		var selectedString = "";
+		if(!selectedFound)
+			selectedString = " selected";
+		$('<option value="live"'+ selectedString +'>Live View</option>').appendTo("#mapModusSelect");
+		if(!Array.isArray(data) || data.length < 1){
+			console.log(data);
+			return;
+		}
+		if(("error" in data) && data["error"] == 1){
+			GnuBoat.displayMessage('<span class="error">Failed to upload map: '+ data["errormessage"] +'</span>');
+			return;
+		}
+		data.forEach(function(value, index){
+			var selectedString = "";
+			if(value == selected)
+				selectedString = " selected";
+			$("<option value=\""+ value +"\""+ selected +">"+ value +"</option>").appendTo("#mapModusSelect");
+		});
+	},
+	
+	mapModusChanged: function()
+	{
+		var modus = $("#mapModusSelect").val();
+		// live modus is automatically activated on displayDataSet
+		if(modus == "live"){
+			GnuBoat.private.mapModusLive = true;
+			return;
+		}
+		// remove overlays
+		if(GnuBoat.private.mapControl != null){
+			for(var key in GnuBoat.private.dataMappings){
+				if(GnuBoat.private.dataMappings[key]["map"] === true)
+					if(key in GnuBoat.private.mapPolylines){
+						GnuBoat.private.mapControl.removeLayer(GnuBoat.private.mapPolylines[key]);
+						GnuBoat.private.mapPolylines[key].remove();
+						delete GnuBoat.private.mapPolylines[key];
+					}
+			}
+		}
+		GnuBoat.private.mapModusLive = false;
+		$.post({
+			url: GnuBoat.private.serverBaseUrl +'?request=replay',
+			data: { logfile: modus },
+			success: function(data){
+// 				if(!Array.isArray(data) || data.length < 1){
+// 					console.log("No data array returned!");
+// 					console.log(data);
+// 					return;
+// 				}
+				if(("error" in data) && data["error"] == 1){
+					GnuBoat.displayMessage('<span class="error">Failed to get logged tracks: '+ data["errormessage"] +'</span>');
+					return;
+				}
+				if(!("track" in data)){
+					console.log("No track given!");
+					return;
+				}
+				GnuBoat.private.mapAddTracks(data["track"]);
+			}
+		});
+	},
+	
+	mapAddTracks: function(track)
+	{
+		if(GnuBoat.private.map == null){
+			console.log("No map in use");
+			return;
+		}
+		
+		var maximas = [];
+		var minimas = [];
+		var points = [];
+		var densityPoints = [];
+		
+		var keysMap = [];
+		for(var key in GnuBoat.private.dataMappings){
+			if(GnuBoat.private.dataMappings[key]["map"] === true)
+				keysMap.push(key);
+		}
+		for(var i = 0; i < keysMap.length; i++){
+			points[keysMap[i]] = [];
+		}
+		
+		// getting maximas, minimums for normalization and the tracks themselves
+		for(var time in track){
+			for(var i = 0; i < keysMap.length; i++){
+				var key = keysMap[i];
+				if(key == "gpsfix")
+					continue;
+				if(!(key in maximas))
+					maximas[key] = track[time][key]
+				else if(maximas[key] < track[time][key])
+					maximas[key] = track[time][key];
+				if(!(key in minimas))
+					minimas[key] = track[time][key]
+				else if(minimas[key] > track[time][key])
+					minimas[key] = track[time][key];
+				points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], track[time][key]));
+				densityPoints.push({latitude: track[time]["latitude"], longitude: track[time]["longitude"], depth: track[time]["waterdepth"]});
+			}
+		}
+		for(var i = 0; i < keysMap.length; i++){
+			var key = keysMap[i];
+			if(points[key].length > 0){
+				if(key in GnuBoat.private.mapPolylines)
+					GnuBoat.private.mapPolylines[key].setLatLngs(points[key]);
+				else{
+					GnuBoat.private.mapPolylines[key] = L.hotline(points[key], {weight: 3, outlineWidth: 0, min: minimas[key], max: maximas[key]});
+					if(GnuBoat.private.mapControl){
+						var name = GnuBoat.private.dataMappings[key]["titleLong"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +" ("+ GnuBoat.private.dataMappings[key]["titleShort"] +")";
+						GnuBoat.private.mapControl.addOverlay(GnuBoat.private.mapPolylines[key], name);
+					}
+					if(GnuBoat.private.dataMappings[key]["mapActive"] === true)
+						GnuBoat.private.mapPolylines[key].addTo(GnuBoat.private.map);
+				}
+			}
+		}
+		GnuBoat.private.drawDensityEstimation(densityPoints, maximas["waterdepth"], minimas["waterdepth"]);
+	},
 };
