forked from madewulf/MigrationsMap.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
515 lines (471 loc) · 21.2 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
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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
<!DOCTYPE HTML>
<html manifest="/cache.manifest" itemscope itemtype="http://schema.org/Visualization">
<head>
<title>Migrations Map: Where are migrants coming from? Where have migrants left? </title>
<meta property="og:title" content="MigrationsMap.net"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="http://migrationsmap.net/"/>
<meta property="og:image" content="http://migrationsmap.net/facebook-image.png"/>
<meta property="og:site_name" content="MigrationsMap.net"/>
<meta property="fb:admins" content="548900828"/>
<meta property="og:description" content="Interactive Migrations Map: Where are migrants coming from? Where have migrants left?"/>
<meta itemprop="name" content="MigrationsMap.net">
<meta itemprop="description" content="Interactive Migrations Map: Where are migrants coming from? Where have migrants left?">
<meta itemprop="image" content="http://migrationsmap.net/facebook-image.png">
<link rel="stylesheet" type="text/css" href="univers-else-font/stylesheet.css" />
<script type="text/javascript" src="raphael.js"></script>
<link type="text/css" href="jquery-ui-1.8.16.custom/css/ui-darkness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<script type="text/javascript" src="jquery-ui-1.8.16.custom/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="signals.js"></script>
<script type="text/javascript" src="hasher.js"></script>
<script type="text/javascript" src="modernizr.geoloc.js"></script>
<link rel="stylesheet" type="text/css" href="main.css" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1397562-10']);
_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>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
</head>
<body>
<div id="container">
<div id="title">
<h1 style="color:white;">MigrationsMap.net</h1>
<p style="font-size:13px;padding: 2px 0px 0px 0px;">Where are migrants coming from? Where have migrants left?</p>
</div>
<div id="social">
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmigrationsmap.net&send=false&layout=button_count&width=100&show_faces=true&action=like&colorscheme=dark&font=arial&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:21px; padding-top:10px;" allowTransparency="true"></iframe>
<div id="plusone"><g:plusone size="medium"></g:plusone></div>
</div>
<div id="country_select_div">
<span id="explanation">Click on the map or pick a country here:</span>
<select id="country_select">
</select>
</div>
<div id="inorout">
<span id="in" class="on"><a href="#" class="blackLink">Arrivals</a></span> <span id="out"><a href="#" class="blackLink">Departures</a></span>
</div>
<div id="canvas_container">
<script type="text/javascript">
var ten_colors = ["#67000D" , "#A50F15","#CB181D", "#EF3B2C", "#FB6A4A","#FC9272","#FCBBA1", "#FEE0D2", "#FFF5F0","#FFFFFF"];
var svg_borders;
var current_arrows=[];
var current_countries=[];
var currentCircles=[];
var currentCountry="USA";
var previousCountry = "USA";
var direction = "out";
var unselected_color = "#515151";
var selected_color = "#999";//"#67E667" ;//"#87ceeb";
var border_color = "#999";
var arrow_color = "#009CFF"//"#add8e6"; //"#fafad2";
var code_to_name ;
var name_to_code;
var code_to_coordinates;
var userLatitude;
var userLongitude;
var GDP ={};
var HIV = {};
var POP = {};
var TUBERCULOSIS = {};
var UNDER_FIVE_MORTALITY = {};
var container ;
function parseHash(hash, redrawing){
res = the_regexp.exec(hash);
if (res)
{
currentCountry = res[1];
if (res[2]=='arrivals')
direction = 'out';
else
direction = 'in';
}
if (redrawing)
redraw();
}
function setHashSilently(hash){
hasher.changed.active = false; //disable changed signal
hasher.setHash(hash); //set hash without dispatching changed signal
hasher.changed.active = true; //re-enable signal
}
function lolatoxy(point){
var lo = point.longitude;
var la = point.latitude;
//lo = -122.18994140625; // SF
//la = 37.33522435930639;
//lo = 23.5546875; //south of south-africa
//la = -37.33522435930639;
var x = (lo+180) * (1200 / 360.0);
var y = (180 - (la+90)) * (700.0 / 180.0);
return {"x":Math.floor(x),
"y":Math.floor(y)
};
}
function flashCircles()
{
var c = paper.circle(userLongitude,userLatitude , 1);
c.attr({"stroke":"white"});
c.animate({r: 30,stroke:"yellow"}, 333, function(){
var d = paper.circle(userLongitude,userLatitude , 1);
c.animate({r: 60,stroke:"white"}, 333);
d.attr({"stroke":"white"});
d.animate({r: 30,stroke:"yellow"},333, function(){
var e = paper.circle(userLongitude,userLatitude , 1);
e.attr({"stroke":"white"});
e.animate({r: 30,stroke:"yellow"}, 333);
c.animate({r: 90,stroke:"yellow"}, 333);
d.animate({r: 60,stroke:"white"},333, function(){
c.remove();
d.remove();
e.remove();
});
});
});
}
function redraw()
{
var other_direction = "in";
var hash_direction = "arrivals"
if (direction =="in")
{
other_direction = "out";
hash_direction = "departures";
}
setHashSilently(currentCountry+"/"+hash_direction);
removeCurrentDrawings();
$("#country_select").val(currentCountry);
draw_arrows_and_paint_countries();
$("#"+direction).removeClass("on");
$("#"+other_direction).addClass("on")
}
function color_country(country,color,strokeColor)
{
var i;
var l;
if (svg_borders.hasOwnProperty(country))
for (i=0, l= svg_borders[country].length;i<l;i++)
{
if (strokeColor)
svg_borders[country][i].animate({"fill":color,"stroke":strokeColor,"stroke-width":2},333);
else
svg_borders[country][i].animate({"fill":color,"stroke":border_color,"stroke-width":1},333);
}
}
function removeCurrentDrawings()
{
color_country(previousCountry,unselected_color);
var i;
var l;
for (i=0,l=current_arrows.length;i<l;i++)
current_arrows[i].remove();
for (i=0,l=currentCircles.length;i<l;i++)
currentCircles[i].remove();
current_arrows=[];
for(i=0,l=current_countries.length;i<l;i++)
color_country(current_countries[i],unselected_color);
current_countries=[]
}
function get_click_handler(country){
return function(){
previousCountry = currentCountry;
currentCountry = country;
redraw();
}
}
function get_over_handler(country){
return function(event){
color_country(country,selected_color);
var country_name = $("#country_name_popup");
country_name.empty();
country_name.append("<span id='popup_country_name'> "+code_to_name[country] + "</span><table width='100%'>");
var pop = insertDecimalPoints(parseFloat(POP[country]).toFixed(0));
if (!pop)
pop = "no data";
country_name.append("<tr><th>Population</th><td style='text-align:right;'>" + pop+'</td></tr>');
var gdp = insertDecimalPoints(parseFloat(GDP[country]).toFixed(0)) ;
if (gdp)
gdp = '$ '+gdp;
else
gdp ="no data";
country_name.append("<tr><th>GDP per capita</th><td style='text-align:right;'>" + gdp+'</td></tr>');
var hiv = HIV[country];
if (hiv)
hiv = hiv + ' %';
else
hiv = "no data"
country_name.append("<tr><th>HIV Prevalence (age 15-49)</th><td style='text-align:right;'>" + hiv+'</td></tr>');
var tb = parseFloat(TUBERCULOSIS[country]/1000).toFixed(2);
if (tb)
tb = tb + ' %';
else
tb = "no data";
country_name.append("<tr><th>Tuberculosis Prevalence</th><td style='text-align:right;'>" + tb +'</td></tr>');
var mortality = parseFloat(UNDER_FIVE_MORTALITY[country]/10).toFixed(2);
if (mortality)
mortality = mortality + ' %';
else
mortality = "no data";
country_name.append("<tr><th>Mortality under Five</th><td style='text-align:right;'>" +mortality+'</td></tr></table>' );
country_name.css("display","block");
var canvasContainer = $("#canvas_container");
var canvasTop = canvasContainer.offset().top;
var canvasLeft = canvasContainer.offset().left;
if (event.pageY<canvasTop+500)
country_name.css("top",event.pageY);
else
country_name.css("top",event.pageY-170);
country_name.css("left",Math.min(event.pageX,canvasLeft+1200-290));
}
}
function insertDecimalPoints(s)
{
var l = s.length;
var res = ""+s[0];
for (var i=1;i<l-1;i++)
{
if ((l-i)%3==0)
res+= ".";
res+=s[i];
}
res+=s[l-1];
return res;
}
function get_out_handler(country){
return function(event){
var found=false;
var i;
var l;
var country_name = $("#country_name_popup");
country_name.css("display","none");
for (i=0,l=current_countries.length;i<l;i++)
{
if (country === current_countries[i])
{
found=true;
break;
}
}
if (country==currentCountry)
color_country(country,selected_color,'yellow');
else if (found)
color_country(country,ten_colors[i])
else
color_country(country,unselected_color);
}
}
function draw_arrows_and_paint_countries()
{
$.getJSON("generated/"+direction+currentCountry+".json", function(data) {
var countries_div = $("#countries");
var country_name_div = $("#country_name");
countries_div.empty();
country_name_div.empty()
country_name_div.append(code_to_name[currentCountry]);
$("#popsize").empty();
var popsize = insertDecimalPoints(parseFloat(POP[currentCountry]).toFixed(0));
popsize = "Pop: "+popsize;
if (popsize)
$("#popsize").append(popsize);
var counter =0;
$.each(data, function(country, val) {
var line;
var i;
var l;
var path;
line = paper.path(val[0]);
countries_div.append("<tr><td><div class=color_span style='height:1em;width:1em;background-color:"+ten_colors[counter] +" '> </div></td><td class='country_name' value='"+name_to_code[val[1]] +"'>"+val[1]+'</td><td style="text-align: right;">'+insertDecimalPoints(val[2])+"</td></tr>")
line.attr({stroke:arrow_color,'stroke-width':2,'opacity':0});
line.animate({stroke:arrow_color,'stroke-width':2,'opacity':1},333);
current_arrows.push(line);
color_country(country,ten_colors[counter]);
current_countries.push(country);
var coo = code_to_coordinates[country];
var circle = paper.circle(coo[0], coo[1], 2);
circle.attr("stroke", arrow_color);
circle.attr("fill", arrow_color);
currentCircles.push(circle);
coo = code_to_coordinates[currentCountry];
circle = paper.circle(coo[0], coo[1], 2);
circle.attr("stroke", "yellow");
circle.attr("fill", "yellow");
currentCircles.push(circle);
counter++;
});
color_country(currentCountry,selected_color,'yellow');
});
}
var paper = new Raphael(document.getElementById('canvas_container'), 1200, 600);
$.getJSON('world_svg_paths_by_code.json', function(data) {
svg_borders = {};
$.each(data, function(country, val) {
svg_borders[country]=[]
var line;
var i;
var path;
for (var i=0, l=val.length;i<l;i++)
{
line = paper.path(val[i]);
line.attr({stroke:border_color,'stroke-width':1,'fill':unselected_color});
line.country=country;
$(line.node).click( get_click_handler(country));
$(line.node).mousemove( get_over_handler(country));
$(line.node).mouseout( get_out_handler(country));
svg_borders[country].push(line);
}
});
$.getJSON("name_to_code.json", function(data) {
name_to_code = data;
});
$.getJSON("GDP.json", function(data) {
GDP = data;
});
$.getJSON("HIV.json", function(data) {
HIV = data;
});
$.getJSON("TUBERCULOSIS.json", function(data) {
TUBERCULOSIS = data;
});
$.getJSON("UNDER-FIVE-MORTALITY.json", function(data) {
UNDER_FIVE_MORTALITY = data;
});
$.getJSON("POP.json", function(data) {
POP = data;
});
$.getJSON("code_to_name.json", function(data) {
code_to_name = data;
var country_select = $("#country_select");
$.each(data, function(code, name) {
var selected='';
if (code=="BEL")
selected='selected="selected"';
country_select.append("<option value='"+code+"'" +selected+">"+name+'</option>');
});
country_select.change(function(e){
previousCountry = currentCountry;
currentCountry = $(this).val();
redraw();
});
//draw_arrows_and_paint_countries();
});
$.getJSON("code_to_coordinates.json", function(data) {
code_to_coordinates = data;
redraw();
});
});
$(function(){
if (!Modernizr.geolocation)
$("#geoloc_me").hide();
container = $("#container");
$("#in").click(function(e){
e.preventDefault();
direction='out';
redraw();
});
$("#out").click(function(e){
e.preventDefault();
direction='in';
redraw();
});
$("#geoloc_me").click(function(e){
navigator.geolocation.getCurrentPosition(function(data){
var userCoordinates = lolatoxy(data.coords);
userLatitude = userCoordinates.y;
userLongitude = userCoordinates.x;
flashCircles();
});
});
$('#geoloc_me').hover(
function() { $(this).addClass('ui-state-hover'); },
function() { $(this).removeClass('ui-state-hover'); }
);
$('#legend').draggable();
$("#legend").delegate(".country_name","click",function(e){
previousCountry = currentCountry;
currentCountry = $(this).attr("value");
redraw();
});
$("#legend").delegate(".country_name","mouseenter",function(e){
$(this).css("text-decoration","underline");
});
$("#legend").delegate(".country_name","mouseleave",function(e){
$(this).css("text-decoration","none");
});
var progressBar = $("#progressbar");
if (window.applicationCache){
var fileCounter=0;
window.applicationCache.onprogress = function(event){
fileCounter++;
progressBar.progressbar({
value: fileCounter/4.84
});
$("#progressbarMessage").html((fileCounter/4.84).toFixed(0) + " % downloaded");
}
window.applicationCache.oncached = function(event){
$("#progressbarMessage").html("Offline cache ready. You can now access the site without internet connection.")
};
window.applicationCache.onnoupdate = function(event){
progressBar.progressbar({
value: 100
});
$("#progressbarMessage").html("Cache up-to-date. You can access the site without internet connection.")
}
window.applicationCache.onupdateready = function(event){
progressBar.progressbar({
value: 100
});
window.applicationCache.swapCache();
//$("#progressbarMessage").html("Cache up-to-date. A new version of the site is now available offline.")
}
window.applicationCache.onerror = function(event){
progressBar.progressbar({
value: 100
});
$("#social").hide();
$("#progressbarMessage").html("You're currently using the site offline.")
}
}
});
var the_regexp = /^([^\/\?]+)\/?(\w*)$/i;
hasher.initialized.add(parseHash);
hasher.changed.add(parseHash, true);
hasher.init(); //start listening for history change
</script>
</div>
<div id="legend">
<h2 id="country_name">
</h2>
<h3 id="popsize">
</h3>
<table id="countries" width="100%">
</table>
</div>
<div id="country_name_popup">
</div>
<div id="html5badge">
<a href="http://www.w3.org/html/logo/">
<img src="http://www.w3.org/html/logo/badge/html5-badge-h-css3-device-graphics-semantics-storage.png" width="261" height="64" alt="HTML5 Powered with CSS3 / Styling, Device Access, Graphics, 3D & Effects, Semantics, and Offline & Storage" title="HTML5 Powered with CSS3 / Styling, Device Access, Graphics, 3D & Effects, Semantics, and Offline & Storage">
</a>
</div>
<div id="credits">
Visualization by <a href="http://twitter.com/madewulf">@madewulf</a> based on <a href="http://www.migrationdrc.org/research/typesofmigration/global_migrant_origin_database.html">the Global Migrant Origin Database</a> Version 4 (updated March 2007) - <a href="about.html">Learn more</a> - <a href="https://github.com/madewulf/MigrationsMap.net">Code on github</a>
</div>
<div id="geoloc_me" class="ui-state-default ui-corner-all">
<span title="Where am I?" class="ui-icon ui-icon-home"></span>
</div>
<div id="progressbar"></div>
<div id="progressbarMessage"></div>
</div>
</body>
</html>