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


Used to group several layers and handle them as one. If you add it to the map, any layers added or removed from the group will be added/removed on the map as well. Implements ILayer interface.

L.layerGroup([marker1, marker2])


Factory Description
L.LayerGroup( <ILayer[]> layers? ) Create a layer group, optionally given an initial set of layers.


Method Returns Description
addTo( <Map> map ) this Adds the group of layers to the map.
addLayer( <ILayer> layer ) this Adds a given layer to the group.
removeLayer( <ILayer> layer ) this Removes a given layer from the group.
removeLayer( <String> id ) this Removes a given layer of the given id from the group.
hasLayer( <ILayer> layer ) Boolean Returns true if the given layer is currently added to the group.
getLayer( <String> id ) ILayer Returns the layer with the given id.
getLayers() Array Returns an array of all the layers added to the group.
clearLayers() this Removes all the layers from the group.
eachLayer( <Function> fn, <Object> context? ) this Iterates over the layers of the group, optionally specifying context of the iterator function.
group.eachLayer(function (layer) {
toGeoJSON() Object Returns a GeoJSON representation of the layer group (GeoJSON FeatureCollection).