List markers and pan to clicked items

Shows marker titles in an HTML list and pans to clicked markers when necessary. This example could be modified to support just panning, just opening tooltips, or a different HTML layout for marker contents.

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>List markers and pan to clicked items</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v3.0.1/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v3.0.1/mapbox.css' rel='stylesheet' />
<style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
  #marker-list {
      position:absolute;
      top:0; right:0; width:200px;
      bottom:0;
      overflow-x:auto;
      background:#fff;
      margin:0;
      padding:5px;
  }
  #marker-list li {
      padding:5px;
      margin:0;
      list-style-type:none;
  }
  #marker-list li:hover {
      background:#eee;
  }
</style>
<div id='map'></div>
<ul id='marker-list'></ul>
<script>
L.mapbox.accessToken = '<your access token here>';
  var map = L.mapbox.map('map', 'mapbox.dc-markers');
  var markerList = document.getElementById('marker-list');

  map.featureLayer.on('ready', function(e) {
      map.featureLayer.eachLayer(function(layer) {
          var item = markerList.appendChild(document.createElement('li'));
          item.innerHTML = layer.toGeoJSON().properties.title;
          item.onclick = function() {
             map.setView(layer.getLatLng(), 14);
             layer.openPopup();
          };
      });
  });
</script>
to create your own custom map and use it in this example.
Use this example by copying its source into your own HTML page and replacing the Map ID with one of your own from your projects. Having trouble with JavaScript? Try out Codecademy or contact our support team.
Copy example