Mapbox.js layer switcher using map.setLayer
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> | |
<script src='http://code.jquery.com/jquery-1.8.3.min.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%; } | |
#switch { position:absolute; top:0; bottom:0; left: 300px width:300px; } | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<div id='switch'> | |
<button data-layer='0'>a</button> | |
<button data-layer='1'>b</button> | |
<button data-layer='2'>c</button> | |
</div> | |
<script> | |
mapbox.load(['landplanner.map-a0wbwf43', 'landplanner.blackmarble2', 'landplanner.enstrat_dni_101111b'], function(o) { | |
var map = mapbox.map('map').zoom(3).center({lat: 40, lon: -90}); | |
map.addLayer(o[0].layer); | |
$('button').click(function() { | |
map.setLayerAt(0, o[$(this).data('layer')].layer); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment