Created
February 4, 2013 20:01
-
-
Save yhahn/4709203 to your computer and use it in GitHub Desktop.
Enable/disable map handlers
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
<!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%; } | |
.buttons { | |
position:absolute; | |
background:#fff; | |
padding:10px; | |
top:0px; right:0px; z-index:1000; | |
} | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<div class='buttons'> | |
<a href='#' onclick='addHandlers(); return false;'>Enable</a> | |
<a href='#' onclick='removeHandlers(); return false;'>Disable</a> | |
</div> | |
<script> | |
var layer = mapbox.layer().id('tmcw.map-2f4ad161'); | |
// Create map with no handlers | |
// The 4th argument is a list of handlers (drag, mousewheel, doubleclick). | |
// Here we have it empty, to disable zooming and panning. | |
var map = mapbox.map('map', layer, null, []); | |
map.centerzoom({lat: 43.6, lon: -79.4 }, 10); | |
// Attribute map | |
map.ui.attribution.add().content('<a href="http://mapbox.com/about/maps">Terms & Feedback</a>'); | |
// Removes all handlers. | |
function removeHandlers() { | |
while (map.eventHandlers.length) map.eventHandlers.pop().remove(); | |
}; | |
// Adds all handlers. | |
function addHandlers() { | |
// Don't re-add handlers. | |
if (map.eventHandlers.length) return; | |
var handlers = [ | |
easey_handlers.TouchHandler, | |
easey_handlers.DragHandler, | |
easey_handlers.DoubleClickHandler, | |
easey_handlers.MouseWheelHandler | |
]; | |
while (handlers.length) { | |
var h = handlers.pop()(); | |
map.eventHandlers.push(h); | |
h.init(map); | |
} | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment