1 |
8feb1753
|
ballakt
|
/* global L */
|
2 |
|
|
/* global $ */
|
3 |
2f227a6c
|
ballakt
|
|
4 |
8feb1753
|
ballakt
|
var mymap
|
5 |
|
|
var heatmapLayer = null
|
6 |
|
|
var marksLayer = null
|
7 |
03c02899
|
vastja
|
|
8 |
8feb1753
|
ballakt
|
var startX = 49.7248
|
9 |
|
|
var startY = 13.3521
|
10 |
|
|
var startZoom = 17
|
11 |
3fc08f2d
|
vastja
|
|
12 |
8feb1753
|
ballakt
|
var dataSourceRoute
|
13 |
1cf1413d
|
ballakt
|
let positionsSourceRoute
|
14 |
8feb1753
|
ballakt
|
var currentTime
|
15 |
a48642fb
|
vastja
|
|
16 |
8feb1753
|
ballakt
|
var timer
|
17 |
|
|
var isAnimationRunning = false
|
18 |
|
|
var data = []
|
19 |
a48642fb
|
vastja
|
|
20 |
70a3df53
|
vastja
|
var info = []
|
21 |
2f227a6c
|
ballakt
|
let currentInfo = 0
|
22 |
|
|
|
23 |
883a423e
|
Tomáš Ballák
|
const datasetDictNameDisplayName = {}
|
24 |
2f227a6c
|
ballakt
|
var datasetSelected = []
|
25 |
70a3df53
|
vastja
|
|
26 |
8feb1753
|
ballakt
|
const globalMarkersHolder = {}
|
27 |
d5a88af0
|
Tomáš Ballák
|
// all marker from which popup was removed
|
28 |
|
|
// contains: {key:[L.circle,L.pupup]}
|
29 |
|
|
// key: x and y, x + '' + y string
|
30 |
|
|
let globalMarkersChanged = {}
|
31 |
084a5972
|
ballakt
|
|
32 |
2f227a6c
|
ballakt
|
const fetchByNameDate = async (baseRoute, name, date, currentTime) => {
|
33 |
|
|
const headers = new Headers()
|
34 |
|
|
const myRequest = new Request(baseRoute + '/' + name + '/' + date + '/' + currentTime, {
|
35 |
|
|
method: 'GET',
|
36 |
|
|
headers: headers
|
37 |
|
|
})
|
38 |
|
|
const beforeJson = await fetch(myRequest)
|
39 |
|
|
return beforeJson.json()
|
40 |
|
|
}
|
41 |
|
|
const fetchDataSourceMarks = async (positionRoute, datasetName) => {
|
42 |
|
|
const headers = new Headers()
|
43 |
|
|
const myRequest = new Request(positionRoute + '/' + datasetName, {
|
44 |
|
|
method: 'GET',
|
45 |
|
|
headers: headers
|
46 |
|
|
})
|
47 |
|
|
const beforeJson = await fetch(myRequest)
|
48 |
|
|
return beforeJson.json()
|
49 |
|
|
}
|
50 |
084a5972
|
ballakt
|
|
51 |
2f227a6c
|
ballakt
|
const genPopUpControlButtons = (currentPage, numPages, onNextClick, onPreviousClick) => ({
|
52 |
|
|
previousButton: '<button id="previous-info-btn" class="circle-button" onclick="previousInfo()"></button>',
|
53 |
|
|
nextButton: '<button id="next-info-btn" onclick="nextInfo()" class="circle-button next"></button>',
|
54 |
|
|
posInfo: `<div id="count-info">${currentPage} z ${numPages}</div>`
|
55 |
|
|
})
|
56 |
084a5972
|
ballakt
|
const genPopUpControls = (controls) => {
|
57 |
2f227a6c
|
ballakt
|
return `<div class="popup-controls">${controls ? controls.reduce((sum, item) => sum + item, '') : ''}</div>`
|
58 |
084a5972
|
ballakt
|
}
|
59 |
883a423e
|
Tomáš Ballák
|
const genMultipleDatasetsPopUp = (sum, currentPos, maxPos, datasetName) => {
|
60 |
|
|
const header = `<strong id="dataset-info">${datasetName}</strong>`
|
61 |
2f227a6c
|
ballakt
|
const digitInfo = `<div id="number-info"><span id="digit-info">${sum}</span></div>`
|
62 |
|
|
const { previousButton, nextButton, posInfo } = genPopUpControlButtons(currentPos, maxPos)
|
63 |
|
|
return `
|
64 |
|
|
${header}
|
65 |
|
|
${digitInfo}
|
66 |
|
|
${genPopUpControls([previousButton, posInfo, nextButton])}
|
67 |
|
|
`
|
68 |
|
|
}
|
69 |
|
|
const prepareLayerPopUp = (lat, lng, num, className) => L.popup({
|
70 |
|
|
autoPan: false,
|
71 |
|
|
className: className
|
72 |
|
|
}).setLatLng([lat / num, lng / num])
|
73 |
|
|
|
74 |
bb2d43b5
|
Martin Sebela
|
const genPopUp = (datasetName, place, count, sum, currentPos, maxPos) => {
|
75 |
|
|
const popupHeader = `
|
76 |
|
|
<strong>${datasetName}</strong>
|
77 |
|
|
<div id="place-info">${place}</div>`
|
78 |
|
|
const popupData = `
|
79 |
|
|
<div id="number-info">
|
80 |
|
|
<span id="digit-info">${count}</span>
|
81 |
|
|
<span id="total-info">${(sum && (sum != count)) ? '/' + sum : ''}</span>
|
82 |
|
|
</div>`
|
83 |
2f227a6c
|
ballakt
|
const { previousButton, nextButton, posInfo } = genPopUpControlButtons(currentPos, maxPos)
|
84 |
bb2d43b5
|
Martin Sebela
|
|
85 |
084a5972
|
ballakt
|
return `
|
86 |
bb2d43b5
|
Martin Sebela
|
${popupHeader}
|
87 |
|
|
${popupData}
|
88 |
2f227a6c
|
ballakt
|
${genPopUpControls(maxPos > 1 ? [previousButton, posInfo, nextButton] : null)}
|
89 |
084a5972
|
ballakt
|
`
|
90 |
|
|
}
|
91 |
1cf1413d
|
ballakt
|
const onCheckboxClicked = async (checkbox) => {
|
92 |
|
|
if ($(checkbox).prop('checked')) {
|
93 |
|
|
loadCurrentTimeHeatmap(dataSourceRoute, positionsSourceRoute)
|
94 |
|
|
changeUrl()
|
95 |
|
|
} else {
|
96 |
|
|
loadCheckboxDatasetNameData()
|
97 |
|
|
data.forEach((item, index) => {
|
98 |
|
|
Object.keys(item).forEach((datasetName) => {
|
99 |
|
|
if (datasetName === $(checkbox).val()) {
|
100 |
|
|
delete data[index][datasetName]
|
101 |
|
|
}
|
102 |
|
|
})
|
103 |
|
|
drawHeatmap(data[currentTime])
|
104 |
|
|
})
|
105 |
|
|
changeUrl()
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
const debounce = (func, delay) => {
|
109 |
|
|
let inDebounce
|
110 |
|
|
return function () {
|
111 |
|
|
const context = this
|
112 |
|
|
const args = arguments
|
113 |
|
|
clearTimeout(inDebounce)
|
114 |
|
|
inDebounce = setTimeout(() => func.apply(context, args), delay)
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
bb2d43b5
|
Martin Sebela
|
|
118 |
1cf1413d
|
ballakt
|
const onValueChangeRegister = () => {
|
119 |
|
|
$('#date').change(function () {
|
120 |
|
|
data = []
|
121 |
|
|
loadCurrentTimeHeatmap(dataSourceRoute, positionsSourceRoute)
|
122 |
|
|
const date = new Date($(this).val())
|
123 |
|
|
$('#player-date').html(`${date.getDate()}. ${date.getMonth() + 1}. ${date.getFullYear()}`)
|
124 |
bb2d43b5
|
Martin Sebela
|
changeUrl()
|
125 |
1cf1413d
|
ballakt
|
})
|
126 |
bb2d43b5
|
Martin Sebela
|
|
127 |
1cf1413d
|
ballakt
|
$('#dataset-dropdown-time input[type="radio"]').each(function () {
|
128 |
|
|
$(this).change(function () {
|
129 |
94c6eb49
|
Martin Sebela
|
currentTime = parseInt($(this).val())
|
130 |
1cf1413d
|
ballakt
|
updateHeaderControls()
|
131 |
|
|
setTimeline()
|
132 |
|
|
drawHeatmap(data[currentTime])
|
133 |
bb2d43b5
|
Martin Sebela
|
changeUrl()
|
134 |
1cf1413d
|
ballakt
|
})
|
135 |
|
|
})
|
136 |
bb2d43b5
|
Martin Sebela
|
|
137 |
1cf1413d
|
ballakt
|
$('input[type=checkbox]').each(function () {
|
138 |
|
|
$(this).change(
|
139 |
|
|
debounce(() => onCheckboxClicked(this), 1000)
|
140 |
|
|
)
|
141 |
|
|
})
|
142 |
|
|
}
|
143 |
bb2d43b5
|
Martin Sebela
|
|
144 |
70a3df53
|
vastja
|
/**
|
145 |
|
|
* Initialize leaflet map on start position which can be default or set based on user action
|
146 |
|
|
*/
|
147 |
8feb1753
|
ballakt
|
// eslint-disable-next-line no-unused-vars
|
148 |
|
|
function initMap () {
|
149 |
90d3db28
|
Tomáš Ballák
|
startX = localStorage.getItem('lat') || startX
|
150 |
|
|
startY = localStorage.getItem('lng') || startY
|
151 |
|
|
startZoom = localStorage.getItem('zoom') || startZoom
|
152 |
72a438f3
|
vastja
|
|
153 |
8feb1753
|
ballakt
|
mymap = L.map('heatmap').setView([startX, startY], startZoom)
|
154 |
3fc08f2d
|
vastja
|
|
155 |
c236b33a
|
msebela
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
156 |
|
|
attribution: '',
|
157 |
|
|
maxZoom: 19
|
158 |
8feb1753
|
ballakt
|
}).addTo(mymap)
|
159 |
3ae59f75
|
vastja
|
|
160 |
8feb1753
|
ballakt
|
mymap.on('click', showInfo)
|
161 |
c236b33a
|
msebela
|
}
|
162 |
2f227a6c
|
ballakt
|
const getInfoLength = () => {
|
163 |
|
|
const infoKeys = Object.keys(info)
|
164 |
|
|
if (infoKeys.length === 1) {
|
165 |
|
|
// return number of records in one dataset (one dataset in area)
|
166 |
|
|
return info[infoKeys[0]].items.length
|
167 |
|
|
}
|
168 |
|
|
// return number of datasets (agregation of all datasets in area)
|
169 |
|
|
return infoKeys.length
|
170 |
|
|
}
|
171 |
|
|
const getElFromObjectInfo = (position) => {
|
172 |
|
|
const keys = Object.keys(info)
|
173 |
|
|
return info[keys[position]]
|
174 |
|
|
}
|
175 |
|
|
const hasInfoMultipleDatasets = () => {
|
176 |
|
|
return Object.keys(info).length > 1
|
177 |
|
|
}
|
178 |
8feb1753
|
ballakt
|
function showInfo (e) {
|
179 |
3ae59f75
|
vastja
|
info = []
|
180 |
2f227a6c
|
ballakt
|
currentInfo = 0
|
181 |
3ae59f75
|
vastja
|
|
182 |
|
|
// https://wiki.openstreetmap.org/wiki/Zoom_levels
|
183 |
|
|
// Todo change to variable - it is used in heatmap init
|
184 |
2f227a6c
|
ballakt
|
const stile = 40075016.686 * Math.cos(startX) / Math.pow(2, mymap.getZoom())
|
185 |
|
|
const radius = 25 * stile / 256
|
186 |
|
|
|
187 |
|
|
let i = 0
|
188 |
|
|
let lat = 0
|
189 |
|
|
let lng = 0
|
190 |
|
|
|
191 |
|
|
let total = 0
|
192 |
|
|
|
193 |
|
|
const datasetsInRadius = {}
|
194 |
|
|
|
195 |
|
|
Object.keys(data[currentTime]).forEach((key) => {
|
196 |
|
|
const namedData = data[currentTime][key]
|
197 |
|
|
namedData.items.forEach(element => {
|
198 |
|
|
if (e.latlng.distanceTo(new L.LatLng(element.x, element.y)) < radius) {
|
199 |
|
|
lat += element.x
|
200 |
|
|
lng += element.y
|
201 |
|
|
info[i] = { place: element.place, number: element.number, datasetName: key }
|
202 |
|
|
total += parseInt(element.number)
|
203 |
|
|
i++
|
204 |
|
|
datasetsInRadius[key] = true
|
205 |
|
|
}
|
206 |
|
|
})
|
207 |
8feb1753
|
ballakt
|
})
|
208 |
3ae59f75
|
vastja
|
|
209 |
2f227a6c
|
ballakt
|
// Process info for more then one dataset
|
210 |
8feb1753
|
ballakt
|
|
211 |
2f227a6c
|
ballakt
|
info = info.reduce((acc, item) => {
|
212 |
|
|
if (!acc[item.datasetName]) {
|
213 |
|
|
acc[item.datasetName] = {
|
214 |
|
|
items: [],
|
215 |
|
|
number: 0,
|
216 |
|
|
datasetName: item.datasetName
|
217 |
|
|
}
|
218 |
|
|
}
|
219 |
|
|
acc[item.datasetName].items.push(item)
|
220 |
|
|
acc[item.datasetName].number += Number(item.number)
|
221 |
|
|
return acc
|
222 |
|
|
}, {})
|
223 |
|
|
|
224 |
|
|
// There is one dataset
|
225 |
|
|
|
226 |
|
|
const numDatasets = Object.keys(datasetsInRadius).length
|
227 |
|
|
|
228 |
d5a88af0
|
Tomáš Ballák
|
if (!numDatasets) {
|
229 |
|
|
return
|
230 |
|
|
}
|
231 |
2f227a6c
|
ballakt
|
|
232 |
|
|
if (numDatasets === 1) {
|
233 |
|
|
const infoDict = getElFromObjectInfo(0)
|
234 |
|
|
const info_ = infoDict.items
|
235 |
|
|
const { place, number } = info_[currentInfo]
|
236 |
|
|
prepareLayerPopUp(lat, lng, i, `popup-${infoDict.datasetName}`)
|
237 |
883a423e
|
Tomáš Ballák
|
.setContent(genPopUp(datasetDictNameDisplayName[infoDict.datasetName], place, number, total, currentInfo + 1, info_.length))
|
238 |
2f227a6c
|
ballakt
|
.openOn(mymap)
|
239 |
|
|
if (info_.length === 1) {
|
240 |
8feb1753
|
ballakt
|
$('#previous-info-btn').prop('disabled', true)
|
241 |
|
|
$('#next-info-btn').prop('disabled', true)
|
242 |
|
|
$('.popup-controls').hide()
|
243 |
3ae59f75
|
vastja
|
}
|
244 |
2f227a6c
|
ballakt
|
} else {
|
245 |
|
|
const { datasetName, number } = getElFromObjectInfo(currentInfo)
|
246 |
|
|
prepareLayerPopUp(lat, lng, i, `popup-${datasetName}`)
|
247 |
883a423e
|
Tomáš Ballák
|
.setContent(genMultipleDatasetsPopUp(number, currentInfo + 1, getInfoLength(), datasetDictNameDisplayName[datasetName]))
|
248 |
2f227a6c
|
ballakt
|
.openOn(mymap)
|
249 |
3ae59f75
|
vastja
|
}
|
250 |
|
|
}
|
251 |
|
|
|
252 |
8feb1753
|
ballakt
|
// eslint-disable-next-line no-unused-vars
|
253 |
|
|
function previousInfo () {
|
254 |
2f227a6c
|
ballakt
|
const infoLength = getInfoLength()
|
255 |
|
|
const previousCurrentInfo = currentInfo
|
256 |
|
|
currentInfo = (currentInfo + infoLength - 1) % infoLength
|
257 |
|
|
displayInfoText(previousCurrentInfo)
|
258 |
3ae59f75
|
vastja
|
}
|
259 |
|
|
|
260 |
8feb1753
|
ballakt
|
// eslint-disable-next-line no-unused-vars
|
261 |
|
|
function nextInfo () {
|
262 |
2f227a6c
|
ballakt
|
const infoLength = getInfoLength()
|
263 |
|
|
const previousCurrentInfo = currentInfo
|
264 |
|
|
currentInfo = (currentInfo + 1) % infoLength
|
265 |
|
|
displayInfoText(previousCurrentInfo)
|
266 |
3ae59f75
|
vastja
|
}
|
267 |
2f227a6c
|
ballakt
|
function displayInfoText (previousInfoNum) {
|
268 |
|
|
const previousInfo = hasInfoMultipleDatasets() ? getElFromObjectInfo(previousInfoNum) : getElFromObjectInfo(0).items[previousInfoNum]
|
269 |
|
|
const info_ = hasInfoMultipleDatasets() ? getElFromObjectInfo(currentInfo) : getElFromObjectInfo(0).items[currentInfo]
|
270 |
|
|
const infoLength = getInfoLength()
|
271 |
883a423e
|
Tomáš Ballák
|
const datasetInfo = $('#dataset-info')
|
272 |
|
|
if (datasetInfo) {
|
273 |
|
|
$(datasetInfo).html(datasetDictNameDisplayName[info_.datasetName])
|
274 |
|
|
}
|
275 |
2f227a6c
|
ballakt
|
$('#place-info').html(info_.place ? info_.place : info_.datasetName)
|
276 |
|
|
$('#digit-info').html(info_.number)
|
277 |
|
|
$('#count-info').html(currentInfo + 1 + ' z ' + infoLength)
|
278 |
|
|
$('.leaflet-popup').removeClass(`popup-${previousInfo.datasetName}`)
|
279 |
|
|
$('.leaflet-popup').addClass(`popup-${info_.datasetName}`)
|
280 |
3ae59f75
|
vastja
|
}
|
281 |
351696d5
|
Martin Sebela
|
|
282 |
8feb1753
|
ballakt
|
// eslint-disable-next-line no-unused-vars
|
283 |
72a438f3
|
vastja
|
function setMapView (latitude, longitude, zoom) {
|
284 |
90d3db28
|
Tomáš Ballák
|
localStorage.setItem('lat', latitude)
|
285 |
|
|
localStorage.setItem('lng', longitude)
|
286 |
|
|
localStorage.setItem('zoom', zoom)
|
287 |
8feb1753
|
ballakt
|
mymap.setView([latitude, longitude], zoom)
|
288 |
3fc08f2d
|
vastja
|
}
|
289 |
|
|
|
290 |
70a3df53
|
vastja
|
/**
|
291 |
|
|
* Change animation start from playing to stopped or the other way round
|
292 |
|
|
*/
|
293 |
8feb1753
|
ballakt
|
// eslint-disable-next-line no-unused-vars
|
294 |
|
|
function changeAnimationState () {
|
295 |
a48642fb
|
vastja
|
isAnimationRunning = !isAnimationRunning
|
296 |
|
|
if (isAnimationRunning) {
|
297 |
8feb1753
|
ballakt
|
$('#play-pause').attr('class', 'pause')
|
298 |
a48642fb
|
vastja
|
timer = setInterval(
|
299 |
8feb1753
|
ballakt
|
function () {
|
300 |
|
|
next()
|
301 |
a48642fb
|
vastja
|
},
|
302 |
|
|
800
|
303 |
8feb1753
|
ballakt
|
)
|
304 |
|
|
} else {
|
305 |
|
|
clearTimeout(timer)
|
306 |
|
|
$('#play-pause').attr('class', 'play')
|
307 |
351696d5
|
Martin Sebela
|
}
|
308 |
|
|
}
|
309 |
|
|
|
310 |
8feb1753
|
ballakt
|
// eslint-disable-next-line no-unused-vars
|
311 |
|
|
function previous () {
|
312 |
|
|
currentTime = (currentTime + 23) % 24
|
313 |
|
|
drawHeatmap(data[currentTime])
|
314 |
|
|
setTimeline()
|
315 |
|
|
mymap.closePopup()
|
316 |
|
|
updateHeaderControls()
|
317 |
|
|
changeUrl()
|
318 |
a48642fb
|
vastja
|
}
|
319 |
|
|
|
320 |
8feb1753
|
ballakt
|
function next () {
|
321 |
|
|
currentTime = (currentTime + 1) % 24
|
322 |
|
|
drawHeatmap(data[currentTime])
|
323 |
|
|
setTimeline()
|
324 |
|
|
mymap.closePopup()
|
325 |
|
|
updateHeaderControls()
|
326 |
|
|
changeUrl()
|
327 |
8b840eb7
|
vastja
|
}
|
328 |
2f227a6c
|
ballakt
|
const typeUrlReducer = (accumulator, currentValue) => accumulator + currentValue
|
329 |
70a3df53
|
vastja
|
/**
|
330 |
|
|
* Change browser url based on animation step
|
331 |
|
|
*/
|
332 |
8feb1753
|
ballakt
|
function changeUrl () {
|
333 |
8b840eb7
|
vastja
|
window.history.pushState(
|
334 |
8feb1753
|
ballakt
|
'',
|
335 |
8b840eb7
|
vastja
|
document.title,
|
336 |
2f227a6c
|
ballakt
|
window.location.origin + window.location.pathname + `?date=${$('#date').val()}&time=${currentTime}${datasetSelected.reduce((acc, current) => acc + '&type[]=' + current, '')}`
|
337 |
8feb1753
|
ballakt
|
)
|
338 |
4e8c0e5b
|
Martin Sebela
|
}
|
339 |
|
|
|
340 |
8feb1753
|
ballakt
|
function updateHeaderControls () {
|
341 |
1cf1413d
|
ballakt
|
$(`#time_${currentTime}`).prop('checked', true)
|
342 |
bb2d43b5
|
Martin Sebela
|
$('#dropdownMenuButtonTime').html((currentTime < 10 ? '0' : '') + `${currentTime}:00`)
|
343 |
a48642fb
|
vastja
|
}
|
344 |
351696d5
|
Martin Sebela
|
|
345 |
8feb1753
|
ballakt
|
function setTimeline () {
|
346 |
|
|
$('#timeline').text(currentTime + ':00')
|
347 |
|
|
$('#timeline').attr('class', 'time hour-' + currentTime)
|
348 |
351696d5
|
Martin Sebela
|
}
|
349 |
|
|
|
350 |
70a3df53
|
vastja
|
/**
|
351 |
|
|
* Load and display heatmap layer for current data
|
352 |
|
|
* @param {string} opendataRoute route to dataset source
|
353 |
|
|
* @param {string} positionsRoute route to dataset postitions source
|
354 |
|
|
*/
|
355 |
8feb1753
|
ballakt
|
// eslint-disable-next-line no-unused-vars
|
356 |
2f227a6c
|
ballakt
|
async function loadCurrentTimeHeatmap (opendataRoute, positionsRoute) {
|
357 |
1cf1413d
|
ballakt
|
loadCheckboxDatasetNameData()
|
358 |
8feb1753
|
ballakt
|
dataSourceRoute = opendataRoute
|
359 |
1cf1413d
|
ballakt
|
positionsSourceRoute = positionsRoute
|
360 |
2f227a6c
|
ballakt
|
const dataSourceMarks = {}
|
361 |
|
|
const allPromises = []
|
362 |
|
|
const date = $('#date').val()
|
363 |
1cf1413d
|
ballakt
|
currentTime = parseInt($('#dataset-dropdown-time input[type="radio"]:checked').val())
|
364 |
|
|
|
365 |
8feb1753
|
ballakt
|
setTimeline()
|
366 |
2f227a6c
|
ballakt
|
data[currentTime] = {}
|
367 |
|
|
const dataSelectedHandler = async (datasetName) => {
|
368 |
|
|
const marks = await fetchDataSourceMarks(positionsRoute, datasetName)
|
369 |
|
|
const datasetData = await fetchByNameDate(dataSourceRoute, datasetName, date, currentTime)
|
370 |
|
|
dataSourceMarks[datasetName] = marks
|
371 |
|
|
data[currentTime][datasetName] = datasetData
|
372 |
|
|
}
|
373 |
|
|
await datasetSelected.forEach((datasetName) => {
|
374 |
|
|
allPromises.push(dataSelectedHandler(datasetName))
|
375 |
8feb1753
|
ballakt
|
})
|
376 |
2f227a6c
|
ballakt
|
Promise.all(allPromises).then(
|
377 |
|
|
() => {
|
378 |
|
|
drawDataSourceMarks(dataSourceMarks)
|
379 |
|
|
drawHeatmap(data[currentTime])
|
380 |
|
|
preload(currentTime, 1, date)
|
381 |
|
|
preload(currentTime, -1, date)
|
382 |
|
|
}
|
383 |
|
|
)
|
384 |
a48642fb
|
vastja
|
}
|
385 |
|
|
|
386 |
8feb1753
|
ballakt
|
function drawDataSourceMarks (data) {
|
387 |
61ff7718
|
vastja
|
if (marksLayer != null) {
|
388 |
1cf1413d
|
ballakt
|
mymap.removeLayer(marksLayer)
|
389 |
61ff7718
|
vastja
|
}
|
390 |
8feb1753
|
ballakt
|
marksLayer = L.layerGroup()
|
391 |
2f227a6c
|
ballakt
|
Object.keys(data).forEach((key_) => {
|
392 |
|
|
for (var key in data[key_]) {
|
393 |
|
|
const { x, y, name } = data[key_][key]
|
394 |
|
|
const pop =
|
395 |
|
|
prepareLayerPopUp(x, y, 1, `popup-${key_}`)
|
396 |
883a423e
|
Tomáš Ballák
|
.setContent(genPopUp(datasetDictNameDisplayName[key_], name, 0, 0, 1, 1))
|
397 |
2f227a6c
|
ballakt
|
const newCircle =
|
398 |
|
|
L.circle([x, y], { radius: 2, fillOpacity: 0.8, color: '#004fb3', fillColor: '#004fb3', bubblingMouseEvents: true })
|
399 |
|
|
.bindPopup(pop)
|
400 |
|
|
globalMarkersHolder[x + '' + y] = [newCircle, pop] // add new marker to global holders
|
401 |
|
|
marksLayer.addLayer(
|
402 |
|
|
newCircle
|
403 |
|
|
)
|
404 |
|
|
}
|
405 |
|
|
})
|
406 |
61ff7718
|
vastja
|
|
407 |
8feb1753
|
ballakt
|
marksLayer.setZIndex(-1).addTo(mymap)
|
408 |
61ff7718
|
vastja
|
}
|
409 |
|
|
|
410 |
2f227a6c
|
ballakt
|
async function preload (time, change, date) {
|
411 |
|
|
for (let nTime = time + change; nTime >= 0 && nTime <= 23; nTime = nTime + change) {
|
412 |
|
|
if (!data[nTime]) {
|
413 |
|
|
data[nTime] = {}
|
414 |
|
|
}
|
415 |
1cf1413d
|
ballakt
|
datasetSelected.forEach(async (datasetName) => {
|
416 |
|
|
if (!data[nTime][datasetName]) {
|
417 |
|
|
data[nTime][datasetName] = await fetchByNameDate(dataSourceRoute, datasetName, date, nTime)
|
418 |
|
|
}
|
419 |
|
|
})
|
420 |
a48642fb
|
vastja
|
}
|
421 |
3fc08f2d
|
vastja
|
}
|
422 |
|
|
|
423 |
2f227a6c
|
ballakt
|
function drawHeatmap (dataRaw) {
|
424 |
03c02899
|
vastja
|
// Todo still switched
|
425 |
2f227a6c
|
ballakt
|
const dataDict = dataRaw
|
426 |
|
|
const mergedPoints = []
|
427 |
|
|
let max = 0
|
428 |
d5a88af0
|
Tomáš Ballák
|
if (Object.keys(globalMarkersChanged).length) {
|
429 |
|
|
Object.keys(globalMarkersChanged).forEach(function (key) {
|
430 |
|
|
globalMarkersChanged[key][0].bindPopup(globalMarkersChanged[key][1])
|
431 |
|
|
})
|
432 |
|
|
globalMarkersChanged = {}
|
433 |
|
|
}
|
434 |
2f227a6c
|
ballakt
|
Object.keys(dataDict).forEach((key) => {
|
435 |
|
|
const data = dataDict[key]
|
436 |
|
|
max = Math.max(max, data.max)
|
437 |
|
|
if (data != null) {
|
438 |
8feb1753
|
ballakt
|
// Bind back popups for markers (we dont know if there is any data for this marker or not)
|
439 |
2f227a6c
|
ballakt
|
const points = data.items.map((point) => {
|
440 |
|
|
const { x, y, number } = point
|
441 |
|
|
const key = x + '' + y
|
442 |
|
|
const holder = globalMarkersHolder[key]
|
443 |
|
|
if (!globalMarkersChanged[key] && number) {
|
444 |
8feb1753
|
ballakt
|
// There is data for this marker => unbind popup with zero value
|
445 |
2f227a6c
|
ballakt
|
holder[0] = holder[0].unbindPopup()
|
446 |
|
|
globalMarkersChanged[key] = holder
|
447 |
|
|
}
|
448 |
|
|
return [x, y, number]
|
449 |
|
|
})
|
450 |
|
|
mergedPoints.push(...points)
|
451 |
|
|
} else {
|
452 |
|
|
if (heatmapLayer != null) {
|
453 |
|
|
mymap.removeLayer(heatmapLayer)
|
454 |
084a5972
|
ballakt
|
}
|
455 |
a48642fb
|
vastja
|
}
|
456 |
2f227a6c
|
ballakt
|
})
|
457 |
|
|
if (heatmapLayer != null) {
|
458 |
|
|
mymap.removeLayer(heatmapLayer)
|
459 |
|
|
}
|
460 |
|
|
if (mergedPoints.length) {
|
461 |
|
|
heatmapLayer = L.heatLayer(mergedPoints, { max: max, minOpacity: 0.5, radius: 35, blur: 30 }).addTo(mymap)
|
462 |
a48642fb
|
vastja
|
}
|
463 |
03c02899
|
vastja
|
}
|
464 |
3fc08f2d
|
vastja
|
|
465 |
70a3df53
|
vastja
|
/**
|
466 |
|
|
* Checks dataset availibility
|
467 |
81980e82
|
ballakt
|
* @param {string} route authority for datasets availibility checks
|
468 |
70a3df53
|
vastja
|
*/
|
469 |
8feb1753
|
ballakt
|
// eslint-disable-next-line no-unused-vars
|
470 |
|
|
function checkDataSetsAvailability (route) {
|
471 |
03c02899
|
vastja
|
$.ajax({
|
472 |
8feb1753
|
ballakt
|
type: 'POST',
|
473 |
03c02899
|
vastja
|
// Todo it might be good idea to change db collections format
|
474 |
03ccdd65
|
vastja
|
url: route + '/' + $('#date').val(),
|
475 |
8feb1753
|
ballakt
|
success: function (result) {
|
476 |
|
|
updateAvailableDataSets(result)
|
477 |
03c02899
|
vastja
|
}
|
478 |
8feb1753
|
ballakt
|
})
|
479 |
03c02899
|
vastja
|
}
|
480 |
|
|
|
481 |
8feb1753
|
ballakt
|
function updateAvailableDataSets (available) {
|
482 |
2f227a6c
|
ballakt
|
let leastOneOptionEnabled = false
|
483 |
|
|
// datasetSelected = []
|
484 |
|
|
$('#dataset-dropdown .dropdown-item').each(function () {
|
485 |
|
|
const input = $(this).find('input')
|
486 |
|
|
const inputVal = input[0].value
|
487 |
|
|
if (!(inputVal in available)) {
|
488 |
|
|
$(this).addClass('disabled')
|
489 |
|
|
$(input).prop('checked', false)
|
490 |
8feb1753
|
ballakt
|
} else {
|
491 |
2f227a6c
|
ballakt
|
leastOneOptionEnabled = true
|
492 |
|
|
$(this).removeClass('disabled')
|
493 |
5d599617
|
vastja
|
}
|
494 |
8feb1753
|
ballakt
|
})
|
495 |
dfe43218
|
vastja
|
|
496 |
94c6eb49
|
Martin Sebela
|
$('#btn-update-heatmap').prop('disabled', !leastOneOptionEnabled)
|
497 |
03c02899
|
vastja
|
}
|
498 |
0a828a5a
|
Martin Sebela
|
|
499 |
8feb1753
|
ballakt
|
function formatDate (date) {
|
500 |
|
|
var day = String(date.getDate())
|
501 |
|
|
var month = String(date.getMonth() + 1)
|
502 |
0a828a5a
|
Martin Sebela
|
|
503 |
|
|
if (day.length === 1) {
|
504 |
8feb1753
|
ballakt
|
day = '0' + day
|
505 |
0a828a5a
|
Martin Sebela
|
}
|
506 |
|
|
|
507 |
|
|
if (month.length === 1) {
|
508 |
8feb1753
|
ballakt
|
month = '0' + month
|
509 |
0a828a5a
|
Martin Sebela
|
}
|
510 |
|
|
|
511 |
8feb1753
|
ballakt
|
return date.getFullYear() + '-' + month + '-' + day
|
512 |
0a828a5a
|
Martin Sebela
|
}
|
513 |
|
|
|
514 |
8feb1753
|
ballakt
|
// eslint-disable-next-line no-unused-vars
|
515 |
|
|
function initDatepicker (availableDatesSource) {
|
516 |
|
|
var availableDates = ''
|
517 |
0a828a5a
|
Martin Sebela
|
|
518 |
|
|
$.ajax({
|
519 |
|
|
type: 'GET',
|
520 |
|
|
url: availableDatesSource,
|
521 |
8feb1753
|
ballakt
|
success: function (result) {
|
522 |
|
|
availableDates = String(result).split(',')
|
523 |
0a828a5a
|
Martin Sebela
|
}
|
524 |
a7e04778
|
Martin Sebela
|
}).then(function () {
|
525 |
|
|
$('#date').datepicker({
|
526 |
|
|
format: 'yyyy-mm-dd',
|
527 |
|
|
language: 'cs',
|
528 |
8feb1753
|
ballakt
|
beforeShowDay: function (date) {
|
529 |
a7e04778
|
Martin Sebela
|
if (availableDates.indexOf(formatDate(date)) < 0) {
|
530 |
8feb1753
|
ballakt
|
return { enabled: false, tooltip: 'Žádná data' }
|
531 |
|
|
} else {
|
532 |
|
|
return { enabled: true }
|
533 |
a7e04778
|
Martin Sebela
|
}
|
534 |
|
|
},
|
535 |
|
|
autoclose: true
|
536 |
8feb1753
|
ballakt
|
})
|
537 |
|
|
})
|
538 |
|
|
}
|
539 |
dd652e61
|
Martin Sebela
|
|
540 |
81980e82
|
ballakt
|
function initLocationsMenu () {
|
541 |
|
|
var locationsWrapper = '.locations'
|
542 |
|
|
var locationsDisplayClass = 'show'
|
543 |
dd652e61
|
Martin Sebela
|
|
544 |
81980e82
|
ballakt
|
if ($(window).width() <= 480) {
|
545 |
|
|
$(locationsWrapper).removeClass(locationsDisplayClass)
|
546 |
|
|
} else {
|
547 |
|
|
$(locationsWrapper).addClass(locationsDisplayClass)
|
548 |
dd652e61
|
Martin Sebela
|
}
|
549 |
4e003182
|
Martin Sebela
|
}
|
550 |
|
|
|
551 |
81980e82
|
ballakt
|
function openDatepicker () {
|
552 |
4e003182
|
Martin Sebela
|
if ($(window).width() <= 990) {
|
553 |
81980e82
|
ballakt
|
$('.navbar-collapse').collapse()
|
554 |
4e003182
|
Martin Sebela
|
}
|
555 |
|
|
|
556 |
|
|
$('#date').datepicker('show')
|
557 |
81980e82
|
ballakt
|
}
|
558 |
2f227a6c
|
ballakt
|
function onDocumentReady () {
|
559 |
|
|
$('#dataset-dropdown').on('click', function (e) {
|
560 |
|
|
e.stopPropagation()
|
561 |
|
|
})
|
562 |
1cf1413d
|
ballakt
|
|
563 |
94c6eb49
|
Martin Sebela
|
$('#btn-update-heatmap').prop('name', '')
|
564 |
1cf1413d
|
ballakt
|
onValueChangeRegister()
|
565 |
|
|
}
|
566 |
|
|
const loadCheckboxDatasetNameData = () => {
|
567 |
2f227a6c
|
ballakt
|
datasetSelected = []
|
568 |
|
|
$('#dataset-dropdown .dropdown-item').each(function () {
|
569 |
|
|
const input = $(this).find('input')
|
570 |
|
|
const inputVal = input[0].value
|
571 |
|
|
if (input[0].checked) {
|
572 |
|
|
datasetSelected.push(inputVal)
|
573 |
|
|
}
|
574 |
883a423e
|
Tomáš Ballák
|
datasetDictNameDisplayName[inputVal] = $(input).data('dataset-display-name')
|
575 |
2f227a6c
|
ballakt
|
})
|
576 |
|
|
}
|