source: src/webapp/webclient/javascript/main.js@ ec44191

debian/bullseye debian/jessie
Last change on this file since ec44191 was 5149714, checked in by Joachim Langenbach <joachim.langenbach@…>, 10 years ago
  • Add favicon to webclient
  • Add icon to webclient title
  • javascript prints the numbers in the display formatted (one decimal) now
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2
3 Copyright (C) 2016 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
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
22var map;
23var polyline;
24
25function openLink(target){
26 window.location=target;
27}
28
29function displayDataSet(data){
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)){
40 var text = value.toFixed(1);
41 if(key == "watertemperature"){
42 text = value.toFixed(0);
43 }
44 $("#display #"+ keys[i] +" #value").text(text);
45 }
46 else if(key == "gpsfix"){
47 $("#display #"+ keys[i] +" #value").text(value);
48 }
49 }
50 }
51
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 }
61 if(points.length > 0){
62 if(!polyline){
63 polyline = L.polyline(points, {color: 'red'}).addTo(map);
64 }
65 else{
66 polyline.setLatLngs(points);
67 }
68 map.fitBounds(polyline.getBounds());
69 }
70 }
71}
72
73function displayDataGet() {
74 var gnuboatApi = "../webservice/";
75 $.getJSON( gnuboatApi, displayDataSet);
76}
77
78function mapSetup(data){
79 var overlay;
80 var latitudeTop = data["bounds"][3];
81 var latitudeBottom = data["bounds"][1];
82 var longitudeLeft = data["bounds"][0];
83 var longitudeRight = data["bounds"][2];
84
85 var mapZoomMin = data["minzoom"];
86 var mapZoomMax = data["maxzoom"];
87
88 var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
89 var longitudeCenter = (longitudeLeft - longitudeRight)/2 + longitudeRight;
90 var mapZoomStart = (mapZoomMax - mapZoomMin)/2 + mapZoomMin;
91
92 var mapBounds = new L.LatLngBounds(
93 new L.LatLng(latitudeBottom, longitudeLeft),
94 new L.LatLng(latitudeTop, longitudeRight));
95
96 map = L.map('map').setView([latitudeCenter, longitudeCenter], mapZoomStart);
97
98 overlay = L.tileLayer('../webservice/tileserver.php?/index.json?/map/{z}/{x}/{y}.png', {
99 minZoom: mapZoomMin, maxZoom: mapZoomMax,
100 bounds: mapBounds,
101 attribution: 'undefined',opacity: 0.85
102 }).addTo(map);
103}
104
105function shutdown(){
106 $.getJSON("../webservice/?request=shutdown", function(data){
107 var shutdownTime = data["shutdownstart"];
108 var shutdownDate = Date.parse(shutdownTime);
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
118$(document).ready(function() {
119 displayDataGet();
120 setInterval(displayDataGet, 5000);
121
122 $.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
123
124 $("#shutdownButton").click(shutdown);
125});
Note: See TracBrowser for help on using the repository browser.