--- layout: api title: "v1.6.1 API: L.mapbox.legendControl(options)" categories: api version: v1.6.1 permalink: /api/v1.6.1/l-mapbox-legendcontrol ---

## L.mapbox.legendControl(options)

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.

Example:

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

Returns: a `L.mapbox.legendControl` object.

### legendControl.addLegend(legend)

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.

### legendControl.removeLegend(legend)

Removes a legend from the legendControl.

Options | Value | Description
--- | --- | ---
legend required | string | legend data to remove.