source: src/webapp/webclient/javascript/main.js@ 71df8a6

debian/bullseye debian/jessie
Last change on this file since 71df8a6 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
RevLine 
[d7e6e9c]1/*
2
[33c6557]3 Copyright (C) 2016 - 2017 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]22var map;
23var polyline;
24
[d7e6e9c]25function openLink(target){
26 window.location=target;
27}
28
29function displayDataSet(data){
[c61b79b]30 if(!Array.isArray(data)){
31 console.log("No data array returned!");
32 return;
33 }
[4ab1c0a]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)){
[5149714]44 var text = value.toFixed(1);
[4ab1c0a]45 if(key == "watertemperature"){
[5149714]46 text = value.toFixed(0);
[4ab1c0a]47 }
[5149714]48 $("#display #"+ keys[i] +" #value").text(text);
[4ab1c0a]49 }
50 else if(key == "gpsfix"){
51 $("#display #"+ keys[i] +" #value").text(value);
52 }
53 }
54 }
[f8dfbe7]55
[4ab1c0a]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 }
[f8dfbe7]65 if(points.length > 0){
[4ab1c0a]66 if(!polyline){
67 polyline = L.polyline(points, {color: 'red'}).addTo(map);
68 }
69 else{
[f8dfbe7]70 polyline.setLatLngs(points);
71 }
[4ab1c0a]72 map.fitBounds(polyline.getBounds());
[f8dfbe7]73 }
74 }
[d7e6e9c]75}
76
77function displayDataGet() {
[6f38643]78 var gnuboatApi = "../webservice/";
[d7e6e9c]79 $.getJSON( gnuboatApi, displayDataSet);
80}
81
[6f38643]82function mapSetup(data){
83 var overlay;
84 var latitudeTop = data["bounds"][3];
[f8dfbe7]85 var latitudeBottom = data["bounds"][1];
[6f38643]86 var longitudeLeft = data["bounds"][0];
[f8dfbe7]87 var longitudeRight = data["bounds"][2];
88
89 var mapZoomMin = data["minzoom"];
90 var mapZoomMax = data["maxzoom"];
[6f38643]91
92 var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
93 var longitudeCenter = (longitudeLeft - longitudeRight)/2 + longitudeRight;
[f8dfbe7]94 var mapZoomStart = (mapZoomMax - mapZoomMin)/2 + mapZoomMin;
95
[6f38643]96 var mapBounds = new L.LatLngBounds(
[f8dfbe7]97 new L.LatLng(latitudeBottom, longitudeLeft),
98 new L.LatLng(latitudeTop, longitudeRight));
99
100 map = L.map('map').setView([latitudeCenter, longitudeCenter], mapZoomStart);
[6f38643]101
102 overlay = L.tileLayer('../webservice/tileserver.php?/index.json?/map/{z}/{x}/{y}.png', {
[f8dfbe7]103 minZoom: mapZoomMin, maxZoom: mapZoomMax,
[6f38643]104 bounds: mapBounds,
105 attribution: 'undefined',opacity: 0.85
[f8dfbe7]106 }).addTo(map);
[6f38643]107}
108
[5519ced]109function shutdown(){
110 $.getJSON("../webservice/?request=shutdown", function(data){
111 var shutdownTime = data["shutdownstart"];
[d7ee6ae]112 var shutdownDate = Date.parse(shutdownTime);
[5519ced]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
[d7e6e9c]122$(document).ready(function() {
123 displayDataGet();
[33c6557]124 setInterval(displayDataGet, 10000);
[c84f87e]125
[6f38643]126 $.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
[5519ced]127
128 $("#shutdownButton").click(shutdown);
[d7e6e9c]129});
Note: See TracBrowser for help on using the repository browser.