Control.Zoom

A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by default unless you set its zoomControl option to false. Extends Control.

Creation

Factory Description
L.control.zoom(<Control.Zoom options> options) Creates a zoom control

Options

Option Type Default Descripion
zoomInText String '+' The text set on the 'zoom in' button.
zoomInTitle String 'Zoom in' The title set on the 'zoom in' button.
zoomOutText String '−' The text set on the 'zoom out' button.
zoomOutTitle String 'Zoom out' The title set on the 'zoom out' button.

Methods

Method Returns Descripion
getPosition() string Returns the position of the control.
setPosition( position) this Sets the position of the control.
getContainer() HTMLElement Returns the HTMLElement that contains the control.
addTo(<Map> map) this Adds the control to the given map.
remove() this Removes the control from the map it is currently active on.

Control.Attribution

The attribution control allows you to display attribution data in a small text box on a map. It is put on the map by default unless you set its attributionControl option to false, and it fetches attribution texts from layers with the getAttribution method automatically. Extends Control.

Creation

Factory Description
L.control.attribution(<Control.Attribution options> options) Creates an attribution control.

Options

Option Type Default Descripion
prefix String 'Leaflet' The HTML text shown before the attributions. Pass false to disable.

Methods

Method Returns Descripion
setPrefix(<string> prefix) this Sets the text before the attributions.
addAttribution(<string> text) this Adds an attribution text (e.g. 'Vector data © Mapbox').
removeAttribution(<string> text) this Removes an attribution text.

Control.Layers

The layers control gives users the ability to switch between different base layers and switch overlays on/off (check out the detailed example). Extends Control.

Creation

Factory Description
L.control.layers(
<Object> baselayers?,
<Object> overlays?,
<Control.Layers options> options?
)
Creates an attribution control with the given layers. Base layers will be switched with radio buttons, while overlays will be switched with checkboxes. Note that all base layers should be passed in the base layers object, but only one should be added to the map during map instantiation.

Options

Option Type Default Descripion
collapsed Boolean true If true, the control will be collapsed into an icon and expanded on mouse hover or touch.
autoZIndex Boolean true If true, the control will assign zIndexes in increasing order to all of its layers so that the order is preserved when switching them on/off.
hideSingleBase Boolean false If true, the base layers in the control will be hidden when there is only one.
sortLayers Boolean false Whether to sort the layers. When false, layers will keep the order in which they were added to the control.
sortFunction Function * A compare function that will be used for sorting the layers, when sortLayers is true. The function receives both the L.Layer instances and their names, as in sortFunction(layerA, layerB, nameA, nameB). By default, it sorts layers alphabetically by their name.

Methods

Method Returns Descripion
addBaseLayer(<Layer options> layer, <String options> name) this Adds a base layer (radio button entry) with the given name to the control.
addOverlay(<Layer options> layer, <String options> name) this Adds an overlay (checkbox entry) with the given name to the control.
removeLayer(<Layer options> layer) this Remove the given layer from the control.
expand() this Expand the control container if collapsed.
collapse() this Collapse the control container if expanded.

Control.Scale

A simple scale control that shows the scale of the current center of screen in metric (m/km) and imperial (mi/ft) systems. Extends Control.

Creation

Factory Description
L.control.scale(<Control.Scale options> options?) Creates an scale control with the given options.

Options

Option Type Default Descripion
maxWidth Number 100 Maximum width of the control in pixels. The width is set dynamically to show round values (e.g. 100, 200, 500).
metric Boolean true Whether to show the metric scale line (m/km).
imperial Boolean true Whether to show the imperial scale line (mi/ft).
updateWhenIdle Boolean false If true, the control is updated on moveend, otherwise it's always up-to-date (updated on move).