Mapbox.js is no longer in active development. To learn more about our newer mapping tools see Mapbox GL JS.

You are viewing an older version of Mapbox.js. Check out v3.3.1 for the latest.


Extends: L.Control

A map control that shows legends added to maps in Mapbox. Legends are auto-detected from active layers.

Options Value Description
options optional object An options object. Beyond the default options for map controls, this object has one special parameter: sanitizer: A function that accepts a string, and returns a sanitized result for HTML display. The default will remove dangerous script content, and is recommended.


var map = L.mapbox.map('map').setView([38, -77], 5);

Returns: a L.mapbox.legendControl object.

Class: L.mapbox.LegendControl


Adds a legend to the legendControl.

Options Value Description
legend required string A string which may contain HTML. It will be sanitized by the legendControl's sanitizer option.


Removes a legend from the legendControl.

Options Value Description
legend required string legend data to remove.