This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathv1.html
328 lines (288 loc) · 13.3 KB
/
v1.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<html>
<head>
<meta charset="utf-8">
<title>Mapa de ônibus de Fortaleza</title>
<link rel="stylesheet" type="text/css" href="libs/chosen.css" />
<link rel="stylesheet" type="text/css" href="style/gh-buttons.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="libs/underscore-min.js" charset="utf-8"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="libs/icanhaz.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="libs/backbone-min.js" charset="utf-8" ></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script type="text/javascript" src="libs/chosen.jquery.js"></script>
<script type="text/javascript" src="arrows.js"></script>
<script type="text/javascript" src="intersection.js" charset="utf-8" ></script>
<script id="lineList" type="text/html">
<p><strong>Escolhe uma linha :</strong> <select data-placeholder="Escolhe uma linha" class="chzn-select">
{{#table}}
{{#rows}}
<option value="{{num}}">{{label}}</option>
{{/rows}}
{{/table}}
</select></p>
</script>
<script id="markerList" type="text/html">
<ul>
{{#models}}
<li><button class="button icon remove danger" onClick="busMap._markerList.removeByIndex({{index}})">Ponto {{num}}</button></li>
{{/models}}
</ul>
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26151767-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<h3>Mapa de ônibus de Fortaleza</h3>
<div id="wrapper">
<div id="filter">
<h4>Filtrar linhas:</h4>
<p class="description justify"><i>Filtrar a lista de linhas pela adição de pontos onde o ônibus tem que passar (< 1 km).</i></p>
<button class="button icon pin big" onClick="busMap._markerList.add(new Marker());">Addicionar ponto</button>
<div id="listmarkers"></div>
</div>
<div id="map">
<div id="listlines">
</div>
<div id="map_canvas"></div>
</div>
</div>
<div id="map_footer">
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a href="http://www.addthis.com/bookmark.php?v=250&pubid=ra-4e8d941115aebb57" class="addthis_button_compact">Share</a>
<span class="addthis_separator">|</span>
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4e8d941115aebb57"></script>
<!-- AddThis Button END -->
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4e8d941115aebb57"></script>
<div id="about">
<h4>Sobre o aplicativo</h4>
<ul>
<li>Os dados são do <a href="http://www.fortaleza.ce.gov.br/etufor/index.php?option=com_content&task=view&id=278">etufor</a></li>
<li><em>Os dados não são atualizados automaticamente. (Última actualização: 2011/10/05)</em></li>
<li>Você pode pesquisar as linhas passando por uma rua <a href="http://www.fortaleza.ce.gov.br/etufor/index.php?option=com_etuforonibusitinerarios">aqui</a></li>
<li>Fontes do aplicativo no <a href="https://github.com/tdurand/mapafortaleza/">Github</a> (pode enviar <a href="https://github.com/tdurand/mapafortaleza/issues/new">sugestão de funcionalidade</a>)</li>
</ul>
<h4>Contribuidores</h4>
<ul>
<li><a href="https://github.com/regismesquita">Regis David Souza Mesquita</a> (<a href="https://twitter.com/#!/regismesquita">@regismesquita</a>): Sistema de filtragem pela posição </li>
<li><a href="https://github.com/tdurand">Thibault Durand</a> (<a href="https://twitter.com/#!/tibbb">@tibbb</a>): Criador da aplicação </li>
<ul>
</div>
<script>
ich.grabTemplates();
var Map = Backbone.Model.extend({
initialize : function() {
this.myLatlng = new google.maps.LatLng(-3.71969,-38.52562);
this.myOptions = {
zoom: 13,
center: this.myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
this.map = new google.maps.Map(document.getElementById("map_canvas"), this.myOptions);
this.setArrows=new ArrowHandler(this.map);
this.lines=[];
this.fetch();
},
url:function() {
//HACK because etufor data set is not consistent
if(this.name!=undefined && this.name.length==2) {
this.name=this.name+" -";
}
return "https://www.google.com/fusiontables/api/query?sql=SELECT geometry FROM 1628071 WHERE name STARTS WITH '"+this.name+"'&jsonCallback=?"
},
parse : function(response) {
var setArrows=this.setArrows;
var map=this.map;
var lines=this.lines;
//remove previous lines
_.each(lines,function(line) {
line.setMap(null);
});
//remove all previous arrows
_.each(setArrows.arrows,function(arrow) {
arrow.setMap(null);
});
//reinit set of arrows
setArrows.arrows=[];
//Parse response
response.table.rows=_.flatten(response.table.rows);
//For each coordinate, create a gmap.Latlng object, and display it
response.table.rows=_(response.table.rows).each(function (row){
row.coordinates=_(row.coordinates).map(function(coord) {
return new google.maps.LatLng(coord[1],coord[0]);
});
lines.push(createPoly(row.coordinates,"midline",setArrows,map));
});
},
displayLine : function(name) {
this.name=name;
this.fetch();
},
getMap : function(){
return this.map;
},
});
var Marker = Backbone.Model.extend({
initialize : function() {
var markerBone = this;
this.marker = new google.maps.Marker({position: busMap.getMap().center ,map: busMap.getMap() , draggable: true});
google.maps.event.addListener(this.marker, 'dragend', function(mouse) {
markerBone.fetch({success: function(model,response){
busMap._markerList.updateLineList();
}});
});
markerBone.fetch({success: function(model,response){
busMap._markerList.updateLineList();
}});
},
url:function() {
return "https://www.google.com/fusiontables/api/query?sql=SELECT name FROM 1628071 WHERE ST_INTERSECTS(geometry,CIRCLE(LATLNG"+this.marker.position+",1000))&jsonCallback=?"
},
parse : function(response) {
response.table.rows=_.flatten(response.table.rows);
response.table.rows=_.reject(response.table.rows,function(row) {
if(row.split("-")[2]==" Volta") {
return true;
}
else {
return false;
}
});
return response;
},
});
var MarkerList = Backbone.Collection.extend({
_view : null,
model: Marker,
updateLineList : function() {
this._view=new MarkerListView({model : this});
this._view.render();
if(this.models.length>0) {
busMap._lineList._view=new LineListView({model : this.computeLineList()});
busMap._lineList._view.renderJSON();
}
else {
busMap._lineList.reinit();
}
},
computeLineList : function(){
var markers_routes = this.models.map(function(mark){return mark.attributes.table.rows});
var rotas = arrayIntersection(markers_routes);
return {table: {rows: rotas.map(function(row) {
var array=row.split("-");
return { num: array[0],label: array[0]+array[1]};
})}};
},
toJSON : function() {
var listMarkers=this.models;
return {models: _.map(listMarkers,function(mark,i) {
return {num: i+1,index: i};
})};
},
removeByIndex : function(index) {
var markerToRemove=this.at(index);
markerToRemove.marker.setMap(null);
this.remove(markerToRemove);
this.updateLineList();
}
});
var MarkerListView = Backbone.View.extend({
el : $("#listmarkers"),
render : function() {
//console.log(this.model.toJSON());
this.el.html(ich.markerList(this.model.toJSON()));
return this;
}
});
var LineList = Backbone.Model.extend({
_view : null,
initialize : function() {
this.fetch();
this.bind("change", function() {
this._view=new LineListView({model : this});
this._view.render();
});
},
url:function() {
return "https://www.google.com/fusiontables/api/query?sql=SELECT name FROM 1628071&jsonCallback=?"
},
parse : function(response) {
response.table.rows=_.flatten(response.table.rows);
response.table.rows=_.reject(response.table.rows,function(row) {
if(row.split("-")[2]==" Volta") {
return true;
}
else {
return false;
}
});
response.table.rows=_.map(response.table.rows,function(row) {
var array=row.split("-");
return { num: array[0],label: array[0]+array[1]};
});
return response;
},
reinit : function() {
this.fetch();
this._view=new LineListView({model : this});
this._view.render();
}
});
var LineListView = Backbone.View.extend({
el : $("#listlines"),
render: function() {
this.el.html(ich.lineList(this.model.toJSON()));
$(".chzn-select").chosen({no_results_text: "No results matched"}).change(function () {
busMap.navigate("line/"+$(".chzn-select").val(),true);
});
busMap.navigate("line/"+$(".chzn-select").val(),true);
return this;
},
renderJSON: function() {
this.el.html(ich.lineList(this.model));
$(".chzn-select").chosen({no_results_text: "No results matched"}).change(function () {
busMap.navigate("line/"+$(".chzn-select").val(),true);
});
busMap.navigate("line/"+$(".chzn-select").val(),true);
return this;
}
});
var BusMap = Backbone.Router.extend({
routes : {
"": "index",
"line/:name": "displayLine"
},
initialize : function() {
this._lineList=new LineList();
this._markerList=new MarkerList();
this._map=new Map();
},
index : function() {
},
getMap : function(){
return this._map.getMap();
},
displayLine : function(name) {
this._map.displayLine(name);
}
});
var busMap=new BusMap();
Backbone.history.start();
</script>
</body>
</html>