block by wboykinm 4331911

Mapbox.js layer switcher using map.setLayer

Full Screen

index.html

<!DOCTYPE html>
<html>
<head>
  <script src='//api.tiles.mapbox.com/mapbox.js/v0.6.7/mapbox.js'></script>
  <script src='//code.jquery.com/jquery-1.8.3.min.js'></script>
  <link href='//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>