| [d7e6e9c] | 1 | /*
|
|---|
| 2 |
|
|---|
| [3121b3b] | 3 | Copyright (C) 2016 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| [d7e6e9c] | 4 |
|
|---|
| 5 | This library is free software; you can redistribute it and/or
|
|---|
| 6 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 7 | License as published by the Free Software Foundation; either
|
|---|
| 8 | version 2.1 of the License, or (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This library is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | Lesser General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 16 | License along with this library; if not, write to the Free Software
|
|---|
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|---|
| 18 | MA 02110-1301 USA.
|
|---|
| 19 |
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| [f8dfbe7] | 22 | var map;
|
|---|
| 23 | var polyline;
|
|---|
| 24 |
|
|---|
| [d7e6e9c] | 25 | function openLink(target){
|
|---|
| 26 | window.location=target;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | function displayDataSet(data){
|
|---|
| [4ab1c0a] | 30 | if(!("lastvalid" in data)){
|
|---|
| 31 | console.log("No last valid values given!");
|
|---|
| 32 | }
|
|---|
| 33 | else{
|
|---|
| 34 | var lastValid = data["lastvalid"];
|
|---|
| 35 | var keys = ["speedthroughwater", "speedoverground", "waterdepth", "watertemperature", "gpsfix"];
|
|---|
| 36 | for(var i = 0; i < keys.length; i++){
|
|---|
| 37 | var key = keys[i];
|
|---|
| 38 | var value = lastValid[key];
|
|---|
| 39 | if($.isNumeric(value)){
|
|---|
| [5149714] | 40 | var text = value.toFixed(1);
|
|---|
| [4ab1c0a] | 41 | if(key == "watertemperature"){
|
|---|
| [5149714] | 42 | text = value.toFixed(0);
|
|---|
| [4ab1c0a] | 43 | }
|
|---|
| [5149714] | 44 | $("#display #"+ keys[i] +" #value").text(text);
|
|---|
| [4ab1c0a] | 45 | }
|
|---|
| 46 | else if(key == "gpsfix"){
|
|---|
| 47 | $("#display #"+ keys[i] +" #value").text(value);
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| [f8dfbe7] | 51 |
|
|---|
| [4ab1c0a] | 52 | if(!("track" in data)){
|
|---|
| 53 | console.log("No track given!");
|
|---|
| 54 | }
|
|---|
| 55 | else{
|
|---|
| 56 | var track = data["track"];
|
|---|
| 57 | var points = [];
|
|---|
| 58 | for(var time in track){
|
|---|
| 59 | points.push(new L.latLng(track[time]["latitude"], track[time]["longitude"]));
|
|---|
| 60 | }
|
|---|
| [f8dfbe7] | 61 | if(points.length > 0){
|
|---|
| [4ab1c0a] | 62 | if(!polyline){
|
|---|
| 63 | polyline = L.polyline(points, {color: 'red'}).addTo(map);
|
|---|
| 64 | }
|
|---|
| 65 | else{
|
|---|
| [f8dfbe7] | 66 | polyline.setLatLngs(points);
|
|---|
| 67 | }
|
|---|
| [4ab1c0a] | 68 | map.fitBounds(polyline.getBounds());
|
|---|
| [f8dfbe7] | 69 | }
|
|---|
| 70 | }
|
|---|
| [d7e6e9c] | 71 | }
|
|---|
| 72 |
|
|---|
| 73 | function displayDataGet() {
|
|---|
| [6f38643] | 74 | var gnuboatApi = "../webservice/";
|
|---|
| [d7e6e9c] | 75 | $.getJSON( gnuboatApi, displayDataSet);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| [6f38643] | 78 | function mapSetup(data){
|
|---|
| 79 | var overlay;
|
|---|
| 80 | var latitudeTop = data["bounds"][3];
|
|---|
| [f8dfbe7] | 81 | var latitudeBottom = data["bounds"][1];
|
|---|
| [6f38643] | 82 | var longitudeLeft = data["bounds"][0];
|
|---|
| [f8dfbe7] | 83 | var longitudeRight = data["bounds"][2];
|
|---|
| 84 |
|
|---|
| 85 | var mapZoomMin = data["minzoom"];
|
|---|
| 86 | var mapZoomMax = data["maxzoom"];
|
|---|
| [6f38643] | 87 |
|
|---|
| 88 | var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
|
|---|
| 89 | var longitudeCenter = (longitudeLeft - longitudeRight)/2 + longitudeRight;
|
|---|
| [f8dfbe7] | 90 | var mapZoomStart = (mapZoomMax - mapZoomMin)/2 + mapZoomMin;
|
|---|
| 91 |
|
|---|
| [6f38643] | 92 | var mapBounds = new L.LatLngBounds(
|
|---|
| [f8dfbe7] | 93 | new L.LatLng(latitudeBottom, longitudeLeft),
|
|---|
| 94 | new L.LatLng(latitudeTop, longitudeRight));
|
|---|
| 95 |
|
|---|
| 96 | map = L.map('map').setView([latitudeCenter, longitudeCenter], mapZoomStart);
|
|---|
| [6f38643] | 97 |
|
|---|
| 98 | overlay = L.tileLayer('../webservice/tileserver.php?/index.json?/map/{z}/{x}/{y}.png', {
|
|---|
| [f8dfbe7] | 99 | minZoom: mapZoomMin, maxZoom: mapZoomMax,
|
|---|
| [6f38643] | 100 | bounds: mapBounds,
|
|---|
| 101 | attribution: 'undefined',opacity: 0.85
|
|---|
| [f8dfbe7] | 102 | }).addTo(map);
|
|---|
| [6f38643] | 103 | }
|
|---|
| 104 |
|
|---|
| [5519ced] | 105 | function shutdown(){
|
|---|
| 106 | $.getJSON("../webservice/?request=shutdown", function(data){
|
|---|
| 107 | var shutdownTime = data["shutdownstart"];
|
|---|
| [d7ee6ae] | 108 | var shutdownDate = Date.parse(shutdownTime);
|
|---|
| [5519ced] | 109 | var currentDate = new Date();
|
|---|
| 110 | var shutdownHint = "Shutting down in "+ Math.floor((shutdownDate - currentDate)/1000) +"s at "+ shutdownTime.toLocaleString();
|
|---|
| 111 | if(shutdownTime == -1){
|
|---|
| 112 | shutdownHint = "Failed to initiate shutdown!";
|
|---|
| 113 | }
|
|---|
| 114 | $("#shutdownMessage").text(shutdownHint);
|
|---|
| 115 | });
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| [d7e6e9c] | 118 | $(document).ready(function() {
|
|---|
| 119 | displayDataGet();
|
|---|
| 120 | setInterval(displayDataGet, 5000);
|
|---|
| [6f38643] | 121 |
|
|---|
| 122 | $.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
|
|---|
| [5519ced] | 123 |
|
|---|
| 124 | $("#shutdownButton").click(shutdown);
|
|---|
| [d7e6e9c] | 125 | });
|
|---|