| 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 |
|
|---|
| 22 | var map;
|
|---|
| 23 | var polyline;
|
|---|
| 24 |
|
|---|
| 25 | function openLink(target){
|
|---|
| 26 | window.location=target;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | function 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 | 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 | }
|
|---|
| 50 |
|
|---|
| 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 | }
|
|---|
| 60 | if(points.length > 0){
|
|---|
| 61 | if(!polyline){
|
|---|
| 62 | polyline = L.polyline(points, {color: 'red'}).addTo(map);
|
|---|
| 63 | }
|
|---|
| 64 | else{
|
|---|
| 65 | polyline.setLatLngs(points);
|
|---|
| 66 | }
|
|---|
| 67 | map.fitBounds(polyline.getBounds());
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | function displayDataGet() {
|
|---|
| 73 | var gnuboatApi = "../webservice/";
|
|---|
| 74 | $.getJSON( gnuboatApi, displayDataSet);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | function mapSetup(data){
|
|---|
| 78 | var overlay;
|
|---|
| 79 | var latitudeTop = data["bounds"][3];
|
|---|
| 80 | var latitudeBottom = data["bounds"][1];
|
|---|
| 81 | var longitudeLeft = data["bounds"][0];
|
|---|
| 82 | var longitudeRight = data["bounds"][2];
|
|---|
| 83 |
|
|---|
| 84 | var mapZoomMin = data["minzoom"];
|
|---|
| 85 | var mapZoomMax = data["maxzoom"];
|
|---|
| 86 |
|
|---|
| 87 | var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
|
|---|
| 88 | var longitudeCenter = (longitudeLeft - longitudeRight)/2 + longitudeRight;
|
|---|
| 89 | var mapZoomStart = (mapZoomMax - mapZoomMin)/2 + mapZoomMin;
|
|---|
| 90 |
|
|---|
| 91 | var mapBounds = new L.LatLngBounds(
|
|---|
| 92 | new L.LatLng(latitudeBottom, longitudeLeft),
|
|---|
| 93 | new L.LatLng(latitudeTop, longitudeRight));
|
|---|
| 94 |
|
|---|
| 95 | map = L.map('map').setView([latitudeCenter, longitudeCenter], mapZoomStart);
|
|---|
| 96 |
|
|---|
| 97 | overlay = L.tileLayer('../webservice/tileserver.php?/index.json?/map/{z}/{x}/{y}.png', {
|
|---|
| 98 | minZoom: mapZoomMin, maxZoom: mapZoomMax,
|
|---|
| 99 | bounds: mapBounds,
|
|---|
| 100 | attribution: 'undefined',opacity: 0.85
|
|---|
| 101 | }).addTo(map);
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | $(document).ready(function() {
|
|---|
| 105 | displayDataGet();
|
|---|
| 106 | setInterval(displayDataGet, 5000);
|
|---|
| 107 |
|
|---|
| 108 | $.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
|
|---|
| 109 | });
|
|---|