[GIS] Error with Leaflet Tutorial on adding Mapbox tile layer

leafletmapboxtiles

I'm trying to add a Mapbox Classic base layer from my account using Leaflet's tutorial. I can't figure out what's wrong with my code:

<div id='map' ></div>
<script>
    var map = L.map('map').setView([39.952451, -75.163459], 15);
    L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={token}', {
        attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>'
    maxZoom: 18,
    id: 'XXX',
    token: 'XXX'
    }).addTo(map);
</script>

Best Answer

You have a syntax error when declaring the object properties.

Do not do this:

var options = {
  maxZoom: 18,
  id = 'kirsten',
  token = 'abcdefghijklm'
}

Do this instead:

var options = {
  maxZoom: 18,
  id: 'kirsten',
  token: 'abcdefghijklm'
}

Note = vs :, and read the docs on object literals while you're at it.