Skip to content

Instantly share code, notes, and snippets.

@geografa
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geografa/9075516 to your computer and use it in GitHub Desktop.
Save geografa/9075516 to your computer and use it in GitHub Desktop.
Marker Filter by Color
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title></title>
<script src='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.js'></script>
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/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 onload="myFunction()">
<style>
#map-ui {
position: absolute;
top: 10px;
right: 10px;
z-index: 100;
}
#map-ui ul {
list-style: none;
margin: 0;
padding: 0;
}
#map-ui a {
font-size: 13px;
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;
color: #FFF;
}
</style>
<div id='map-ui'>
<ul>
<li><a href='#' id='filter-red'>show only red events</a></li>
<li><a href='#' class='active' id='filter-all'>show all events</a></li>
</ul>
</div>
<div id='map'></div>
<script type='text/javascript'>
var map = L.mapbox.map('map','grafa.hack22fp');
var red = document.getElementById('filter-red');
var all = document.getElementById('filter-all');
red.onclick = function(e) {
all.className = '';
this.className = 'active';
// The setFilter function takes a GeoJSON feature object
// and returns true to show it or false to hide it.
map.markerLayer.setFilter(function(f) {
return f.properties['marker-color'] === '#f86767';
});
return false;
};
all.onclick = function() {
red.className = '';
this.className = 'active';
map.markerLayer.setFilter(function(f) {
// Returning true for all markers shows everything.
return true;
});
return false;
};
function myFunction() {
map.markerLayer.setFilter(function() {
return false;
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment