1
|
var mymap;
|
2
|
var heatmapLayer = null;
|
3
|
|
4
|
var startX = 49.7248;
|
5
|
var startY = 13.3521;
|
6
|
var startZoom = 17;
|
7
|
|
8
|
var currentTime = 0;
|
9
|
|
10
|
|
11
|
function initMap() {
|
12
|
mymap = L.map('heatmap').setView([startX, startY], startZoom);
|
13
|
|
14
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
15
|
attribution: '',
|
16
|
maxZoom: 19
|
17
|
}).addTo(mymap);
|
18
|
}
|
19
|
|
20
|
|
21
|
function setMapView(latitude = startX, longitude = startY, zoom = startZoom) {
|
22
|
mymap.setView([latitude, longitude], zoom);
|
23
|
}
|
24
|
|
25
|
|
26
|
function changeTime(direction, max = 0) {
|
27
|
let time = document.getElementById('time');
|
28
|
|
29
|
if (direction === 'next') {
|
30
|
currentTime += 1;
|
31
|
|
32
|
if (currentTime > 23) {
|
33
|
currentTime = 0;
|
34
|
}
|
35
|
}
|
36
|
else if (direction === 'prev') {
|
37
|
currentTime -= 1;
|
38
|
|
39
|
if (currentTime < 0) {
|
40
|
currentTime = 23;
|
41
|
}
|
42
|
}
|
43
|
|
44
|
time.textContent = currentTime + ":00";
|
45
|
time.className = 'time hour-' + currentTime;
|
46
|
}
|
47
|
|
48
|
|
49
|
function animateTimeline() {
|
50
|
setTimeout(
|
51
|
function () {
|
52
|
if (currentTime < 23) {
|
53
|
animateTimeline();
|
54
|
changeTime('next');
|
55
|
}
|
56
|
else {
|
57
|
changeTime('next');
|
58
|
}
|
59
|
}, 400);
|
60
|
}
|
61
|
|
62
|
function showHeatmap(route) {
|
63
|
|
64
|
var name = $('#type').children("option:selected").text();
|
65
|
var parts = $('#date').val().split('-');
|
66
|
var date = parts[2] + parts[1] + parts[0];
|
67
|
var time = $('#time').children("option:selected").val();
|
68
|
|
69
|
$.ajax({
|
70
|
type: "POST",
|
71
|
url: route + '/' + name + '/' + date + '/' + time,
|
72
|
success: function(result) {
|
73
|
drawHeatmap(result);
|
74
|
}
|
75
|
});
|
76
|
}
|
77
|
|
78
|
|
79
|
function drawHeatmap(points) {
|
80
|
|
81
|
// Todo still switched
|
82
|
points = points.map(function (p) { return [p['y'], p['x'], p['number']]; });
|
83
|
if (heatmapLayer != null) {
|
84
|
mymap.removeLayer(heatmapLayer);
|
85
|
}
|
86
|
heatmapLayer = L.heatLayer(points, {opacity: 0.5}).addTo(mymap);
|
87
|
heatmapLayer.options = {opacity: 1};
|
88
|
// var heat_01 = ...
|
89
|
// on background map.addLayer(heat_01) -> map.removeLayer(heat_01);
|
90
|
// $(.leaflet-heatmap-layer).css('opacity', 'value');
|
91
|
}
|
92
|
|
93
|
function checkDataSetsAvailability(route) {
|
94
|
|
95
|
var parts = $('#date').val().split('-');
|
96
|
|
97
|
$.ajax({
|
98
|
type: "POST",
|
99
|
// Todo it might be good idea to change db collections format
|
100
|
url: route + '/' + parts[2] + parts[1] + parts[0],
|
101
|
success: function(result) {
|
102
|
updateAvailableDataSets(result);
|
103
|
}
|
104
|
});
|
105
|
}
|
106
|
|
107
|
function updateAvailableDataSets(available) {
|
108
|
|
109
|
var options = '';
|
110
|
|
111
|
Object.entries(available).forEach(([key, value]) => {
|
112
|
options += '<option value="' + value + '">' + key + '</option>\n';
|
113
|
});
|
114
|
|
115
|
$('#type').empty().append(options);
|
116
|
|
117
|
}
|