Revize 61ff7718
Přidáno uživatelem Jakub Vašta před téměř 5 roky(ů)
website/public/js/zcu-heatmap.js | ||
---|---|---|
1 | 1 |
var mymap; |
2 | 2 |
var heatmapLayer = null; |
3 |
var marksLayer = null; |
|
3 | 4 |
|
4 | 5 |
var startX = 49.7248; |
5 | 6 |
var startY = 13.3521; |
... | ... | |
46 | 47 |
var lat = 0; |
47 | 48 |
var lng = 0; |
48 | 49 |
|
50 |
var total = 0; |
|
49 | 51 |
data[currentTime]['items'].forEach(element => { |
50 | 52 |
if (e.latlng.distanceTo(new L.LatLng(element.x, element.y)) < radius) { |
51 | 53 |
lat += element.x |
52 | 54 |
lng += element.y; |
53 | 55 |
info[i] = {'place' : element.place, 'number' : element.number}; |
56 |
total += parseInt(element.number); |
|
54 | 57 |
i++; |
55 | 58 |
} |
56 | 59 |
}); |
... | ... | |
62 | 65 |
}) |
63 | 66 |
.setLatLng([lat / i, lng / i]) |
64 | 67 |
.setContent('<strong>Zařízení a počet:</strong><div id=\'place-info\'>' + info[currenInfo].place + '</div>' + |
65 |
'<div id=\'number-info\'>' + info[currenInfo].number + '</div>' +
|
|
68 |
'<div id=\'number-info\'><span id=\'digit-info\'>' + info[currenInfo].number + '</span>' + '<span id=\'total-info\' style="font-size: large">/' + total +'</span></div>' +
|
|
66 | 69 |
'<div class=\'popup-controls\'>' + |
67 | 70 |
'<button id=\'previous-info-btn\' class=\'circle-button\' onclick=\'previousInfo()\'></button>' + |
68 |
'<div id=\'count-info\'>' + (currenInfo + 1) + '/' + info.length + '</div>' +
|
|
71 |
'<div id=\'count-info\'>' + (currenInfo + 1) + ' z ' + info.length + '</div>' +
|
|
69 | 72 |
'<button id=\'next-info-btn\' onclick=\'nextInfo()\' class=\'circle-button next\'></button>' + |
70 | 73 |
'</div>' |
71 | 74 |
) |
... | ... | |
92 | 95 |
|
93 | 96 |
function displayInfoText() { |
94 | 97 |
$('#place-info').html(info[currenInfo].place) |
95 |
$('#number-info').html(info[currenInfo].number)
|
|
96 |
$('#count-info').html(currenInfo + 1 + '/' + info.length);
|
|
98 |
$('#digit-info').html(info[currenInfo].number)
|
|
99 |
$('#count-info').html(currenInfo + 1 + ' z ' + info.length);
|
|
97 | 100 |
} |
98 | 101 |
|
99 | 102 |
function setMapView(latitude = startX, longitude = startY, zoom = startZoom) { |
... | ... | |
155 | 158 |
$('#timeline').attr('class', 'time hour-' + currentTime); |
156 | 159 |
} |
157 | 160 |
|
158 |
function loadCurrentTimeHeatmap(route) {
|
|
161 |
function loadCurrentTimeHeatmap(opendataRoute, positionsRoute) {
|
|
159 | 162 |
|
160 |
dataSourceRoute = route; |
|
161 | 163 |
data = [] |
162 | 164 |
|
163 |
name = $('#type').children("option:selected").text();
|
|
165 |
name = $('#type').children("option:selected").val();
|
|
164 | 166 |
date = $('#date').val() |
165 | 167 |
currentTime = parseInt($('#time').children("option:selected").val()); |
166 | 168 |
setTimeline(); |
167 | 169 |
|
168 | 170 |
$.ajax({ |
169 | 171 |
type: "POST", |
170 |
url: dataSourceRoute + '/' + name + '/' + date + '/' + currentTime,
|
|
172 |
url: opendataRoute + '/' + name + '/' + date + '/' + currentTime,
|
|
171 | 173 |
success: function(result) { |
172 | 174 |
data[currentTime] = result; |
173 | 175 |
drawHeatmap(data[currentTime]); |
174 | 176 |
} |
175 | 177 |
}); |
176 | 178 |
|
179 |
$.ajax({ |
|
180 |
type: 'POST', |
|
181 |
url: positionsRoute + '/' + name, |
|
182 |
success: function(result) { |
|
183 |
drawDataSourceMarks(result) |
|
184 |
} |
|
185 |
}); |
|
186 |
|
|
177 | 187 |
preload(currentTime, 1); |
178 | 188 |
preload(currentTime, -1); |
179 | 189 |
|
180 | 190 |
} |
181 | 191 |
|
192 |
function drawDataSourceMarks(data) { |
|
193 |
|
|
194 |
if (marksLayer != null) { |
|
195 |
L.removeLayer(marksLayer); |
|
196 |
} |
|
197 |
|
|
198 |
marksLayer = L.layerGroup(); |
|
199 |
for (var key in data) { |
|
200 |
marksLayer.addLayer(L.circle([data[key]['x'], data[key]['y']], {radius: 1, color: 'black'})); |
|
201 |
} |
|
202 |
|
|
203 |
marksLayer.addTo(mymap); |
|
204 |
|
|
205 |
} |
|
206 |
|
|
182 | 207 |
function preload(time, change) { |
183 | 208 |
|
184 | 209 |
var ntime = time + change; |
website/src/Controller/HeatmapController.php | ||
---|---|---|
61 | 61 |
public function datesWithAvailableDatasets(IOpenDataManager $manager) { |
62 | 62 |
return $this->json($manager->getDatesWithAvailableCollection()); |
63 | 63 |
} |
64 |
|
|
65 |
/** |
|
66 |
* @Route("heatmap/positions/{name}", name="positions") |
|
67 |
*/ |
|
68 |
public function dataSourcePoistions(IOpenDataManager $manager, $name = 'NONE') { |
|
69 |
return $this->json($manager->getDataSourcePositions($name)); |
|
70 |
} |
|
64 | 71 |
} |
website/src/IOpenDataManager.php | ||
---|---|---|
14 | 14 |
public function getDatesWithAvailableCollection(); |
15 | 15 |
|
16 | 16 |
public function getMaxCollectionNumberAtDay($name, $date); |
17 |
|
|
18 |
public function getDataSourcePositions($name); |
|
17 | 19 |
} |
website/src/OpenDataManager.php | ||
---|---|---|
29 | 29 |
} |
30 | 30 |
|
31 | 31 |
public function getAvailableCollections() { |
32 |
$openData = $this->manager->executeQuery('open-data-db.DATASETS', new Query([], ['projection' => ['name' => 1, '_id' => 0]])); |
|
32 |
$openData = $this->manager->executeQuery('open-data-db.DATASETS', new Query([], ['projection' => ['key-name' => 1, 'display-name' => 1, '_id' => 0]]));
|
|
33 | 33 |
|
34 | 34 |
$openData->setTypeMap([ |
35 | 35 |
'array' => 'array', |
... | ... | |
45 | 45 |
$available = $this->getAvailableCollections(); |
46 | 46 |
$index = 0; |
47 | 47 |
foreach ($available as $key => $value) { |
48 |
if ($this->isCollectionAvailable($value['name'], $date) && false == array_key_exists($value['name'], $availableInDate)) {
|
|
49 |
$availableInDate[$value['name']] = $value['name'];
|
|
48 |
if ($this->isCollectionAvailable($value['key-name'], $date) && false == array_key_exists($value['key-name'], $availableInDate)) {
|
|
49 |
$availableInDate[$value['key-name']] = $value['display-name'];
|
|
50 | 50 |
} |
51 | 51 |
} |
52 | 52 |
|
... | ... | |
87 | 87 |
|
88 | 88 |
return empty($result) ? 1 : $result[0]['number']; |
89 | 89 |
} |
90 |
|
|
91 |
public function getDataSourcePositions($name = 'NONE') { |
|
92 |
$positions = $this->manager->executeQuery('open-data-db.'.$name.'DEVICES', new Query([], [])); |
|
93 |
|
|
94 |
$positions->setTypeMap([ |
|
95 |
'array' => 'array', |
|
96 |
'document' => 'array', |
|
97 |
'root' => 'array', |
|
98 |
]); |
|
99 |
|
|
100 |
return $positions->toArray(); |
|
101 |
} |
|
90 | 102 |
} |
website/src/Utils/Utils.php | ||
---|---|---|
8 | 8 |
|
9 | 9 |
$index = 0; |
10 | 10 |
foreach ($datasets as $key => $value) { |
11 |
if (false == array_key_exists($value['name'], $names)) { |
|
12 |
$names[$value['name']] = $value['name'];
|
|
11 |
if (false == array_key_exists($value['key-name'], $names)) {
|
|
12 |
$names[$value['display-name']] = $value['key-name'];
|
|
13 | 13 |
} |
14 | 14 |
} |
15 | 15 |
|
website/templates/heatmap.html.twig | ||
---|---|---|
160 | 160 |
initMap(); |
161 | 161 |
checkDataSetsAvailability("{{ path('available') }}") |
162 | 162 |
{% if submitted %} |
163 |
loadCurrentTimeHeatmap("{{ path('opendata') }}"); |
|
163 |
loadCurrentTimeHeatmap("{{ path('opendata') }}", "{{ path('positions') }}");
|
|
164 | 164 |
{% endif %} |
165 | 165 |
|
166 | 166 |
var datesetDates = '23-04-2019,24-04-2019,25-04-2019,24-05-2020,27-05-2020'.split(','); |
Také k dispozici: Unified diff
Re #8092, Re #8085
+ data source points location layer - circles
+ total number of activity in aggregation