-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
297 lines (243 loc) · 8.31 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
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
<html>
<head>
<title>Draw the border!</title>
<link rel=stylesheet href="lib/css/bootstrap.css" type="text/css">
<link rel=stylesheet href="lib/css/bootstrap-responsive.css" type="text/css">
<link rel=stylesheet href="lib/css/style.css" type="text/css">
<script src="data/levels.js"></script>
<script src="lib/js/jquery.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="lib/js/underscore.js"></script>
<script src="lib/js/backbone.js"></script>
<script src="lib/js/bootstrap.js"></script>
<script>
var CityModel = Backbone.Model.extend({
parse: function(data){
// parse ints and floats
data['usa'] = parseInt(data['usa']);
data['gdp'] = parseInt(data['gdp'].replace('$', '').replace(',',''));
data['latitude'] = parseFloat(data['lat']);
data['longitude'] = parseFloat(data['lon']);
data['population'] = parseInt(data['population'].replace(',',''));
// delete the old properties
delete data['lat'];
delete data['lon'];
return data;
},
in_usa: function(){
return this.get('usa');
},
plot: function(){
return new google.maps.LatLng(this.get('latitude'), this.get('longitude'));
},
});
var CitiesCollection = Backbone.Collection.extend({
model: CityModel,
url: 'data/counties.json',
parse: function(data){
that = this;
_.each(data, function(city, i){
var city = new CityModel(city, {parse: true});
data[i] = city;
});
return data;
}
});
var CityContentView = Backbone.View.extend({
template: _.template('\
<h3><%= cityData.title %></h3>\
<h5><%= cityData.geography %></h5>\
<div style="font-size:12px">\
<span>\
Population:\
</span>\
<%= cityData.population %> \
</br>\
<span>\
High school graduates:\
</span>\
<%= cityData.graduates_percent %>\
</br>\
<span>\
Unemployment rate:\
</span> \
<%= cityData.unemployment %>\
</br>\
<span>\
GDP per capita:\
</span>\
<%= cityData.gdp %>\
</br>\
</div>'),
render: function(){
$(this.el).html( this.template({ cityData: this.model.toJSON()}) );
return this;
}
});
var map, poly, frontera;
var tableId = '1aJ_-XLrNBF8x1xvmCDBSzStfNh6cKNFEGmgqXiI';
var cities = new CitiesCollection();
cities.fetch({success: function(){ data = initialize(); }});
LEVEL_COUNTER = 0;
function initialize() {
frontera = new google.maps.FusionTablesLayer({
query: {
select: 'geometry',
from: tableId,
},
styles : [{
polylineOptions: {
strokeColor: "#00FF00",
strokeWeight: "5" },
polygonOptions: {
fillColor: '#00FF00',
fillOpacity: 0.3
}
}],
options: {
clickable: false
}
});
var polyOptions = {
strokeColor: '#000',
strokeOpacity: 1.0,
strokeWeight: 2,
editable: false //users?
}
initial_options = {
center: new google.maps.LatLng(levels[LEVEL_COUNTER].center[0],
levels[LEVEL_COUNTER].center[1]),
zoom: 11,
mapTypeId: google.maps.MapTypeId.SATELLITE,
draggable: false,
disableDoubleClickZoom: true,
mapTypeControl: false,
navigationControl: true,
panControl: false,
scrollwheel: false,
streetViewControl: false,
scaleControl: false,
zoomControl: false,
zoomControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT
},
};
done_options = {
panControl: true,
panControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT
},
scrollwheel: true,
zoomControl: true,
draggable:true,
scrollwheel:true,
}
poly = new google.maps.Polyline(polyOptions);
$(document).ready(function(){
map = new google.maps.Map(document.getElementById('map-canvas'), initial_options);
poly.setMap(map);
google.maps.event.addListener(map, 'click', addLatLng);
});
var lineBoxes = document.createElement('div');
lineBoxes.id = 'line-boxes';
lineBoxes.innerHTML='<input type="checkbox" class="box" id="line-edit-check" onclick="editLine()"/><label for="line-edit-check"> Edit line</label></br><button id="done-button" onclick="doneDrawing()"/><label for="done-button">Done!</label></button>';
lineBoxes.index = 1;
map.controls[google.maps.ControlPosition.TOP_LEFT].push(lineBoxes);
return cities.toJSON();
}
/**
* Handles click events on a map, and adds a new point to the Polyline.
* @param {google.maps.MouseEvent} event
*/
function addLatLng(event) {
var path = poly.getPath();
// Because path is an MVCArray, we can simply append a new coordinate
// and it will automatically appear
path.push(event.latLng);
}
function removePos() {
var path = poly.getPath();
//take last point off path
path.b.pop();
//clear then reset path
poly.setMap();
poly.setMap(map);
}
function editLine() {
var box = $('#line-edit-check')[0];
if (box.checked == true) {
poly.setEditable(true);
}
else {
poly.setEditable(false);
}
}
function doneDrawing() {
$('#line-edit-check')[0].checked = false;
poly.setEditable(false);
poly.strokeOpacity=0.5;
poly.setMap();
poly.setMap(map);
frontera.setMap(map);
setTimeout("showInfo()", 1500);
}
function showInfo() {
var mexicanCity = cities.get(levels[LEVEL_COUNTER].mexCity);
openCityWindow(mexicanCity);
var usCity = cities.get(levels[LEVEL_COUNTER].usCity);
openCityWindow(usCity);
map.setOptions(done_options);
addNextButton();
}
function openCityWindow(city) {
var cityLocation = city.plot();
var cityWindow = new google.maps.InfoWindow();
var cityContent = new CityContentView({model: city});
cityWindow.setContent(cityContent.render().el);
cityWindow.setPosition(cityLocation);
cityWindow.open(map);
}
function addNextButton () {
var nextButton = document.createElement('button');
nextButton.onclick = nextLevel;
nextButton.innerHTML='Next location';
map.controls[google.maps.ControlPosition.TOP_CENTER].push(nextButton);
}
function nextLevel() {
if (LEVEL_COUNTER !== (levels.length - 1)) {
LEVEL_COUNTER++;
} else { LEVEL_COUNTER = 0; }
initialize();
}
function getData(pos) {
for (var i=0; i<data.length; i++) {
if (data[i].ID === pos) {
var regData = data[i];
}
}
return regData;
}
</script>
</head>
<body>
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<a class="brand" href="#">Naco</a>
<ul class="nav">
<li class="active"><a href="#">Draw the Border</a></li>
<li><a href="naco.html">Naco or Naco?</a></li>
</ul>
</div>
</div>
<div class="container">
<h1> Draw the border!</h1>
<p class="lead">The <a href="http://apps.npr.org/borderland/">2,000-mile border</a> between the United States and Mexico divides the border city pictured below. Can you draw the line that splits this city?</p>
<p>Sources: <a href="http://factfinder2.census.gov/faces/nav/jsf/pages/index.xhtml">American Community Survey</a>, <a href="http://www.snim.rami.gob.mx/">Sistema Nacional de Informacion Municipal</a> county data</p>
<small>This is a <a href="http://www.chicagomigrahack.com/">Migrahack</a> prototype! Tweet feedback to <a href="https://twitter.com/DanHillReports">@DanHillReports</a></small>
<div class="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
Start clicking on the map to create the points to construct your border line. Click "Done!" to see the real border in green and learn about the cities on each side. After you've clicked "Done!", click "Next location" to try a new pair of border cities.
</div>
<div id="map-canvas"></div>
</body>
</html>