The Mapbox.js documentation is organized by methods.
Each method is shown with potential arguments in a table.
Objects returned by constructors are documented by just their object type.
For instance, L.mapbox.markerLayer
documents a function that
returns a layer for markers. The methods on that object are then documented as
markerLayer.setFilter
, markerLayer.getGeoJSON
, and so on.
To use this API, you'll need to understand basic Javascript and mapping concepts. If you'd like to learn Javascript, start with an interactive course or book. To learn more about maps, we've provided a helpful article explaining how web maps work.
Mapbox.js is asynchronous - when you create a layer like L.mapbox.tileLayer('{{site.defaultid}}')
, the layer doesn't immediately know which tiles to load and its attribution information. Instead, it loads the information in an AJAX call.
For most things you'll write, this isn't a problem, since Mapbox.js does a good
job of handling these on-the-fly updates. If you're writing code that needs
to know when layers and other dynamically-loaded objects are ready, you can
use the ready
event to listen for their ready state. For instance:
Similarly, dynamically-loaded objects produce an `error` event if something goes wrong:
{% highlight javascript %} var layer = L.mapbox.tileLayer('{{site.defaultid}}'); layer.on('error', function(err) { // Handle error }); {% endhighlight %}