source: src/webapp/webclient/javascript/main.js@ 06c0abb

0.5 app-cordova debian/bullseye debian/jessie
Last change on this file since 06c0abb was c84f87e, checked in by Joachim Langenbach <joachim.langenbach@…>, 10 years ago

Merge branch 'master' of ​https://svn.falaba.de/gnuboat

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2
3 Copyright (C) 2016 - 2017 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(!Array.isArray(data)){
31 console.log("No data array returned!");
32 return;
33 }
34 if(!("lastvalid" in data)){
35 console.log("No last valid values given!");
36 }
37 else{
38 var lastValid = data["lastvalid"];
39 var keys = ["speedthroughwater", "speedoverground", "waterdepth", "watertemperature", "gpsfix"];
40 for(var i = 0; i < keys.length; i++){
41 var key = keys[i];
42 var value = lastValid[key];
43 if($.isNumeric(value)){
44 var text = value.toFixed(1);
45 if(key == "watertemperature"){
46 text = value.toFixed(0);
47 }
48 $("#display #"+ keys[i] +" #value").text(text);
49 }
50 else if(key == "gpsfix"){
51 $("#display #"+ keys[i] +" #value").text(value);
52 }
53 }
54 }
55
56 if(!("track" in data)){
57 console.log("No track given!");
58 }
59 else{
60 var track = data["track"];
61 var points = [];
62 for(var time in track){
63 points.push(new L.latLng(track[time]["latitude"], track[time]["longitude"]));
64 }
65 if(points.length > 0){
66 if(!polyline){
67 polyline = L.polyline(points, {color: 'red'}).addTo(map);
68 }
69 else{
70 polyline.setLatLngs(points);
71 }
72 map.fitBounds(polyline.getBounds());
73 }
74 }
75}
76
77function displayDataGet() {
78 var gnuboatApi = "../webservice/";
79 $.getJSON( gnuboatApi, displayDataSet);
80}
81
82function mapSetup(data){
83 var overlay;
84 var latitudeTop = data["bounds"][3];
85 var latitudeBottom = data["bounds"][1];
86 var longitudeLeft = data["bounds"][0];
87 var longitudeRight = data["bounds"][2];
88
89 var mapZoomMin = data["minzoom"];
90 var mapZoomMax = data["maxzoom"];
91
92 var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
93 var longitudeCenter = (longitudeLeft - longitudeRight)/2 + longitudeRight;
94 var mapZoomStart = (mapZoomMax - mapZoomMin)/2 + mapZoomMin;
95
96 var mapBounds = new L.LatLngBounds(
97 new L.LatLng(latitudeBottom, longitudeLeft),
98 new L.LatLng(latitudeTop, longitudeRight));
99
100 map = L.map('map').setView([latitudeCenter, longitudeCenter], mapZoomStart);
101
102 overlay = L.tileLayer('../webservice/tileserver.php?/index.json?/map/{z}/{x}/{y}.png', {
103 minZoom: mapZoomMin, maxZoom: mapZoomMax,
104 bounds: mapBounds,
105 attribution: 'undefined',opacity: 0.85
106 }).addTo(map);
107}
108
109function shutdown(){
110 $.getJSON("../webservice/?request=shutdown", function(data){
111 var shutdownTime = data["shutdownstart"];
112 var shutdownDate = Date.parse(shutdownTime);
113 var currentDate = new Date();
114 var shutdownHint = "Shutting down in "+ Math.floor((shutdownDate - currentDate)/1000) +"s at "+ shutdownTime.toLocaleString();
115 if(shutdownTime == -1){
116 shutdownHint = "Failed to initiate shutdown!";
117 }
118 $("#shutdownMessage").text(shutdownHint);
119 });
120}
121
122$(document).ready(function() {
123 displayDataGet();
124 setInterval(displayDataGet, 10000);
125
126 $.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
127
128 $("#shutdownButton").click(shutdown);
129});
Note: See TracBrowser for help on using the repository browser.