<style>
#filters {
position:absolute;
top:10px;left:10px;
z-index:100;
padding:5px;
background:#fff;
}
#filters ul {
list-style-type:none;
margin:0;
padding:0;
}
</style>
<div id='map-ui'>
<form id='filters'>
<ul id='options'>
<li><input type='checkbox' checked=checked class='filter'
name='filter' id='fast-food' value='fast-food' /><label for='fast-food'>fast-food</label></li>
<li><input type='checkbox' checked=checked class='filter'
name='filter' id='bicycle' value='bicycle' /><label for='bicycle'>bicycle</label></li>
<li><input type='checkbox' checked=checked class='filter'
name='filter' id='bar' value='bar' /><label for='bar'>bar</label></li>
</ul>
</form>
</div>
<div id='map'></div>
<script>
var map = mapbox.map('map');
map.addLayer(mapbox.layer().id('examples.map-zr0njcqy'));
var markersLayer = mapbox.markers.layer().id('examples.map-zr0njcqy', function() {
// This code is in the second callback to id because it depends
// on the features being loaded asynchronously. If it were put right
// after the call to .id(), the markers layer wouldn't contain any
// data - it would still be on its way from MapBox to the browser.
// Cinch the map display to show all markers
map.extent(markersLayer.extent());
var filters = document.getElementById('filters');
var checkboxes = document.getElementsByClassName('filter');
function change(e) {
// Find all checkboxes that are checked and build a list of their values
var on = [];
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) on.push(checkboxes[i].value);
}
// The filter function takes a GeoJSON feature object
// and returns true to show it or false to hide it.
markersLayer.filter(function(f) {
// check each marker's symbol to see if its value is in the list
// of symbols that should be on, stored in the 'on' array
return on.indexOf(f.properties['marker-symbol']) !== -1;
});
return false;
}
// When the form is touched, re-filter markers
filters.onchange = change;
// Initially filter the markers
change();
});
map.addLayer(markersLayer);
// Attribute map
map.ui.attribution.add()
.content('<a href="http://mapbox.com/about/maps">Terms & Feedback</a>');
</script>