L.mapbox.accessToken = 'pk.eyJ1Ijoia2F0eWRlY29yYWgiLCJhIjoiNWVLQUItVSJ9.lSvDxtmL6e-8WFG5uVtuiA'; // update your access token here var map = L.mapbox.map('map', 'examples.map-i80bb8p3') // update with your own map id .setView([38.909671288923, -77.034084142948], 16); var listings = document.getElementById('listings'); var locations = L.mapbox.featureLayer().addTo(map); locations.loadURL('https://s3-us-west-2.amazonaws.com/s.cdpn.io/6362/sweetgreen.geojson'); // load in your own GeoJSON file here function setActive(el) { var siblings = listings.getElementsByTagName('div'); for (var i = 0; i < siblings.length; i++) { siblings[i].className = siblings[i].className .replace(/active/, '').replace(/\s\s*$/, ''); } el.className += ' active'; } locations.on('ready', function() { locations.eachLayer(function(locale) { // Shorten locale.feature.properties to just `prop` so we're not // writing this long form over and over again. var prop = locale.feature.properties; // Each marker on the map. var popup = '

Sweetgreen

' + prop.address; var listing = listings.appendChild(document.createElement('div')); listing.className = 'item'; var link = listing.appendChild(document.createElement('a')); link.href = '#'; link.className = 'title'; link.innerHTML = prop.address; if (prop.crossStreet) { link.innerHTML += '
' + prop.crossStreet + ''; popup += '
' + prop.crossStreet + ''; } var details = listing.appendChild(document.createElement('div')); details.innerHTML = prop.city; if (prop.phone) { details.innerHTML += ' · ' + prop.phoneFormatted; } link.onclick = function() { setActive(listing); // When a menu item is clicked, animate the map to center // its associated locale and open its popup. map.setView(locale.getLatLng(), 16); locale.openPopup(); return false; }; // Marker interaction locale.on('click', function(e) { // 1. center the map on the selected marker. map.panTo(locale.getLatLng()); // 2. Set active the markers associated listing. setActive(listing); }); popup += '
'; locale.bindPopup(popup); }); }); locations.on('layeradd', function(e) { var marker = e.layer; marker.setIcon(L.icon({ iconUrl: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/6362/marker.png', // load your own custom marker image here iconSize: [56, 56], iconAnchor: [28, 28], popupAnchor: [0, -34] })); });