-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_for_iframe.html
464 lines (394 loc) · 16.5 KB
/
map_for_iframe.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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<link href='iframe_style.css' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="slide.js"></script>
</head>
<body>
<div id="map"></div>
<div id="tool-tip"></div>
<div id="legends">
<div id="legend_countries" class="legend">
<p class="legend_title">COUNTRY PM<sub>2.5</sub> LEVELS</p>
<span class="country_leftest">0.03</span><span class="country_rightest">49.92</span><br>
<aside class="country_colors">
<div style="background-color:#fff74b;"></div>
<div style="background-color:#ffd72d;"></div>
<div style="background-color:#FFaa00;"></div>
<div style="background-color:#FF8200;"></div>
<div style="background-color:#FF5a00;"></div>
<div style="background-color:#FF3200;"></div>
<div style="background-color:#f50000;"></div>
<div style="background-color:#c30000;"></div>
<div style="background-color:#870000;"></div>
<div style="background-color:#4e0000;"></div>
</aside>
</div>
<div id="legend_countries_gray" class="legend" style="display:none">
<p class="legend_title">COUNTRY PM<sub>2.5</sub> LEVELS</p>
<span class="country_leftest">0.03</span><span class="country_rightest">49.92</span><br>
<aside class="country_colors">
<div style="background-color:#262626;"></div>
<div style="background-color:#3B3B3B;"></div>
<div style="background-color:#4F4F4F;"></div>
<div style="background-color:#636363;"></div>
<div style="background-color:#787878;"></div>
<div style="background-color:#8C8C8C;"></div>
<div style="background-color:#A1A1A1;"></div>
<div style="background-color:#B5B5B5;"></div>
<div style="background-color:#C9C9C9;"></div>
<div style="background-color:#DEDEDE;"></div>
</aside>
</div>
<div id="legend_cities" class="legend" style="display:none">
<p class="legend_title">CITY PM<sub>2.5</sub> LEVELS</p><br>
<span class="city_leftest">2</span><span class="city_rightest">153</span><br>
<aside class="city_colors">
<div style="background-color:#fff74b;"></div>
<div style="background-color:#ffd72d;"></div>
<div style="background-color:#FFaa00;"></div>
<div style="background-color:#FF8200;"></div>
<div style="background-color:#FF5a00;"></div>
<div style="background-color:#FF3200;"></div>
<div style="background-color:#f50000;"></div>
<div style="background-color:#c30000;"></div>
<div style="background-color:#870000;"></div>
<div style="background-color:#4e0000;"></div>
</aside>
</div>
</div>
<div id="slide_out_info">
<a class="handle" href="#">
<span id="rotated_text">Map Info</span>
</a>
<div class="content">
<h1>Air pollution trends in countries and cities</h1> <br>
In 2012, the <a href="http://www.who.int/mediacentre/news/releases/2014/air-pollution/en/" target="_blank">World Health Organization (WHO)</a> estimates 7 million people died - one in eight deaths - due to air pollution exposure. This map shows both national and city-level exposures to fine particulate matter or PM<sub>2.5</sub>, which is an air pollutant with human health consequences.<br><br>
City-level data (represented as points in the map) for around 1,600 cities in 91 countries from 2008 to 2013 are provided in the <a href="http://www.who.int/phe/health_topics/outdoorair/databases/AAP_database_methods_2014.pdf?ua=1" target="_blank">WHO's Ambient Air Pollution database</a>. These values for cities generally represent annual averaged data from a single or multiple air monitoring stations.<br><br>
The national data (represented by the country shading) are from the 2014 <a href="http://www.epi.yale.edu/" target="_blank">Environmental Performance Index (EPI)</a>. Researchers led by <a href="http://myweb.dal.ca/adonkela/main.swf" target="_blank">Aaron van Donkelaar</a> at Dalhousie University used satellite data to estimate ground-level exposures to fine particulate matter (PM<sub>2.5</sub>). These data indicate longer term exposures to PM<sub>2.5</sub> and are based on a three-year rolling average of data from 1998 to 2012. Read more about how these data were developed <a href="http://epi.yale.edu/our-methods/air-quality" target="_blank">here</a>.<br><br>
<h1><b>ABOUT THE ENVIRONMENTAL PERFORMANCE INDEX (EPI)</b></h1><br>
The <a href="http://www.epi.yale.edu/" target="_blank">Environmental Performance Index</a> is a biennial global ranking of how well countries perform on high-priority environmental issues. It is a joint project of the <a href="http://envirocenter.yale.edu/" target="_blank">Yale Center for Environmental Law & Policy</a> and the <a href="http://ciesin.columbia.edu/" target="_blank">Center for International Earth Science Information Network</a> at The Earth Institute, Columbia University.
<br><br><br>
<span>Created by <a href="http://spinsomewebs.com/" target="_blank">Pedro Cunha</a> and <a href="http://www.dmitrypavluk.com" target="_blank">Dmitry Pavluk</a> using CartoDB <br>with help from <a href="https://twitter.colorsm/andrewxhill" target="_blank">Andrew Hill</a>, Anna Young, and Diego Torres Quintanilla</span>
</div>
</div>
<div id="header_container">
<div id="header">
<div id="layer_selector" class="cartodb-infobox">
<ul>
<ul class="countries_label"> Countries: <br></ul>
<li data="2000">2000</li>
<li data="2001">2001</li>
<li data="2002">2002</li>
<li data="2003">2003</li>
<li data="2004">2004</li>
<li data="2005">2005</li>
<li data="2006">2006</li>
<li data="2007">2007</li>
<li data="2008">2008</li>
<li data="2009">2009</li>
<li data="2010">2010</li>
<li data="2011">2011</li>
<li data="2012" class="selected">2012</li>
</ul>
</div>
<div id="layer_selector2" class="cartodb-infobox">
<p data="pm_2_5" id="show_cities">Show Cities</p>
</div>
</div>
</div>
</body>
<script type="cartocss/html" id="cities">
/*City Styles*/
#who_georeferenced_clean_v2{
marker-fill-opacity: 0.8;
marker-line-color: #FFF;
marker-line-width: 1.5;
marker-line-opacity: 1;
marker-width: 10;
marker-fill: #FFFFB2;
marker-allow-overlap: true;
}
#who_georeferenced_clean_v2 [ pm_2_5 <= 154] {
marker-fill: #4e0000;
}
#who_georeferenced_clean_v2 [ pm_2_5 <= 140] {
marker-fill: #870000;
}
#who_georeferenced_clean_v2 [ pm_2_5 <= 125] {
marker-fill: #c30000;
}
#who_georeferenced_clean_v2 [ pm_2_5 <= 110] {
marker-fill: #f50000;
}
#who_georeferenced_clean_v2 [ pm_2_5 <= 90] {
marker-fill: #FF3200;
}
#who_georeferenced_clean_v2 [ pm_2_5 <= 69] {
marker-fill: #FF5a00;
}
#who_georeferenced_clean_v2 [ pm_2_5 <= 55] {
marker-fill: #FF8200;
}
#who_georeferenced_clean_v2 [ pm_2_5 <= 41] {
marker-fill: #FFaa00;
}
#who_georeferenced_clean_v2 [ pm_2_5 <= 28] {
marker-fill: #ffd72d;
}
#who_georeferenced_clean_v2 [ pm_2_5 <= 15] {
marker-fill: #fff74b;
}
</script>
<script type="cartocss/html" id="pm25_na">
/*Country Styles*/
#pm25_na{
polygon-fill: #FFFFB2;
polygon-opacity: 0.8;
line-color: #FFF;
line-width: 1;
line-opacity: 1;
}
#pm25_na [ {0} <= 49.92] {
polygon-fill: #4e0000;
}
#pm25_na [ {0} <= 32.54] {
polygon-fill: #870000;
}
#pm25_na [ {0} <= 25.17] {
polygon-fill: #c30000;
}
#pm25_na [ {0} <= 15.17] {
polygon-fill: #f50000;
}
#pm25_na [ {0} <= 10.85] {
polygon-fill: #FF3200;
}
#pm25_na [ {0} <= 9.15] {
polygon-fill: #FF5a00;
}
#pm25_na [ {0} <= 8.15] {
polygon-fill: #FF8200;
}
#pm25_na [ {0} <= 6.06] {
polygon-fill: #FFaa00;
}
#pm25_na [ {0} <= 4.62] {
polygon-fill: #ffd72d;
}
#pm25_na [ {0} <= 2.98] {
polygon-fill: #fff74b;
}
</script>
<script type="cartocss/html" id="pm25_gray">
/*Country Styles*/
#pm25_na{
polygon-fill: #121212;
polygon-opacity: 0.8;
line-color: #FFF;
line-width: 1;
line-opacity: 1;
}
#pm25_na [ {0} <= 49.92] {
polygon-fill: #262626;
}
#pm25_na [ {0} <= 32.54] {
polygon-fill: #3B3B3B;
}
#pm25_na [ {0} <= 25.17] {
polygon-fill: #4F4F4F;
}
#pm25_na [ {0} <= 15.17] {
polygon-fill: #636363;
}
#pm25_na [ {0} <= 10.85] {
polygon-fill: #787878;
}
#pm25_na [ {0} <= 9.15] {
polygon-fill: #8C8C8C;
}
#pm25_na [ {0} <= 8.15] {
polygon-fill: #A1A1A1;
}
#pm25_na [ {0} <= 6.06] {
polygon-fill: #B5B5B5;
}
#pm25_na [ {0} <= 4.62] {
polygon-fill: #C9C9C9;
}
#pm25_na [ {0} <= 2.98] {
polygon-fill: #DEDEDE;
}
</script>
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
<script>
$('#layer_selector li').click(function() {
$('#layer_select li').addClass('selected');
});
var col1 = 'pm25_2000';
var col2 = '';
var country = 'country';
var city = 'city_station';
var pm = 'pm_2_5';
//Formats the columns for us into css
String.prototype.format = (function (i, safe, arg) {
function format() {
var str = this,
len = arguments.length + 1;
for (i = 0; i < len; arg = arguments[i++]) {
safe = typeof arg === 'object' ? JSON.stringify(arg) : arg;
str = str.replace(RegExp('\\{' + (i - 1) + '\\}', 'g'), safe);
}
return str;
}
//format.native = String.prototype.format;
return format;
})();
// create layer selector
function main() {
var map = new L.Map('map', {
zoomControl: true,
legend:true,
center: [43, 0],
zoom: 2,
scrollWheelZoom: true,
searchControl: true
});
// create our layers
cartodb.createLayer(map, {
user_name: 'dmonay',
type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM bathymetry_layers",
cartocss: "#bathymetry_layers{ polygon-fill: #598cdb;polygon-opacity: 0.2;line-color: #FFF;line-width: 0;line-opacity: 1;}"
},{
sql: "SELECT * FROM pm25_na",
cartocss: $('#pm25_na').html().format('pm25_2000'),
interactivity: "cartodb_id, the_geom, pm25_2000, pm25_2001, pm25_2002, pm25_2003, pm25_2004, pm25_2005, pm25_2006, pm25_2007, pm25_2008, pm25_2009, pm25_2010, pm25_2011, pm25_2012, country"
},{
sql: "SELECT * FROM who_georeferenced_clean_v2",
cartocss: $('#cities').html().format('city_station'),
interactivity: "city_station, pm_2_5, country"
}]
}).done(function(layer) {
// add the layers to our map
map.addLayer(layer);
sublayer_country = layer.getSubLayer(1);
sublayer_country.setInteraction(true);
sublayer_city = layer.getSubLayer(2);
sublayer_city.setInteraction(true);
createSelector(sublayer_country);
createSelector(sublayer_city);
sublayer_city.hide();
//create infowindow
sublayer_city.infowindow.set('template', $('#infowindow_template').html()).on('error', function() {
console.log("some error occurred");
});
//Make Tool-tip follow the mouse.
var event = function(e){
$('#tool-tip').css({
left: e.pageX,
top: e.pageY
});
};
//Retrieve data to the tooltip on countries
sublayer_country.on('featureOver', function(e, pos, latlng, data) {
$('#tool-tip').html('<p>' +data[country]+'<br>'+ data[col1] + 'μg/m<sup>3</sup></p>');
$(document).bind('mousemove', event);
$('#tool-tip').show();
});
sublayer_country.on('featureOut', function(e, pos, latlng, data) {
//Make the tooltip go away when off countries
$('#tool-tip').hide();
$(document).unbind('mousemove', event, false);
});
//Retrieve data to the tooltip on cities
sublayer_city.on('featureOver', function(e, pos, latlng, data) {
$('#tool-tip').html('<p>' +data[city]+', '+data[country]+ '<br>'+data[pm]+ 'μg/m<sup>3</sup></p>');
$(document).bind('mousemove', event);
$('#tool-tip').show();
});
sublayer_city.on('featureOut', function(e, pos, latlng, data) {
//Make the tooltip go away when off cities
$('#tool-tip').hide();
$(document).unbind('mousemove', event, false);
});
});
}
window.onload = main;
/*Selection process ------------------------------------------ */
var styles = {}, selectedStyle;
// create layer selector
function createSelector(layer) {
var $options = $('#layer_selector li');
$options.click(function(e) {
// get the area of the selected layer
var $li = $(e.target);
var year = $li.attr('data');
// deselect all and select the clicked one
$options.removeClass('selected');
$li.addClass('selected');
col1 = 'pm25_' + year;
var style = $('#pm25_na').html().format(col1);
layer.setCartoCSS(style);
sublayer_city.hide();
$('#show_cities').removeClass('shown');
$("#show_cities").text("Show Cities");
$("#legend_cities").hide();
$("#legend_countries").removeClass("cities_label");
$(".cartodb-legend:nth-child(1)").show();
});
}
$("#show_cities").on("click", function(){
if ($("#show_cities").hasClass('shown'))
{
sublayer_city.hide();
var year = $('#layer_selector li.selected').attr('data');
col1 = 'pm25_' + year;
$("#legend_countries_gray").hide();
$("#legend_cities").hide();
$("#legend_countries").show();
$("#show_cities").removeClass('shown');
$("#show_cities").text("Show Cities");
var style = $('#pm25_na').html().format(col1);
sublayer_country.setCartoCSS(style);
$("#legend_countries").removeClass("cities_label");
}
else
{
//Set the column to the city_station from our cities table
col2 = 'city_station';
//create a local variable named style and convert our cities script above to html and run the format function defined above to render some CSS.
var style = $('#cities').html().format(col2);
//Attached the CSS to the layer
sublayer_city.setCartoCSS(style);
sublayer_city.show();
// Set countries to gray
var style = $('#pm25_gray').html().format(col1);
sublayer_country.setCartoCSS(style);
$("#legend_countries_gray").show();
$("#legend_cities").show();
$("#legend_countries").hide();
//Hide legend on click
//$("#legend_cities").show();
$("#show_cities").addClass('shown');
$("#show_cities").text("Hide Cities");
$("#legend_countries").addClass("cities_label");
}
});
//have the info tab slide out
$('#slide_out_info').tabSlideOut({
tabHandle: '.handle', //class of the element that will become your tab
//Optionally can be set using css
height: '110px', //height of tab image //Optionally can be set using css
width: '30px', //width of tab image //Optionally can be set using css
tabLocation: 'right', //side of screen where tab lives, top, right, bottom, or left
speed: 400, //speed of animation
action: 'click', //options: true makes it stick(fixed position) on scroll
});
</script>
</script>
</html>