Skip to content

Instantly share code, notes, and snippets.

@And-How
Last active December 25, 2015 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save And-How/6922184 to your computer and use it in GitHub Desktop.
Save And-How/6922184 to your computer and use it in GitHub Desktop.
Oakland Voting
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title></title>
<script src='http://api.tiles.mapbox.com/mapbox.js/v1.4.0/mapbox.uncompressed.js'></script>
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.4.0/mapbox.css' rel='stylesheet' />
<!--[if lte IE 8]>
<link href='//api.tiles.mapbox.com/mapbox.js/v1.4.0/mapbox.ie.css' rel='stylesheet'>
<![endif]-->
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
#map-ui {
position: absolute;
top: 75px;
left: 10px;
list-style: none;
margin: 0;
padding: 0;
z-index: 100;
}
#map-ui a {
font: normal 13px/18px 'Helvetica Neue', Helvetica, sans-serif;
background: #FFF;
color: #3C4E5A;
display: block;
margin: 0;
padding: 0;
border: 1px solid #BBB;
border-bottom-width: 0;
min-width: 138px;
padding: 10px;
text-decoration: none;
}
#map-ui a:hover {
background: #ECF5FA;
}
#map-ui li:last-child a {
border-bottom-width: 1px;
-webkit-border-radius: 0 0 3px 3px;
border-radius: 0 0 3px 3px;
}
#map-ui li:first-child a {
-webkit-border-radius: 3px 3px 0 0;
border-radius: 3px 3px 0 0;
}
#map-ui a.active {
background: #3887BE;
border-color: #3887BE;
border-top-color: #FFF;
color: #FFF;
}
</style>
<ul id='map-ui'></ul>
<div id='map'></div>
<script type='text/javascript'>
var map = L.mapbox.map('map').setView([37.7869, -122.2121], 12);
var ui = document.getElementById('map-ui');
var thelayer = null;
L.mapbox.tileLayer('ofurhe.map-0mdbiazn').addTo(map);
addLayer(L.mapbox.tileLayer('ofurhe.Council_Members'), 'Voter Turnout', 2);
addLayer(L.mapbox.tileLayer('ofurhe.MayoralCandidateVotes'), 'Mayoral Candidates', 3);
addLayer(L.mapbox.tileLayer('ofurhe.Votes_for_Quan'), 'Votes for Quan', 4);
addLayer(L.mapbox.tileLayer('ofurhe.CouncilMembers'), 'City Councilmembers', 5);
function addLayer(layer, name, zIndex) {
// Create a simple layer switcher that toggles layers on
// and off.
var item = document.createElement('li');
var link = document.createElement('a');
link.href = '#';
link.innerHTML = name;
if (thelayer == null) {
layer
.setZIndex(zIndex)
.addTo(map);
layer.on('ready', function() {
map.legendControl.addLegend(layer.getTileJSON().legend);
});
thelayer = layer;
link.className = 'active';
}
layer.link = link;
link.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
if (thelayer != layer) {
map.removeLayer(thelayer);
map.legendControl.removeLegend(thelayer.getTileJSON().legend);
thelayer.link.className = '';
map.addLayer(layer);
map.legendControl.addLegend(layer.getTileJSON().legend);
this.className = 'active';
thelayer = layer;
}
};
item.appendChild(link);
ui.appendChild(item);
}
</script>
</body>
</html>
-122.2218,37.8155,11
-123.0259,37.3884,-121.8477,38.3360
@And-How
Copy link
Author

And-How commented Oct 31, 2013

Thanks to @jfirebaugh for help with legends

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment