Skip to content

Instantly share code, notes, and snippets.

@ajashton
Last active December 12, 2015 07:08
Show Gist options
  • Save ajashton/4734118 to your computer and use it in GitHub Desktop.
Save ajashton/4734118 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src='http://api.tiles.mapbox.com/mapbox.js/v0.6.7/mapbox.js'></script>
<link href='http://api.tiles.mapbox.com/mapbox.js/v0.6.7/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
#map-ui {
position:absolute;
top:10px;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'>
<li><a href='#' id='hiu.lsib-dark-labelled' class='active'>Boundaries (Labelled)</a></li>
<li><a href='#' id='hiu.lsib-dark'>Boundaries</a></li>
<li><a href='#' id='aj.1x1-degrees'>Geography Class (interactive)</a></li>
</ul>
<div id='map'></div>
<script>
var map = mapbox.map('map');
var layers = document.getElementById('map-ui').getElementsByTagName('a');
// add static baselayer
map.addLayer(mapbox.layer().id('aj.map-rdkqhq6e', function() {
map.interaction.auto();
}));
//map.interaction.auto();
for (var i = 0; i < layers.length; i++) {
layer = layers[i];
map.addLayer(mapbox.layer().id(layer.id, function() {
map.interaction.auto();
}));
if (layer.className != 'active') {
map.getLayer(layer.id).disable();
}
layer.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
// If the layer that has been clicked on is not already enabled,
// enable it and also disable any other active layers in the layerswitcher
if (!(map.getLayer(this.id).enabled)) {
for (var i = 0; i < layers.length; i++) {
if (map.getLayer(layers[i].id).enabled) {
map.getLayer(layers[i].id).disable();
layers[i].className = '';
}
}
map.getLayer(this.id).enable();
this.className = 'active';
map.interaction.refresh();
}
};
}
map.zoom(4);
// Attribute map
map.ui.attribution.add()
.content('<a href="http://mapbox.com/about/maps">Terms &amp; Feedback</a>');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment