-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
290 lines (253 loc) · 10.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Locus - Wer ist Wo?</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex, nofollow, noarchive" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link type="image/ico" rel="shortcut icon" href="/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<style type="text/css">
<!--
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
}
-->
</style>
</head>
<body>
<div id="map" style="width: 100%; height: 100%;"></div>
<script type="text/javascript">
/*** Adjust the following location (URL) to your PHP script ***/
var phpScript = 'latrine.php'; // /cgi-bin/latrine.php
/*** If you've got an API Key for https://www.thunderforest.com/maps/ add it here and uncomment ***/
// var TFkey = 'put_your_key_here_and_uncomment';
/*** Change the following only if you know what you're doing ***/
// Initialize some Variables
var lastspeed = 0;
var lastalt = 0;
var center = 0;
var autoPan = 1;
// Maps
//
// OpenStreetMap
var osmUrl = 'https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', // http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png
osmAttribution = 'Map © <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap Contributors</a> (<a href="http://creativecommons.org/licenses/by-sa/2.0/" target="_blank">CC-by-SA 2.0</a>)',
osm = new L.TileLayer(osmUrl, {maxZoom: 18, attribution: osmAttribution});
// Thunderforest - OpenCycleMap
var cyclemapUrl = "https://tile.thunderforest.com/cycle/{z}/{x}/{y}{r}.png"
+ ( typeof TFkey !== "undefined" ? "?apikey=" + TFkey : "" ),
cyclemapAttribution = 'Maps © <a href="https://www.thunderforest.com" target="_blank">Thunderforest</a>, Data © <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap Contributors</a>',
cyclemap = new L.TileLayer(cyclemapUrl, {maxZoom: 18, attribution: cyclemapAttribution});
// Thunderforest - Outdoors
var outdoorsmapUrl = "https://tile.thunderforest.com/outdoors/{z}/{x}/{y}{r}.png"
+ ( typeof TFkey !== "undefined" ? "?apikey=" + TFkey : "" ),
outdoorsmap = new L.TileLayer(outdoorsmapUrl, {maxZoom: 18, attribution: cyclemapAttribution});
// Thunderforest - Outdoors
var landscapemapUrl = "https://tile.thunderforest.com/landscape/{z}/{x}/{y}{r}.png"
+ ( typeof TFkey !== "undefined" ? "?apikey=" + TFkey : "" ),
landscapemap = new L.TileLayer(landscapemapUrl, {maxZoom: 18, attribution: cyclemapAttribution});
// OpentopoMap
var opentopoUrl = 'https://b.tile.opentopomap.org/{z}/{x}/{y}.png',
opentopoAttribution = 'Map © <a href="https://opentopomap.org/copyright" target="_blank">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/" target="_blank">CC-BY-SA</a>)',
opentopo = new L.TileLayer(opentopoUrl, {maxZoom: 18, attribution: opentopoAttribution});
// Hike and Bike
var hikebikeUrl = 'http://{s}.tiles.wmflabs.org/hikebike/{z}/{x}/{y}.png',
hikebike = new L.TileLayer(hikebikeUrl, {maxZoom: 18, attribution: osmAttribution});
// ESRI
var esriUrl = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}.png',
esriAttribution = "National Geographic, Esri, DeLorme, NAVTEQ",
esri = new L.TileLayer(esriUrl, {maxZoom: 16, attribution: esriAttribution});
// Googly Hybrid
var googleUrl = 'https://mts.google.com/vt/lyrs=y&x={x}&y={y}&z={z}',
googleAttribution = "(c)2015 Google - Map data",
google = new L.TileLayer(googleUrl, {maxZoom: 28, attribution: googleAttribution});
// Shaders
//
// Hillshading
var hillshadingUrl = 'http://{s}.tiles.wmflabs.org/hillshading/{z}/{x}/{y}.png',
hillshadingAttribution = 'Hillshading: SRTM3 v2 <a href="http://www2.jpl.nasa.gov/srtm/" target="_blank">(NASA)</a>',
hillshading = new L.TileLayer(hillshadingUrl, {maxZoom: 18, attribution: hillshadingAttribution});
// Contour Lines
var contourshadingUrl = 'http://129.206.66.245:8006/tms_il.ashx?x={x}&y={y}&z={z}',
contourshadingAttribution = 'Contour Data by <a href="http://korona.geog.uni-heidelberg.de/contact.html" target="_blank">Korona</a>',
contourshading = new L.TileLayer(contourshadingUrl, {maxZoom: 18, attribution: contourshadingAttribution});
// Waymarked
var waymarkedshadinghikeUrl = 'http://tile.waymarkedtrails.org/hiking/{z}/{x}/{y}.png',
waymarkedshadinghikeAttribution = 'Trails Data by <a href="http://www.waymarkedtrails.org" target="_blank">Waymarkedtrails</a>',
waymarkedshadinghike = new L.TileLayer(waymarkedshadinghikeUrl, {maxZoom: 18, attribution: waymarkedshadinghikeAttribution});
// Waymarked
var waymarkedshadingbikeUrl = 'http://tile.waymarkedtrails.org/cycling/{z}/{x}/{y}.png',
waymarkedshadingbikeAttribution = 'Trails Data by <a href="http://www.waymarkedtrails.org" target="_blank">Waymarkedtrails</a>',
waymarkedshadingbike = new L.TileLayer(waymarkedshadingbikeUrl, {maxZoom: 18, attribution: waymarkedshadingbikeAttribution});
var baseMaps = {
"OpenStreetMap": osm,
"TF-OpenCycleMap": cyclemap,
"TF-OutdoorsMap": outdoorsmap,
"TF-LandscapeeMap": landscapemap,
"OpenTopoMap": opentopo,
"Hike & Bike": hikebike,
"Google Hybrid": google,
"ESRI": esri
};
var overlayMaps = {
"Hillshading": hillshading,
"Trails": waymarkedshadinghike,
"Radrouten": waymarkedshadingbike,
"Contour Lines": contourshading
};
var layersControl = new L.Control.Layers(baseMaps, overlayMaps);
// Set default until the first update
var map = new L.Map('map', {
center: new L.LatLng(51.4768, 0.0006),
zoom: 14,
layers: [osm]
});
map.addControl(layersControl);
var marker = L.marker([51.4768, 0.0006]);
marker.addTo(map);
marker.bindPopup("<b>Derzeit nicht auf Sendung</b>").openPopup();
var circle = L.circle([51.4768, 0.0006], 100, {
color: 'blue',
fillColor: '#f03',
fillOpacity: 0.5
}).addTo(map);
// Create Auto-Pan control for to switch auto panning of map on/off
var AutoPanCheckbox = L.control({position: 'topright'});
AutoPanCheckbox.onAdd = function (map) {
var div = L.DomUtil.create('div', 'AutoPanCheckbox');
div.innerHTML = '<b><form><input id="AutoPanCheckbox" type="checkbox"/>Auto-Pan</form></b>';
return div;
};
AutoPanCheckbox.addTo(map);
document.getElementById("AutoPanCheckbox").checked = true;
// Add the event handler so that panning gets (de-)activated
function handleAutoPan() {
if (this.checked == 1) {
autoPan = 1;
} else {
autoPan = 0;
}
// alert("Clicked, checked = " + this.checked + " / " + autoPan);
};
document.getElementById ("AutoPanCheckbox").addEventListener ("click", handleAutoPan, false);
// Check private key
var key = window.location.hash.substring(1);
if (!key.match(/^[\w\d]{5,15}$/)) {
Check = prompt('Schlüssel (5-15 Stellen)?','');
if (!Check.match(/^[\w\d]{5,15}$/)) {
window.alert('Bitte richtigen Schlüssel angeben');
key = '';
} else {
key = Check;
window.alert('Hallo, ' + key + ' ! \nDies ist ein gültiger Schlüssel?\n\nIhr direkter Link lautet:\nhttp://<server>/#' + key + '');
}
} else {
window.alert('Hallo, ' + key + ' ! \nDies ist ein gültiger Schlüssel?');
}
// Fetch latlon data and update marker and popup-data
var refreshPos = function(){
$.getJSON(phpScript+'?view=1&key='+key+'', function(data) {
//alert(JSON.stringify(data)); // Output Data for debug
marker.setLatLng([data.lat,data.lon]);
circle.setLatLng([data.lat,data.lon]);
circle.setRadius(data.acc);
// Center the map on first load
if (center < 1) {
map.setView( [data.lat,data.lon], 15 )
center = 1;
}
// Calculate the time of last update
var lastupdate = data.now - data.time;
var minutes = Math.floor(lastupdate / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
var seconds = lastupdate % 60;
minutes = minutes - hours * 60;
hours = hours - days * 24;
minutes = minutes < 9 ? "0"+minutes : minutes;
seconds = seconds < 9 ? "0"+seconds : seconds;
/* Housekeeping (Obsolet, done in latrine.php)
if (lastupdate > 24*60*60) { // 24 Stunden: 24*60*60
alert('Lösche')
$.post(phpScript+'?delete=1&key='+key);
}
*/
// Update popup
var popUpText = '<p>Letzte Position: ' + days + 'd :' + hours + 'h :' + minutes + 'm :' + seconds + 's<br>';
// Calculate speed (m/sec -> km/h ...)
var kmh = data.speed * 3.6;
var psec = 3600 / kmh;
var pmin = psec / 60;
pmin = Math.floor(pmin);
var psek = psec - pmin * 60;
var trend = "\u2192";
var trendH = "\u2192";
if (data.speed == 0) {
var pmin = 0;
var psek = 0;
}
// Faster or slower?
if (data.speed > lastspeed) {
trend = "\u2191";
}
if (data.speed < lastspeed) {
trend = "\u2193";
}
speeddiff = data.speed - lastspeed;
lastspeed = data.speed;
// Higher or lower?
if (data.alt > lastalt) {
trendH = "\u2191";
};
if (data.alt < lastalt) {
trendH = "\u2193";
}
altdiff = data.alt - lastalt;
lastalt = data.alt;
// Expand popup
popUpText = popUpText + '<b>'+ key + '</b>: ' + data.message + '<br/>'
+ '(Akku: ' + data.battery + '% / GSM: ' + data.gsm_signal + '%)<br/></p>'
+ '<p>Speed ( ' + trend + ' ) / Diff: ' + speeddiff + ' m/s<br/>'
+ kmh.toFixed(2) + ' km/h<br/>'
+ data.speed + ' m/s<br/>'
+ pmin.toFixed() + ':' + psek.toFixed() +' min/km<br/>'
+ '<br/>'
+ 'Richtung: ' + data.bearing + ' Grad<br/>'
+ 'Höhe ( '+ trendH + ' ): ' + data.alt + ' m, Diff: ' + altdiff.toFixed(1) + ' m<br/>';
+ '</p>';
if (autoPan == 1) {
map.panTo( [data.lat,data.lon] );
}
marker.setPopupContent(popUpText);
})
};
// Fetch geojson data and update path on map
var refreshGeo = function(){
$.getJSON(phpScript+'?geo=1&key='+key+'', function(data) {
if (data.error) { alert('Error: ' + data.error) }
var myPath = L.geoJson(data, {
style: {
color: '#ff0000',
weight: 5,
opacity: 1
}
}).addTo(map);
});
};
// Refresh
refreshPos();
refreshGeo();
setInterval(refreshPos,5000); // 5 sec
//setInterval(refreshPos,50000); // 50 sec
//setInterval(refreshGeo,100000); // 100 sec
setInterval(refreshGeo,5000); // 5 sec
</script>