Created
September 27, 2013 14:40
-
-
Save tmcw/6729642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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.3.1/mapbox.ie.css' rel='stylesheet'> | |
<![endif]--> | |
<style> | |
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
#allButton { position:absolute; right:20px; top: 20px; z-index:1; border:1px solid black; background-color:white; width:100px; height:20px; font-family:"Helvetica Neue",Arial,sans-serif; text-align:center; cursor:pointer;} | |
#shopButton { position:absolute; right:20px; top: 50px; z-index:1; border:1px solid black; background-color:white; width:100px; height:20px; font-family:"Helvetica Neue",Arial,sans-serif; text-align:center; cursor:pointer;} | |
</style> | |
</head> | |
<body> | |
<span id="allButton">All</span> | |
<span id="shopButton">Shop</span> | |
<div id='map'></div> | |
<script> | |
var map = L.mapbox.map('map', 'examples.map-zr0njcqy'); | |
map.markerLayer.on('ready', function(e) { | |
cycle(); | |
}); | |
function getMarkers() { | |
var markers = []; | |
map.markerLayer.eachLayer(function(marker) { markers.push(marker); }); | |
return markers; | |
} | |
var allButton = document.getElementById('allButton'); | |
var shopButton = document.getElementById('shopButton'); | |
shopButton.onclick = function(e) { | |
map.markerLayer.setFilter(function(f) { | |
return f.properties['marker-symbol'] === 'shop'; | |
}); | |
}; | |
allButton.onclick = function() { | |
map.markerLayer.setFilter(function(f) { | |
return true; | |
}); | |
}; | |
function cycle() { | |
var i = 0; | |
function run() { | |
var markers = getMarkers(); | |
if (++i > markers.length - 1) i = 0; | |
map.setView(markers[i].getLatLng(), 12); | |
markers[i].openPopup(); | |
window.setTimeout(run, 3000); | |
} | |
run(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment