Index: src/webapp/webclient/js/main.js
===================================================================
--- src/webapp/webclient/js/main.js	(revision 4972eea924c8421014ddb7dc14792b577eea4aa2)
+++ src/webapp/webclient/js/main.js	(revision 4972eea924c8421014ddb7dc14792b577eea4aa2)
@@ -0,0 +1,159 @@
+/*
+
+    Copyright (C) 2016 - 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+
+*/
+
+var map;
+var polyline;
+
+function openLink(target){
+	window.location=target;
+}
+
+function displayDataSet(data){
+	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!");
+	}
+	else{
+		var lastValid = data["lastvalid"];
+		var keys = ["speedthroughwater", "speedoverground", "waterdepth", "watertemperature", "gpsfix"];
+		for(var i = 0; i < keys.length; i++){
+			var key = keys[i];
+			var value = lastValid[key];
+			if($.isNumeric(value)){
+				var text = value.toFixed(1);
+				if(key == "watertemperature"){
+					text = value.toFixed(0);
+				}
+				$("#display #"+ keys[i] +" #value").text(text);
+			}
+			else if(key == "gpsfix"){
+				$("#display #"+ keys[i] +" #value").text(value);
+			}
+		}
+	}
+	
+	if(!("track" in data)){
+			console.log("No track given!");
+	}
+	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"];
+	
+	var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
+	var longitudeCenter = (longitudeLeft - longitudeRight)/2 + longitudeRight;
+	var mapZoomStart = (mapZoomMax - mapZoomMin)/2 + mapZoomMin;
+	
+	var mapBounds = new L.LatLngBounds(
+              new L.LatLng(latitudeBottom, longitudeLeft),
+              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', {
+		minZoom: mapZoomMin, maxZoom: mapZoomMax,
+		bounds: mapBounds,
+		attribution: 'undefined',opacity: 0.85
+		}).addTo(map);
+}
+
+function shutdown(){
+	$.getJSON("../webservice/?request=shutdown", function(data){
+		var shutdownTime = data["shutdownstart"];
+		var shutdownDate = Date.parse(shutdownTime);
+		var currentDate = new Date();
+		var shutdownHint = "Shutting down in "+ Math.floor((shutdownDate - currentDate)/1000) +"s at "+ shutdownTime.toLocaleString();
+		if(shutdownTime == -1){
+			shutdownHint = "Failed to initiate shutdown!";
+		}
+		$("#shutdownMessage").text(shutdownHint);
+	});
+}
+
+function uploadMap(form)
+{
+	$.ajax({
+		type: "POST",
+		url: "../webservice/mapupload.php",
+		data: $(form).serialize(),
+		success: function(data){
+			if(("error" in data) && data["error"] == 1){
+				alert("Failed to upload map: "+ data["errormessage"]);
+				return;
+			}
+			alert("Map upload successfully");
+		},
+		error: function(jqXHR, exception, errorThrown){ alert("Failed to upload map: "+ exception); }
+	});
+}
+
+
+$(document).ready(function() {
+	displayDataGet();
+	setInterval(displayDataGet, 10000);
+
+	$.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
+	
+	$("shutdown").click(shutdown);
+	
+	$("#mapTileUpload").validate({
+		rules: {
+			mapFile: {
+				required: true
+			}
+		},
+		submitHandler: function(form){
+			uploadMap(form);
+		}
+	});
+});
