-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
141 lines (129 loc) · 5 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
<html>
<head>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
<script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"
crossorigin=""/>
<style>
#mapid {
height: 400px;
}
#slider {
margin: 10px;
}
.first-marker {
background-color: #f00;
width: 5rem;
height: 5rem;
position: absolute;
border-radius: 5rem 5rem 0;
transform: rotate(45deg);
border: 1px solid #fff;
}
.rest-marker {
background-color: #00f;
width: 3rem;
height: 3rem;
position: absolute;
border-radius: 3rem 3rem 0;
transform: rotate(45deg);
border: 1px solid #fff;
}
</style>
</head>
<body>
<div id="mapid"></div>
<div id="slider"></div>
<input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
<script>
var mindate;
var daysrange;
var markerLayer;
var mymap = L.map('mapid').setView([52.52, 13.405], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(mymap);
markerLayer = new L.LayerGroup();
mymap.addLayer(markerLayer);
const firstIcon = L.divIcon({className: 'first-marker'});
const restIcon = L.divIcon({className: 'rest-marker'});
$.ajax('/cgi-bin/history.php').done(function(data) {
updateMarkers(data.slice(0, 10));
setMapView(data[0]);
});
$.ajax('/cgi-bin/range.php').done(function(data) {
mindate = Date.parse(data["lower"]);
var maxdate = Date.now();
daysrange = (maxdate - mindate)/(1000*60*60*24);
sliderPosition = (Date.parse(data["upper"]) - mindate)/(1000*60*60*24);
console.log("Max: " + daysrange + " position: " + sliderPosition);
$("#slider").slider({
range: true,
min: 0,
max: daysrange,
values: [ Math.max(sliderPosition - 7, 0), sliderPosition ],
slide: function( event, ui ) {
$("#amount").val(sliderPositionToDate(ui.values[0]) + " - " + sliderPositionToDate(ui.values[1]));
},
stop: function (event, ui) {
updateDataRange(ui.values[0], ui.values[1]);
},
});
$("#amount").val(sliderPositionToDate(Math.max(sliderPosition - 7, 0)) + " - " + sliderPositionToDate(sliderPosition));
});
function sliderPositionToDate(position) {
var date = mindate + (position * 1000*60*60*24);
return new Intl.DateTimeFormat('de').format(new Date(date));
}
function sliderPositionToSqlDate(position) {
var date = mindate + (position * 1000*60*60*24);
return new Date(date).toISOString().slice(0, 19).replace('T', ' ');
}
function updateDataRange(lowerPosition, upperPosition) {
$.ajax('/cgi-bin/history.php?from=' + sliderPositionToSqlDate(lowerPosition) + "&to=" + sliderPositionToSqlDate(upperPosition)).done(function(data) {
updateMarkers(data);
});
}
function setMapView(coordinate) {
console.log(`Long: ${coordinate.longitude} Lat: ${coordinate.latitude}`);
mymap.setView([coordinate.latitude, coordinate.longitude], 13);
}
function updateMarkers(data) {
var first = true;
markerLayer.clearLayers();
$.each(data, function(i, coordinate) {
if (coordinate.longitude < -10 || coordinate.longitude > 30 || coordinate.latitude < 20 || coordinate.latitde > 80) {
console.log("Skipping", coordinate);
return;
}
if (first) {
markerLayer.addLayer(L.marker([coordinate.latitude, coordinate.longitude], {icon: firstIcon}));
first = false;
} else {
markerLayer.addLayer(L.marker([coordinate.latitude, coordinate.longitude], {icon: restIcon}));
}
});
console.log(data);
}
</script>
</body>
</html>