Revize 64bc2934
Přidáno uživatelem Jakub Vašta před téměř 5 roky(ů)
website/public/js/zcu-heatmap.js | ||
---|---|---|
1 |
var map; |
|
1 |
var mymap;
|
|
2 | 2 |
var heatmapLayer = null; |
3 | 3 |
|
4 | 4 |
var startX = 49.7248; |
... | ... | |
9 | 9 |
|
10 | 10 |
|
11 | 11 |
function initMap() { |
12 |
map = L.map('heatmap').setView([startX, startY], startZoom); |
|
12 |
mymap = L.map('heatmap').setView([startX, startY], startZoom);
|
|
13 | 13 |
|
14 | 14 |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
15 | 15 |
attribution: '', |
16 | 16 |
maxZoom: 19 |
17 |
}).addTo(map); |
|
17 |
}).addTo(mymap);
|
|
18 | 18 |
} |
19 | 19 |
|
20 | 20 |
|
21 | 21 |
function setMapView(latitude = startX, longitude = startY, zoom = startZoom) { |
22 |
map.setView([latitude, longitude], zoom); |
|
22 |
mymap.setView([latitude, longitude], zoom);
|
|
23 | 23 |
} |
24 | 24 |
|
25 | 25 |
|
... | ... | |
59 | 59 |
}, 400); |
60 | 60 |
} |
61 | 61 |
|
62 |
function showHeatmap(route, date) { |
|
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(); |
|
63 | 68 |
|
64 | 69 |
$.ajax({ |
65 | 70 |
type: "POST", |
66 |
url: route + date,
|
|
71 |
url: route + '/' + name + '/' + date + '/' + time,
|
|
67 | 72 |
success: function(result) { |
68 | 73 |
drawHeatmap(result); |
69 | 74 |
} |
... | ... | |
78 | 83 |
if (heatmapLayer != null) { |
79 | 84 |
mymap.removeLayer(heatmapLayer); |
80 | 85 |
} |
81 |
heatmapLayer = L.heatLayer(points).addTo(map), draw = true; |
|
86 |
heatmapLayer = L.heatLayer(points, {opacity: 0.5}).addTo(mymap); |
|
87 |
heatmapLayer.options = {opacity: 1}; |
|
82 | 88 |
// var heat_01 = ... |
83 | 89 |
// on background map.addLayer(heat_01) -> map.removeLayer(heat_01); |
90 |
// $(.leaflet-heatmap-layer).css('opacity', 'value'); |
|
84 | 91 |
} |
85 | 92 |
|
86 | 93 |
function checkDataSetsAvailability(route) { |
... | ... | |
105 | 112 |
options += '<option value="' + value + '">' + key + '</option>\n'; |
106 | 113 |
}); |
107 | 114 |
|
108 |
$('#types').empty().append(options);
|
|
115 |
$('#type').empty().append(options); |
|
109 | 116 |
|
110 | 117 |
} |
website/src/Controller/HeatmapController.php | ||
---|---|---|
24 | 24 |
$dataSet = $form->getData(); |
25 | 25 |
if ($form->isSubmitted()) { |
26 | 26 |
$dataSet = $form->getData(); |
27 |
// Todo do something |
|
28 | 27 |
} |
29 | 28 |
|
30 | 29 |
return $this->render( |
31 | 30 |
'heatmap.html.twig', |
32 | 31 |
[ |
33 | 32 |
'form' => $form->createView(), |
33 |
'data_to_display' => $dataSet, |
|
34 | 34 |
] |
35 | 35 |
); |
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
/** |
39 |
* @Route("heatmap/opendata/{collectionName}", name="opendata")
|
|
39 |
* @Route("heatmap/opendata/{name}/{date}/{time}", name="opendata")
|
|
40 | 40 |
*/ |
41 |
public function opendata(IOpenDataManager $manager, $collectionName) {
|
|
42 |
return $this->json($manager->getCollectionDataByName($collectionName));
|
|
41 |
public function opendata(IOpenDataManager $manager, $name = 'NONE', $date = '01012020', $time = '1') {
|
|
42 |
return $this->json($manager->getCollectionDataByName($name, $date, $time));
|
|
43 | 43 |
} |
44 | 44 |
|
45 | 45 |
/** |
website/src/IOpenDataManager.php | ||
---|---|---|
3 | 3 |
namespace App\OpenData; |
4 | 4 |
|
5 | 5 |
interface IOpenDataManager { |
6 |
public function getCollectionDataByName($name); |
|
6 |
public function getCollectionDataByName($name, $date, $hour);
|
|
7 | 7 |
|
8 | 8 |
public function getAvailableCollections(); |
9 | 9 |
|
website/src/OpenDataManager.php | ||
---|---|---|
14 | 14 |
); |
15 | 15 |
} |
16 | 16 |
|
17 |
public function getCollectionDataByName($name) { |
|
18 |
$openData = $this->manager->executeQuery($name, new Query([], []));
|
|
17 |
public function getCollectionDataByName($name, $date, $hour) {
|
|
18 |
$openData = $this->manager->executeQuery('open-data-db.'.$name.$date, new Query(['date' => $date.$hour], []));
|
|
19 | 19 |
|
20 | 20 |
$openData->setTypeMap([ |
21 | 21 |
'array' => 'array', |
website/templates/heatmap.html.twig | ||
---|---|---|
44 | 44 |
{{ form_label(form.date, 'Vyberte čas') }} |
45 | 45 |
{{ |
46 | 46 |
form_widget(form.time, { |
47 |
'id' : 'time', |
|
47 | 48 |
'attr' : { |
48 | 49 |
'class' : "custom-select" |
49 | 50 |
} |
... | ... | |
55 | 56 |
{{ form_label(form.date, 'Vybrané datové sady') }} |
56 | 57 |
{{ |
57 | 58 |
form_widget(form.type, { |
58 |
'id' : 'types',
|
|
59 |
'id' : 'type', |
|
59 | 60 |
'attr' : { |
60 | 61 |
'class' : "custom-select" |
61 | 62 |
} |
... | ... | |
164 | 165 |
<script src="{{ asset('js/zcu-heatmap.js') }}"></script> |
165 | 166 |
<script> |
166 | 167 |
initMap(); |
167 |
showHeatmap("{{ path('opendata', {'collectionName':'open-data-db.'}) }}", 'KOLOBEZKY31102018'); |
|
168 |
{% if data_to_display is defined %} |
|
169 |
showHeatmap("{{ path('opendata') }}"); |
|
170 |
{% endif %} |
|
168 | 171 |
</script> |
169 | 172 |
|
170 | 173 |
|
Také k dispozici: Unified diff
+ funkcionalita zobrazení jednotlivých datasetů - zatím bez animace