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

0.5 app-cordova debian/bullseye debian/jessie
Last change on this file since ed749dc was 4ab1c0a, checked in by Joachim Langenbach <joachim.langenbach@…>, 10 years ago
  • Added gnuboat python script, which collects the data from gpsd into a rrd database for the webservice
    • Adapted the webservice
    • Adapted the webclient

Signed-off-by: Joachim Langenbach <joachim.langenbach@…>

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[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]22var map;
23var polyline;
24
[d7e6e9c]25function openLink(target){
26 window.location=target;
27}
28
29function 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)){
40 if(key == "watertemperature"){
41 value = Math.round(value);
42 }
43 $("#display #"+ keys[i] +" #value").text(value.toString());
44 }
45 else if(key == "gpsfix"){
46 $("#display #"+ keys[i] +" #value").text(value);
47 }
48 }
49 }
[f8dfbe7]50
[4ab1c0a]51 if(!("track" in data)){
52 console.log("No track given!");
53 }
54 else{
55 var track = data["track"];
56 var points = [];
57 for(var time in track){
58 points.push(new L.latLng(track[time]["latitude"], track[time]["longitude"]));
59 }
[f8dfbe7]60 if(points.length > 0){
[4ab1c0a]61 if(!polyline){
62 polyline = L.polyline(points, {color: 'red'}).addTo(map);
63 }
64 else{
[f8dfbe7]65 polyline.setLatLngs(points);
66 }
[4ab1c0a]67 map.fitBounds(polyline.getBounds());
[f8dfbe7]68 }
69 }
[d7e6e9c]70}
71
72function displayDataGet() {
[6f38643]73 var gnuboatApi = "../webservice/";
[d7e6e9c]74 $.getJSON( gnuboatApi, displayDataSet);
75}
76
[6f38643]77function mapSetup(data){
78 var overlay;
79 var latitudeTop = data["bounds"][3];
[f8dfbe7]80 var latitudeBottom = data["bounds"][1];
[6f38643]81 var longitudeLeft = data["bounds"][0];
[f8dfbe7]82 var longitudeRight = data["bounds"][2];
83
84 var mapZoomMin = data["minzoom"];
85 var mapZoomMax = data["maxzoom"];
[6f38643]86
87 var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
88 var longitudeCenter = (longitudeLeft - longitudeRight)/2 + longitudeRight;
[f8dfbe7]89 var mapZoomStart = (mapZoomMax - mapZoomMin)/2 + mapZoomMin;
90
[6f38643]91 var mapBounds = new L.LatLngBounds(
[f8dfbe7]92 new L.LatLng(latitudeBottom, longitudeLeft),
93 new L.LatLng(latitudeTop, longitudeRight));
94
95 map = L.map('map').setView([latitudeCenter, longitudeCenter], mapZoomStart);
[6f38643]96
97 overlay = L.tileLayer('../webservice/tileserver.php?/index.json?/map/{z}/{x}/{y}.png', {
[f8dfbe7]98 minZoom: mapZoomMin, maxZoom: mapZoomMax,
[6f38643]99 bounds: mapBounds,
100 attribution: 'undefined',opacity: 0.85
[f8dfbe7]101 }).addTo(map);
[6f38643]102}
103
[d7e6e9c]104$(document).ready(function() {
105 displayDataGet();
106 setInterval(displayDataGet, 5000);
[6f38643]107
108 $.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
[d7e6e9c]109});
Note: See TracBrowser for help on using the repository browser.