Index: src/webapp/webclient/js/main.js
===================================================================
--- src/webapp/webclient/js/main.js	(revision 4972eea924c8421014ddb7dc14792b577eea4aa2)
+++ src/webapp/webclient/js/main.js	(revision ba861c4bf288564779dbc026e8e819b570897993)
@@ -20,12 +20,17 @@
 */
 
-var map;
-var polyline;
-
-function openLink(target){
+var map = null;
+var mapLayerCurrent = null;
+// var mapControl = null;
+var mapsMetadata = null;
+var polyline = null;
+
+function openLink(target)
+{
 	window.location=target;
 }
 
-function displayDataSet(data){
+function displayDataSet(data)
+{
 	if(!Array.isArray(data) && !(data instanceof Object)){
 		console.log("No data array returned!");
@@ -59,35 +64,52 @@
 	}
 	else{
-		var track = data["track"];
-		var points = [];
-		for(var time in track){
-			points.push(new L.latLng(track[time]["latitude"], track[time]["longitude"]));
-		}
-		if(points.length > 0){
-			if(!polyline){
-				polyline = L.polyline(points, {color: 'red'}).addTo(map);
-			}
-			else{
-				polyline.setLatLngs(points);
-			}
-			map.fitBounds(polyline.getBounds());
-		}
-	}
-}
-
-function displayDataGet() {
+		if(map == null){
+			console.log("No map in use");
+		}
+		else{
+			var track = data["track"];
+			var points = [];
+			for(var time in track){
+				points.push(new L.latLng(track[time]["latitude"], track[time]["longitude"]));
+			}
+			if(points.length > 0){
+				if(!polyline){
+					polyline = L.polyline(points, {color: 'red'}).addTo(map);
+				}
+				else{
+					polyline.setLatLngs(points);
+				}
+				map.fitBounds(polyline.getBounds());
+			}
+		}
+	}
+}
+
+function displayDataGet()
+{
 	var gnuboatApi = "../webservice/";
 	$.getJSON( gnuboatApi, displayDataSet);
 }
 
-function mapSetup(data){
-	var overlay;
-	var latitudeTop = data["bounds"][3];
-	var latitudeBottom = data["bounds"][1];
-	var longitudeLeft = data["bounds"][0];
-	var longitudeRight = data["bounds"][2];
-	
-	var mapZoomMin = data["minzoom"];
-	var mapZoomMax = data["maxzoom"];
+function mapSetup()
+{
+	var mapMetadataIndex = $("#mapSelect").val();
+	if(mapsMetadata == null){
+		console.log("No mapsMetadata set");
+	}
+	if(mapMetadataIndex < 0 || mapMetadataIndex >= mapsMetadata.length){
+		console.log("Map metadata is outside of range :"+ mapMetadataIndex.toString());
+		console.log(mapsMetadata);
+		return;
+	}
+	var mapMetadata = mapsMetadata[mapMetadataIndex];
+	
+	var latitudeTop = mapMetadata["bounds"][3];
+	var latitudeBottom = mapMetadata["bounds"][1];
+	var longitudeLeft = mapMetadata["bounds"][0];
+	var longitudeRight = mapMetadata["bounds"][2];
+	
+	var mapZoomMin = mapMetadata["minzoom"];
+	var mapZoomMax = mapMetadata["maxzoom"];
 	
 	var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
@@ -99,14 +121,44 @@
               new L.LatLng(latitudeTop, longitudeRight));
 	
-	map = L.map('map').setView([latitudeCenter, longitudeCenter], mapZoomStart);
-	
-	overlay = L.tileLayer('../webservice/tileserver.php?/index.json?/map/{z}/{x}/{y}.png', {
+	if(map == null){
+		// only initialize the map (viewport) once
+		map = L.map('mapViewport');
+	}
+	map.setView([latitudeCenter, longitudeCenter], mapZoomStart);
+	
+	if(mapLayerCurrent != null){
+		map.removeLayer(mapLayerCurrent);
+		mapLayerCurrent = null;
+	}
+	mapLayerCurrent = L.tileLayer(mapMetadata["tiles"][0], {
 		minZoom: mapZoomMin, maxZoom: mapZoomMax,
 		bounds: mapBounds,
-		attribution: 'undefined',opacity: 0.85
+		attribution: mapMetadata["name"],
+		opacity: 0.85
 		}).addTo(map);
 }
 
-function shutdown(){
+function getMapInfos()
+{
+	$.getJSON("../webservice/tileserver.php?/index.json", mapInfos);
+}
+
+function mapInfos(data)
+{
+	mapsMetadata = data;
+	
+	$("#mapSelect").empty();
+	var selected = "selected";
+	data.forEach(function(value, index){
+		$("<option value=\""+ index.toString() +"\" "+ selected +">"+ value["name"] +"</option>").appendTo("#mapSelect");
+		selected = "";
+	});
+	
+	mapSetup();
+	$("#mapSelect").change(function(){ mapSetup(); });
+}
+
+function shutdown()
+{
 	$.getJSON("../webservice/?request=shutdown", function(data){
 		var shutdownTime = data["shutdownstart"];
@@ -123,16 +175,34 @@
 function uploadMap(form)
 {
+	var formData = new FormData($("#mapTileUpload")[0]);
+// 	formData.append("mapFile", $("#mapFileInput")[0].files[0]);
+	
+	$("#mapFileInput").hide();
+	$("#mapTileUploadProgress").show();
 	$.ajax({
-		type: "POST",
-		url: "../webservice/mapupload.php",
-		data: $(form).serialize(),
+		type: 'POST',
+		url: '../webservice/mapupload.php',
+		data: formData,
+		contentType: false,
+		processData: false,
 		success: function(data){
 			if(("error" in data) && data["error"] == 1){
 				alert("Failed to upload map: "+ data["errormessage"]);
+				$("#mapTileUploadProgress").hide();
+				$("#mapFileInput").show();
 				return;
 			}
 			alert("Map upload successfully");
+			$("#mapTileUploadProgress").hide();
+			$("#mapFileInput").show();
+			getMapInfos();
 		},
-		error: function(jqXHR, exception, errorThrown){ alert("Failed to upload map: "+ exception); }
+		error: function(jqXHR, exception, errorThrown){
+			alert("Failed to upload map (XHR): "+ exception);
+			$("#mapTileUploadProgress").hide();
+			$("#mapFileInput").show();
+		}
+	}).progress(function(e){
+		$("#mapTileUploadProgress").attr({value: e.oloaded, max: e.total});
 	});
 }
@@ -140,12 +210,8 @@
 
 $(document).ready(function() {
-	displayDataGet();
-	setInterval(displayDataGet, 10000);
-
-	$.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
-	
+	$("#mapTileUploadProgress").hide();
 	$("shutdown").click(shutdown);
-	
-	$("#mapTileUpload").validate({
+
+		$("#mapTileUpload").validate({
 		rules: {
 			mapFile: {
@@ -157,3 +223,7 @@
 		}
 	});
+
+	getMapInfos();
+	displayDataGet();
+	setInterval(displayDataGet, 10000);
 });
