2

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>
  • Open up your browser's developer tools (F12 on most browsers) and look at the console output. Are there any errors showing up? – nathansnider Feb 16 '16 at 6:13
  • thanks for the tip. says there's Uncaught SyntaxError: missing ) after argument list on the L.tileLayer line, but the Leaflet tutorial code shows no ) – kakess Feb 16 '16 at 16:36
  • I don't see anything wrong with your parentheses, but you are still missing a comma after your attribution line. – nathansnider Feb 16 '16 at 18:21
5

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.

  • fixed, but still another error – kakess Feb 16 '16 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.