-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
179 lines (168 loc) · 7.69 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html>
<head>
<title>Monitoramento Bike Sampa</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<h1>Mapa das estações <small style="font-size: 10px;">(Última atualização: {{last_update}})</small></h1>
<div class="btn-group" id="tipo-mapa" role="group">
<button class="btn bikes btn-xs btn-default active">Ver mapa das bicicletas</button>
<button class="btn viagens btn-xs btn-default">Ver mapa de calor das viagens</button>
</div>
<div id="chart" style="width: 100%; height: 500px; margin-top: 10px;"></div>
<h1>Lista de estações</h1>
<p>
<button class="btn btn-filtro filtro-com btn-success">Com bicicletas</button>
<button class="btn btn-filtro filtro-sem btn-warning">Sem bicicletas</button>
<button class="btn btn-filtro filtro-off btn-danger">Em manutenção</button>
</p>
<table class="table table-striped table-hover" id="estacoes">
<thead>
<tr>
<th><strong>Estação</strong></th>
<th>Bicicletas</th>
<th>Capacidade</th>
<th>Viagens</th>
<th>Nome</th>
<th>Endereço</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for estacao in estacoes %}
<tr class="estacao
{% if estacao.funcionando and estacao.bicicletas == 0 %}warning{% endif %}
{% if estacao.funcionando and estacao.bicicletas > 0 %}success{% endif %}
{% if not estacao.funcionando %}danger{% endif %}
" data-local="{{estacao.local}}" data-numero="{{estacao.numero}}"
data-bicicletas="{{estacao.bicicletas}}" data-viagens="{{estacao.interacoes}}">
<td align="right"><strong>{{estacao.numero}}</strong></td>
<td>{{estacao.bicicletas}}</td>
<td>{{estacao.vagas}}</td>
<td>{{estacao.interacoes}}</td>
<td>{{estacao.nome}}</td>
<td>{{estacao.endereco}}</td>
<td>{{estacao.status}}</td>
</tr>
{%- endfor %}
</tbody>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?libraries=visualization&sensor=false"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
$(document).ready(function(){
// Aplica o filtro dos botoes
var botoes;
if(!localStorage.getItem('filtro-conf')){
botoes = {
'filtro-com': [true, 'success'],
'filtro-sem': [true, 'warning'],
'filtro-off': [false, 'danger'],
}
localStorage.setItem('filtro-conf', JSON.stringify(botoes));
}else{
botoes = JSON.parse(localStorage.getItem('filtro-conf'));
}
for(botao in botoes){
if(botoes[botao][0]){
$("."+botao).addClass('active');
}else{
$("#estacoes tr."+botoes[botao][1]).hide();
}
}
$('.btn-filtro').click(function(){
var $this = $(this);
for(i in botoes){
if($this.hasClass(i)){
console.log(i)
botoes[i][0] = !botoes[i][0]
$this.toggleClass('active');
$("#estacoes tr."+botoes[i][1]).toggle();
}
}
localStorage.setItem('filtro-conf', JSON.stringify(botoes));
});
// Visualizacao do mapa
$("#tipo-mapa .btn").click(function(){
$("#tipo-mapa .btn").toggleClass("active");
$this = $(this);
if($this.hasClass("bikes")){
window.map_cluster.addMarkers(window.markers);
}else{
window.map_cluster.removeMarkers(window.markers);
}
if($this.hasClass("viagens")){
window.map_heat.setMap(window.map);
window.map_heat.setData(window.heatMapData);
}else{
window.map_heat.setData([]);
}
});
// Plotagem do mapa
var center = new google.maps.LatLng(-23.5715396,-46.6572312);
window.map = new google.maps.Map(document.getElementById("chart"),{
zoom: 12,
'center': center,
mapTypeId: google.maps.MapTypeId.ROADMAP,
});
var estacoes = [
{% for estacao in estacoes %}
{% if estacao.funcionando %}
[{{estacao.numero}}, {{estacao.bicicletas}}, {{estacao.local}}, {{estacao.interacoes}}],
{%- endif %}
{%- endfor %}
]
window.markers = [];
window.heatMapData = [];
for(i in estacoes){
var estacao = estacoes[i];
for(x=0;x<estacao[1];x++){
markers.push(
new google.maps.Marker({
position: new google.maps.LatLng(estacao[2]+x*0.00004, estacao[3]+x*0.00004),
title: 'Estação '+estacao[0],
})
)
}
heatMapData.push({
location: new google.maps.LatLng(estacao[2], estacao[3]),
weight: Math.sqrt(estacao[4])
});
}
window.map_cluster = new MarkerClusterer(map, markers);
window.map_heat = new google.maps.visualization.HeatmapLayer({
radius: 10,
opacity: 1
});
$(".estacao").css("cursor", "pointer");
$(".estacao").click(function(){
var $this = $(this);
window.scrollTo(0,0);
if(!window.estacao_marker){
window.estacao_marker = new google.maps.Marker();
}
if(!window.estacao_info) window.estacao_info = new google.maps.InfoWindow()
var pos = $this.attr("data-local").split(',')
var latlng = new google.maps.LatLng(pos[0], pos[1]);
estacao_marker.setPosition(latlng);
estacao_marker.setMap(window.map);
estacao_info.setContent("Estação: <strong>"+$this.attr("data-numero")+"</strong>"+
"<br>Bicicletas disponíveis: <strong>"+$this.attr("data-bicicletas")+"</strong>"+
"<br>Viagens feitas hoje: <strong>"+$this.attr("data-viagens")+"</strong>"
)
estacao_info.setPosition(latlng);
estacao_info.open(window.map, estacao_marker)
});
});
</script>
</body>
<html>