index.html
<!DOCTYPE html>
<html>
<head>
<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="//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;
}
.schwarzenberg {
stroke: #f0f;
color: #f0f;
fill: #f0f;
}
.zeman {
stroke: #f00;
color: #f00;
fill: #f00;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
var map = L.map('map').setView([50, 15], 8);
L.tileLayer('//{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON( "cz_president_2013_both_2_ring.json", function (data) {
$.each(data.features, function (index, value) {
circle = L.circle([value.coordinates[1], value.coordinates[0]], Math.sqrt((value.population.p6+value.population.p9)*1000), {
color: class2color(value.classname),
fillColor: class2color(value.classname),
fillOpacity: 2*(Math.max(value.population.p6,value.population.p9) / (value.population.p6+value.population.p9) - 0.45),
weight: 0.1,
className: value.classname,
}).addTo(map);
perc1 = Math.round(Math.max(value.population.p6,value.population.p9) / (value.population.p6+value.population.p9) * 100);
perc2 = 100 - perc1;
circle.bindPopup(value.name + "<br/>" + value.winner + " vyhrál " + perc1 + " % vs. " + perc2 + " % <br/>(" +Math.max(value.population.p6,value.population.p9) + " : " + Math.min(value.population.p6,value.population.p9) + ")");
});
});
function class2color(className) {
if (className == 'zeman') return "#f00";
else return "#f0f";
}
</script>
</body>
</html>