Viewing an older version of MapBox.js. Check out v1.5.0 for the latest.

Toggling UI Controls

Select all
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Toggling UI Controls</title>
  
  <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%; }
  </style>
</head>
<body>
<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;
        border-top-color:#FFF;
        color:#FFF;
        }
        #map-ui li:first-child a.active {
          border-top-color:#3887BE;
          }
        #map .map-fullscreen {
          background-color:#28353D;
          }

</style>
<div id='map'>
    <div id='map-ui'>
      <ul>
        <li><a href='#' id='zoomer'>Zoomer</a></li>
        <li><a href='#' id='zoombox'>Zoombox</a></li>
        <li><a href='#' id='fullscreen'>Fullscreen</a></li>
        <li><a href='#' id='attribution'>Attribution</a></li>
        <li><a href='#' id='pointselector'>Pointselector</a></li>
        <li><a href='#' id='hash'>Hash</a></li>
      </ul>
    </div>
</div>


<script>
  // Create map with layer and zoom to level 3
  var map = mapbox.map('map', mapbox.layer().id('examples.map-9ijuk24y')).zoom(3);
  map.ui.attribution.add()
      .content('<a href="http://mapbox.com/about/maps">Terms &amp; Feedback</a>');

  // Connect check boxes to ui functions
  var options = document.getElementsByTagName('a');
  for (var i = 0; i < options.length; i++) {
      options[i].onclick = function() {
          map.ui.refresh();
          if (this.className === 'active') {
            map.ui[this.id].remove();
            this.className = '';
          } else {
            map.ui[this.id].add();
            this.className = 'active';
          }
          return false;
      }
  }
</script>
The code and documentation to mapbox.js is hosted on GitHub where you can contribute changes and improvements.