index.html
<!DOCTYPE html>
<html>
<head>
<title>Czech elections 2013: new government vs. opposition</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;
}
</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="#">Czech elections 2013: new government vs. opposition</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 and the <strong>oppacity</strong> the margin of victory. Possible <span style="color:#00b">government</span> vs. <span style="color:#b00">opposition</span></div>
</div>
<div id="map" style="margin-top:40px;"></div>
<script type="text/javascript">
var map = L.map('map',{zoomControl: false}).setView([50,15], 8);
map.addControl( L.control.zoom({position: 'topright'}) );
L.tileLayer('//{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON( "cz_psp_2013_ring_cssd-ano-kdu-csl_kscm-top-09-ods-usvit.json", function (data) {
$.each(data.features, function (index, value) {
circle = L.circle([value.coordinates[1], value.coordinates[0]], Math.sqrt((parseInt(value.population.p6)+parseInt(value.population.p9))*2750), {
color: class2color(value.classname),
fillColor: class2color(value.classname),
fillOpacity: 2*(Math.max(parseInt(value.population.p6),parseInt(value.population.p9)) / (parseInt(value.population.p6)+parseInt(value.population.p9))-0.5),
weight: 0.1,
className: value.classname,
}).addTo(map);
perc1 = Math.round(Math.max(parseInt(value.population.p6),parseInt(value.population.p9)) / (parseInt(value.population.p6)+parseInt(value.population.p9)) * 100);
perc2 = 100 - perc1;
circle.bindPopup(value.name + "<br>" + value.winner + " vyhrály " + perc1 + " % vs. " + perc2 + " % <br>(" +Math.max(value.population.p6,value.population.p9) + " : " + Math.min(value.population.p6,value.population.p9) + " hlasov)");
});
});
function class2color(className) {
if (className == 'cssd-ano-kdu-csl') return "#00b";
if (className == 'kscm-top-09-ods-usvit') return "#b00";
else return "#fff";
}
</script>
</body>
</html>