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

0.5 app-cordova debian/bullseye debian/jessie
Last change on this file since f8dfbe7 was f8dfbe7, checked in by Joachim Langenbach <joachim.langenbach@…>, 10 years ago
  • Added GPS position to webservice output
    • Added position returned by webservice to the polyline (not tested yet!)

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

  • Property mode set to 100644
File size: 3.1 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 points = [];
24var polyline;
25
26function openLink(target){
27 window.location=target;
28}
29
30function displayDataSet(data){
31 $("#display #speedthroughwater #value").text(data["speedthroughwater"].toString());
32 $("#display #speedoverground #value").text(data["speedoverground"].toString());
33 $("#display #waterdepth #value").text(data["waterdepth"].toString());
34 $("#display #watertemperature #value").text(Math.round(data["watertemperature"]).toString());
35 $("#display #gps #value").text(data["gpsfix"]);
36
37 var latitude = data["latitude"];
38 var longitude = data["longitude"];
39 if(latitude && longitude){
40 if(points.length > 0){
41 var lastPoint = points[points.length - 1];
42 if(lastPoint.lat != latitude || lastPoint.lng != longitude){
43 points.push(new L.latLng(latitude, longitude));
44 console.log(points);
45 polyline.setLatLngs(points);
46 map.fitBounds(polyline.getBounds());
47 }
48 }
49 }
50}
51
52function displayDataGet() {
53 var gnuboatApi = "../webservice/";
54 $.getJSON( gnuboatApi, displayDataSet);
55}
56
57function mapSetup(data){
58 var overlay;
59 var latitudeTop = data["bounds"][3];
60 var latitudeBottom = data["bounds"][1];
61 var longitudeLeft = data["bounds"][0];
62 var longitudeRight = data["bounds"][2];
63
64 var mapZoomMin = data["minzoom"];
65 var mapZoomMax = data["maxzoom"];
66
67 var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
68 var longitudeCenter = (longitudeLeft - longitudeRight)/2 + longitudeRight;
69 var mapZoomStart = (mapZoomMax - mapZoomMin)/2 + mapZoomMin;
70
71 var mapBounds = new L.LatLngBounds(
72 new L.LatLng(latitudeBottom, longitudeLeft),
73 new L.LatLng(latitudeTop, longitudeRight));
74
75 map = L.map('map').setView([latitudeCenter, longitudeCenter], mapZoomStart);
76
77 overlay = L.tileLayer('../webservice/tileserver.php?/index.json?/map/{z}/{x}/{y}.png', {
78 minZoom: mapZoomMin, maxZoom: mapZoomMax,
79 bounds: mapBounds,
80 attribution: 'undefined',opacity: 0.85
81 }).addTo(map);
82
83 points.push(new L.latLng(47.5914051, 10.710862));
84 points.push(new L.latLng(47.576667, 10.735278));
85 polyline = L.polyline(points, {color: 'red'}).addTo(map);
86}
87
88$(document).ready(function() {
89 displayDataGet();
90 setInterval(displayDataGet, 5000);
91
92 $.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
93});
Note: See TracBrowser for help on using the repository browser.