Using CoffeeScript to make a map

Mapbox.js is just as easy to use from the CoffeeScript language.

<!DOCTYPE html>
<meta charset=utf-8 />
<title>Using CoffeeScript to make a map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src=''></script>
<link href='' rel='stylesheet' />
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
<div id='map'></div>

<script src='//'></script>
<script type='text/coffeescript'>
L.mapbox.accessToken = '<your access token here>'
# Mapbox.js can easily be used in CoffeeScript, and use
# all fancy CoffeeScript functionality
map = 'map'
geocoder = L.mapbox.geocoder 'mapbox.places'

# for instance, in CoffeeScript we dont need to use
# parenthesis for functions or semicolons at the end of lines
map.setView [40, -74.50], 3
map.addLayer L.mapbox.styleLayer 'mapbox://styles/mapbox/streets-v11'

# defining a function that uses the geocoder to put a marker
# on a place, defined by its name
add = (placename) ->
  geocoder.query placename, (error, result) ->

add place for place in ['Washington, DC', 'San Francisco', 'Detroit, MI']
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