block by michalskop 7741866

SK-BB Regional Elections '13: Chairman 2nd Round

Full Screen

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Regional elections 2013, Banská Bystrica, Chairman - 2nd round</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>
	  // see //leafletjs.com/reference.html
	  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" />
	 <!--[if lte IE 8]>
		 <link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" />
	 <![endif]-->
    <script src="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
    <!--<script type="text/javascript" src="//mbostock.github.com/d3/d3.js?1.29.1"></script>-->
    <style type="text/css">

		html, body, #map {
		  width: 100%;
		  height: 100%;
		  margin: 0;
		  padding: 0;
		}


		.marian-kotleba {
		  stroke: #040;
		  color: #080;
		  fill: #040;
		}
		.vladimir-manka {
		  stroke: #f00;
		  color: #f00;
		  fill: #f00;
		}


    </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="#">Regional elections 2013, Banská Bystrica, Chairman - 2nd round - <span class="marian-kotleba">Kotleba</span> vs. <span class="vladimir-manka">Maňka</span></a>
        </div>
      </div>
    </div>
    
    <div class="alert alert-info" style="position:fixed;top:50px;z-index:1000;">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.</div>
    <div id="map" style="margin-top:40px;"></div>
    <script type="text/javascript">


		// Create the map
		var map = L.map('map',{zoomControl: false}).setView([48.565703,19.390411], 9);
		map.addControl( L.control.zoom({position: 'topright'}) );
		
		// add an OpenStreetMap tile layer
		// also see //wiki.openstreetmap.org/wiki/Tiles
		//L.tileLayer('//{s}.tile.osm.org/{z}/{x}/{y}.png', {
		L.tileLayer('//{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
			attribution: '&copy; <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
		}).addTo(map);
		
		//add circles
		//$.getJSON( "cz_president_2013_both_2_ring.json", function (data) {
		$.getJSON( "sk_vuc_2013_2_ring_marian-kotleba_vladimir-manka.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.45),
					weight: 0.1,
					className: value.classname,	//this does not seem to work, so hacked by class2color
				}).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 + " vyhral " + 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 == 'marian-kotleba') return "#040";//"#f00";
		  else return "#f00";//"#f0f";
		}
	</script>
  </body>
</html>