Revize a48642fb
Přidáno uživatelem Jakub Vašta před asi 4 roky(ů)
website/public/js/zcu-heatmap.js | ||
---|---|---|
5 | 5 |
var startY = 13.3521; |
6 | 6 |
var startZoom = 17; |
7 | 7 |
|
8 |
var currentTime = 0; |
|
8 |
var dataSourceRoute; |
|
9 |
var currentTime; |
|
10 |
var name; |
|
11 |
var date; |
|
12 |
|
|
13 |
var timer; |
|
14 |
var isAnimationRunning = false; |
|
15 |
var data = []; |
|
16 |
|
|
9 | 17 |
|
10 | 18 |
|
11 | 19 |
function initMap() { |
... | ... | |
22 | 30 |
mymap.setView([latitude, longitude], zoom); |
23 | 31 |
} |
24 | 32 |
|
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 |
} |
|
33 |
function changeAnimationState() { |
|
34 |
|
|
35 |
isAnimationRunning = !isAnimationRunning |
|
36 |
if (isAnimationRunning) { |
|
37 |
$('#play-pause').attr('class', 'pause'); |
|
38 |
timer = setInterval( |
|
39 |
function() { |
|
40 |
next(); |
|
41 |
}, |
|
42 |
800 |
|
43 |
); |
|
35 | 44 |
} |
36 |
else if (direction === 'prev') { |
|
37 |
currentTime -= 1; |
|
38 |
|
|
39 |
if (currentTime < 0) { |
|
40 |
currentTime = 23; |
|
41 |
} |
|
45 |
else { |
|
46 |
clearTimeout(timer); |
|
47 |
$('#play-pause').attr('class', 'play'); |
|
42 | 48 |
} |
43 | 49 |
|
44 |
time.textContent = currentTime + ":00"; |
|
45 |
time.className = 'time hour-' + currentTime; |
|
50 |
|
|
46 | 51 |
} |
47 | 52 |
|
53 |
function previous() { |
|
54 |
currentTime = (currentTime + 23) % 24; |
|
55 |
drawHeatmap(data[currentTime]); |
|
56 |
setTimeline(); |
|
57 |
} |
|
58 |
|
|
59 |
function next() { |
|
60 |
currentTime = (currentTime + 1) % 24; |
|
61 |
drawHeatmap(data[currentTime]); |
|
62 |
setTimeline(); |
|
63 |
} |
|
48 | 64 |
|
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); |
|
65 |
function setTimeline() { |
|
66 |
$('#timeline').text(currentTime + ":00"); |
|
67 |
$('#timeline').attr('class', 'time hour-' + currentTime); |
|
60 | 68 |
} |
61 | 69 |
|
62 |
function showHeatmap(route) {
|
|
70 |
function loadCurrentTimeHeatmap(route) {
|
|
63 | 71 |
|
64 |
var name = $('#type').children("option:selected").text(); |
|
72 |
dataSourceRoute = route; |
|
73 |
data = [] |
|
74 |
|
|
75 |
name = $('#type').children("option:selected").text(); |
|
65 | 76 |
var parts = $('#date').val().split('-'); |
66 |
var date = parts[2] + parts[1] + parts[0]; |
|
67 |
var time = $('#time').children("option:selected").val(); |
|
77 |
date = parts[2] + parts[1] + parts[0]; |
|
78 |
currentTime = parseInt($('#time').children("option:selected").val()); |
|
79 |
setTimeline(); |
|
68 | 80 |
|
69 | 81 |
$.ajax({ |
70 | 82 |
type: "POST", |
71 |
url: route + '/' + name + '/' + date + '/' + time,
|
|
83 |
url: dataSourceRoute + '/' + name + '/' + date + '/' + currentTime,
|
|
72 | 84 |
success: function(result) { |
73 |
drawHeatmap(result); |
|
85 |
data[currentTime] = result; |
|
86 |
drawHeatmap(data[currentTime]); |
|
74 | 87 |
} |
75 | 88 |
}); |
89 |
|
|
90 |
preload(currentTime, 1); |
|
91 |
preload(currentTime, -1); |
|
92 |
|
|
93 |
} |
|
94 |
|
|
95 |
function preload(time, change) { |
|
96 |
|
|
97 |
var ntime = time + change; |
|
98 |
if (0 <= ntime && ntime <= 23) { |
|
99 |
$.ajax({ |
|
100 |
type: "POST", |
|
101 |
url: dataSourceRoute + '/' + name + '/' + date + '/' + ntime, |
|
102 |
success: function(result) { |
|
103 |
data[ntime] = result; |
|
104 |
preload(ntime, change); |
|
105 |
} |
|
106 |
}); |
|
107 |
} |
|
108 |
|
|
76 | 109 |
} |
77 | 110 |
|
78 | 111 |
|
79 | 112 |
function drawHeatmap(points) { |
80 | 113 |
|
81 | 114 |
// Todo still switched |
82 |
points = points.map(function (p) { return [p['y'], p['x'], p['number']]; }); |
|
83 |
if (heatmapLayer != null) { |
|
84 |
mymap.removeLayer(heatmapLayer); |
|
115 |
if (points != null) { |
|
116 |
points = points.map(function (p) { return [p['x'], p['y'], p['number']]; }); |
|
117 |
if (heatmapLayer != null) { |
|
118 |
mymap.removeLayer(heatmapLayer); |
|
119 |
} |
|
120 |
heatmapLayer = L.heatLayer(points).addTo(mymap); |
|
85 | 121 |
} |
86 |
heatmapLayer = L.heatLayer(points, {opacity: 0.5}).addTo(mymap); |
|
87 |
heatmapLayer.options = {opacity: 1}; |
|
122 |
else { |
|
123 |
if (heatmapLayer != null) { |
|
124 |
mymap.removeLayer(heatmapLayer); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
88 | 128 |
// var heat_01 = ... |
89 | 129 |
// on background map.addLayer(heat_01) -> map.removeLayer(heat_01); |
90 | 130 |
// $(.leaflet-heatmap-layer).css('opacity', 'value'); |
Také k dispozici: Unified diff
Re #7940
+ heatmap animace - js kód
+ pause tlačítko - přidání stylu, změna