index.html
<!DOCTYPE html>
<html>
<head>
<title>European election 2014 in Czechia and Slovakia</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
L_PREFER_CANVAS = true;
</script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.leaflet-tile-pane {
opacity: .3
}
.leaflet-container {
background-color: #fff;
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">European election 2014 in Czechia and Slovakia</a>
</div>
</div>
</div>
<div style="position:fixed;top:50px;z-index:1000;">
<div class="alert alert-info" >The <strong>size</strong> of bubbles represents number of voters, the <strong>color</strong> represents the winner.</div>
</div> <div style="position:fixed;top:125px;z-index:1000;">
<div class="alert alert-info" style="float:left;">
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#009ee0"></svg> ANO<br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#808"></svg> TOP 09<br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#f54200"></svg> ČSSD<br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#ff0000"></svg> KSČM<br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#fedc35"></svg> KDU-ČSL <br/></br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#f00"></svg> SMER<br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#00558F"></svg> KDH<br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#008"></svg> SDKÚ-DS<br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#67d45d"></svg> OĽaNO<br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#002456"></svg> Nova<br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#619d00"></svg> SaS<br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#004e00"></svg> SMK-MKP<br/>
<svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#ff7f0e"></svg> Most-Híd
</div>
</div>
<div id="map" style="margin-top:40px;"></div>
<script type="text/javascript">
var map = L.map('map',{zoomControl: false}).setView([49.193816,16.60608], 7);
map.addControl( L.control.zoom({position: 'topright'}) );
L.tileLayer('//{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
attribution: 'CC-BY Michal Škop <a href="//kohovolit.eu">KohoVolit.eu</a> | © <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON( "epsk_2014.json", function (data) {
$.each(data.votes, function (index, value) {
description = "<strong>" + value.town + "</strong> (" + value.population + ")<br>";
tuples = [];
for (var key in value.votes) {
tuples.push([key,parseInt(value.votes[key])]);
}
tuples.sort(function(a, b) {
a = a[1];
b = b[1];
return a < b ? 1 : (a > b ? -1 : 0);
});
for (i = 0; i < 9; i++) {
tmp = Math.round(parseInt(tuples[i][1]) / parseInt(value.population) * 100);
description += data.people[tuples[i][0]] + ": " + tmp +"%<br>";
}
circle = L.circle([value.lat, value.lng], Math.sqrt(parseInt(value.population)*2000), {
color: data.colors[value.winner_class],
fillColor: data.colors[value.winner_class],
fillOpacity: 0.85,
weight: 1,
}).addTo(map);
circle.bindPopup(description);
});
});
$.getJSON( "epcz_2014.json", function (data) {
$.each(data.votes, function (index, value) {
description = "<strong>" + value.town + "</strong> (" + value.population + ")<br>";
tuples = [];
for (var key in value.votes) {
tuples.push([key,parseInt(value.votes[key])]);
}
tuples.sort(function(a, b) {
a = a[1];
b = b[1];
return a < b ? 1 : (a > b ? -1 : 0);
});
for (i = 0; i < 9; i++) {
tmp = Math.round(parseInt(tuples[i][1]) / parseInt(value.population) * 100);
description += data.people[tuples[i][0]] + ": " + tmp +"%<br>";
}
circle = L.circle([value.lat, value.lng], Math.sqrt(parseInt(value.population)*2000), {
color: data.colors[value.winner_class],
fillColor: data.colors[value.winner_class],
fillOpacity: 0.85,
weight: 1,
}).addTo(map);
circle.bindPopup(description);
});
});
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-8592359-13', 'ocks.org');
ga('send', 'pageview');
</script>
</body>
</html>