1 |
64bc2934
|
vastja
|
var mymap;
|
2 |
03c02899
|
vastja
|
var heatmapLayer = null;
|
3 |
|
|
|
4 |
c236b33a
|
msebela
|
var startX = 49.7248;
|
5 |
|
|
var startY = 13.3521;
|
6 |
|
|
var startZoom = 17;
|
7 |
3fc08f2d
|
vastja
|
|
8 |
a48642fb
|
vastja
|
var dataSourceRoute;
|
9 |
|
|
var currentTime;
|
10 |
|
|
var name;
|
11 |
|
|
var date;
|
12 |
|
|
|
13 |
|
|
var timer;
|
14 |
|
|
var isAnimationRunning = false;
|
15 |
|
|
var data = [];
|
16 |
|
|
|
17 |
351696d5
|
Martin Sebela
|
|
18 |
|
|
|
19 |
c236b33a
|
msebela
|
function initMap() {
|
20 |
64bc2934
|
vastja
|
mymap = L.map('heatmap').setView([startX, startY], startZoom);
|
21 |
3fc08f2d
|
vastja
|
|
22 |
c236b33a
|
msebela
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
23 |
|
|
attribution: '',
|
24 |
|
|
maxZoom: 19
|
25 |
64bc2934
|
vastja
|
}).addTo(mymap);
|
26 |
3ae59f75
|
vastja
|
|
27 |
|
|
mymap.on('click', showInfo);
|
28 |
|
|
|
29 |
c236b33a
|
msebela
|
}
|
30 |
3fc08f2d
|
vastja
|
|
31 |
3ae59f75
|
vastja
|
var info = [];
|
32 |
|
|
var currenInfo = 0;
|
33 |
|
|
var infoLength = 0;
|
34 |
|
|
|
35 |
|
|
function showInfo(e) {
|
36 |
|
|
|
37 |
|
|
info = []
|
38 |
|
|
currenInfo = 0;
|
39 |
|
|
|
40 |
|
|
// https://wiki.openstreetmap.org/wiki/Zoom_levels
|
41 |
|
|
// Todo change to variable - it is used in heatmap init
|
42 |
|
|
var stile = 40075016.686 * Math.cos(startX) / Math.pow(2, mymap.getZoom()) ;
|
43 |
|
|
var radius = 25 * stile / 256;
|
44 |
|
|
|
45 |
|
|
var i = 0;
|
46 |
|
|
var lat = 0;
|
47 |
|
|
var lng = 0;
|
48 |
|
|
|
49 |
|
|
data[currentTime]['items'].forEach(element => {
|
50 |
|
|
if (e.latlng.distanceTo(new L.LatLng(element.x, element.y)) < radius) {
|
51 |
|
|
lat += element.x
|
52 |
|
|
lng += element.y;
|
53 |
|
|
info[i] = {'place' : element.place, 'number' : element.number};
|
54 |
|
|
i++;
|
55 |
|
|
}
|
56 |
|
|
});
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
if (info.length > 0) {
|
60 |
|
|
var popup = L.popup()
|
61 |
|
|
.setLatLng([lat / i, lng / i])
|
62 |
|
|
.setContent('<div id=\'place-info\'>Umístění: ' + info[currenInfo].place + '</div>' +
|
63 |
|
|
'<div id=\'number-info\'>Počet: ' + info[currenInfo].number + '</div>' +
|
64 |
|
|
'<div class=\'popup-controls\'>' +
|
65 |
|
|
'<button id=\'previous-info-btn\' onclick=\'previousInfo()\'><</button>' +
|
66 |
|
|
'<div id=\'count-info\'>' + (currenInfo + 1) + '/' + info.length + '</div>' +
|
67 |
|
|
'<button id=\'next-info-btn\' onclick=\'nextInfo()\'>></button>' +
|
68 |
|
|
'</div>'
|
69 |
|
|
)
|
70 |
|
|
.openOn(mymap);
|
71 |
|
|
|
72 |
|
|
if (info.length == 1) {
|
73 |
|
|
$('#previous-info-btn').prop('disabled', true);
|
74 |
|
|
$('#next-info-btn').prop('disabled', true);
|
75 |
|
|
$('.popup-controls').hide();
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
function previousInfo() {
|
82 |
|
|
currenInfo = (currenInfo + info.length - 1) % info.length;
|
83 |
|
|
displayInfoText();
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
function nextInfo() {
|
87 |
|
|
currenInfo = (currenInfo + 1) % info.length
|
88 |
|
|
displayInfoText();
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
function displayInfoText() {
|
92 |
|
|
$('#place-info').html('Umístění: ' + info[currenInfo].place)
|
93 |
|
|
$('#number-info').html('Počet: ' + info[currenInfo].number)
|
94 |
|
|
$('#count-info').html(currenInfo + 1 + '/' + info.length);
|
95 |
|
|
}
|
96 |
351696d5
|
Martin Sebela
|
|
97 |
c236b33a
|
msebela
|
function setMapView(latitude = startX, longitude = startY, zoom = startZoom) {
|
98 |
64bc2934
|
vastja
|
mymap.setView([latitude, longitude], zoom);
|
99 |
3fc08f2d
|
vastja
|
}
|
100 |
|
|
|
101 |
a48642fb
|
vastja
|
function changeAnimationState() {
|
102 |
|
|
|
103 |
|
|
isAnimationRunning = !isAnimationRunning
|
104 |
|
|
if (isAnimationRunning) {
|
105 |
|
|
$('#play-pause').attr('class', 'pause');
|
106 |
|
|
timer = setInterval(
|
107 |
|
|
function() {
|
108 |
3ae59f75
|
vastja
|
mymap.closePopup();
|
109 |
a48642fb
|
vastja
|
next();
|
110 |
|
|
},
|
111 |
|
|
800
|
112 |
|
|
);
|
113 |
351696d5
|
Martin Sebela
|
}
|
114 |
a48642fb
|
vastja
|
else {
|
115 |
|
|
clearTimeout(timer);
|
116 |
|
|
$('#play-pause').attr('class', 'play');
|
117 |
351696d5
|
Martin Sebela
|
}
|
118 |
|
|
|
119 |
a48642fb
|
vastja
|
|
120 |
351696d5
|
Martin Sebela
|
}
|
121 |
|
|
|
122 |
a48642fb
|
vastja
|
function previous() {
|
123 |
|
|
currentTime = (currentTime + 23) % 24;
|
124 |
|
|
drawHeatmap(data[currentTime]);
|
125 |
|
|
setTimeline();
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
function next() {
|
129 |
|
|
currentTime = (currentTime + 1) % 24;
|
130 |
|
|
drawHeatmap(data[currentTime]);
|
131 |
|
|
setTimeline();
|
132 |
|
|
}
|
133 |
351696d5
|
Martin Sebela
|
|
134 |
a48642fb
|
vastja
|
function setTimeline() {
|
135 |
|
|
$('#timeline').text(currentTime + ":00");
|
136 |
|
|
$('#timeline').attr('class', 'time hour-' + currentTime);
|
137 |
351696d5
|
Martin Sebela
|
}
|
138 |
|
|
|
139 |
a48642fb
|
vastja
|
function loadCurrentTimeHeatmap(route) {
|
140 |
64bc2934
|
vastja
|
|
141 |
a48642fb
|
vastja
|
dataSourceRoute = route;
|
142 |
|
|
data = []
|
143 |
|
|
|
144 |
|
|
name = $('#type').children("option:selected").text();
|
145 |
64bc2934
|
vastja
|
var parts = $('#date').val().split('-');
|
146 |
a48642fb
|
vastja
|
date = parts[2] + parts[1] + parts[0];
|
147 |
|
|
currentTime = parseInt($('#time').children("option:selected").val());
|
148 |
|
|
setTimeline();
|
149 |
351696d5
|
Martin Sebela
|
|
150 |
c236b33a
|
msebela
|
$.ajax({
|
151 |
|
|
type: "POST",
|
152 |
a48642fb
|
vastja
|
url: dataSourceRoute + '/' + name + '/' + date + '/' + currentTime,
|
153 |
c236b33a
|
msebela
|
success: function(result) {
|
154 |
a48642fb
|
vastja
|
data[currentTime] = result;
|
155 |
|
|
drawHeatmap(data[currentTime]);
|
156 |
c236b33a
|
msebela
|
}
|
157 |
|
|
});
|
158 |
a48642fb
|
vastja
|
|
159 |
|
|
preload(currentTime, 1);
|
160 |
|
|
preload(currentTime, -1);
|
161 |
|
|
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
function preload(time, change) {
|
165 |
|
|
|
166 |
|
|
var ntime = time + change;
|
167 |
|
|
if (0 <= ntime && ntime <= 23) {
|
168 |
|
|
$.ajax({
|
169 |
|
|
type: "POST",
|
170 |
|
|
url: dataSourceRoute + '/' + name + '/' + date + '/' + ntime,
|
171 |
|
|
success: function(result) {
|
172 |
|
|
data[ntime] = result;
|
173 |
|
|
preload(ntime, change);
|
174 |
|
|
}
|
175 |
|
|
});
|
176 |
|
|
}
|
177 |
|
|
|
178 |
3fc08f2d
|
vastja
|
}
|
179 |
|
|
|
180 |
351696d5
|
Martin Sebela
|
|
181 |
3ae59f75
|
vastja
|
function drawHeatmap(data) {
|
182 |
03c02899
|
vastja
|
|
183 |
|
|
// Todo still switched
|
184 |
3ae59f75
|
vastja
|
if (data['items'] != null) {
|
185 |
|
|
points = data['items'].map(function (p) { return [p['x'], p['y'], p['number']]; });
|
186 |
a48642fb
|
vastja
|
if (heatmapLayer != null) {
|
187 |
|
|
mymap.removeLayer(heatmapLayer);
|
188 |
|
|
}
|
189 |
3fc22d29
|
Martin Sebela
|
heatmapLayer = L.heatLayer(points, {'max' : data['max'], 'minOpacity' : 0.5, 'radius' : 35, 'blur' : 30}).addTo(mymap);
|
190 |
03c02899
|
vastja
|
}
|
191 |
a48642fb
|
vastja
|
else {
|
192 |
|
|
if (heatmapLayer != null) {
|
193 |
|
|
mymap.removeLayer(heatmapLayer);
|
194 |
|
|
}
|
195 |
|
|
}
|
196 |
|
|
|
197 |
03c02899
|
vastja
|
// var heat_01 = ...
|
198 |
|
|
// on background map.addLayer(heat_01) -> map.removeLayer(heat_01);
|
199 |
64bc2934
|
vastja
|
// $(.leaflet-heatmap-layer).css('opacity', 'value');
|
200 |
03c02899
|
vastja
|
}
|
201 |
3fc08f2d
|
vastja
|
|
202 |
03c02899
|
vastja
|
function checkDataSetsAvailability(route) {
|
203 |
|
|
|
204 |
|
|
var parts = $('#date').val().split('-');
|
205 |
|
|
|
206 |
|
|
$.ajax({
|
207 |
|
|
type: "POST",
|
208 |
|
|
// Todo it might be good idea to change db collections format
|
209 |
|
|
url: route + '/' + parts[2] + parts[1] + parts[0],
|
210 |
|
|
success: function(result) {
|
211 |
|
|
updateAvailableDataSets(result);
|
212 |
|
|
}
|
213 |
|
|
});
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
function updateAvailableDataSets(available) {
|
217 |
|
|
|
218 |
0919408a
|
vastja
|
var options = '';
|
219 |
|
|
|
220 |
|
|
Object.entries(available).forEach(([key, value]) => {
|
221 |
|
|
options += '<option value="' + value + '">' + key + '</option>\n';
|
222 |
|
|
});
|
223 |
03c02899
|
vastja
|
|
224 |
64bc2934
|
vastja
|
$('#type').empty().append(options);
|
225 |
03c02899
|
vastja
|
|
226 |
|
|
}
|