Skip to content

Map

The central class of the API — it is used to create a map on a page and manipulate it.

Usage example

js
const map = new Map('map', {
center: [51.505, -0.09],
zoom: 13
});

Map State Options

OptionTypeDefaultDescription
crsCRSCRS.EPSG3857The Coordinate Reference System to use. Don't change this if you're not
centerLatLngundefinedInitial geographic center of the map
zoomNumberundefinedInitial map zoom level
minZoomNumber*Minimum zoom level of the map.
maxZoomNumber*Maximum zoom level of the map.
layersLayerArray of layers that will be added to the map initially
maxBoundsLatLngBoundsnullWhen this option is set, the map restricts the view to the given
rendererRenderer*The default method for drawing vector layers on the map. SVG

Animation Options

OptionTypeDefaultDescription
zoomAnimationBooleantrueWhether the map zoom animation is enabled. By default it's enabled
zoomAnimationThresholdNumber4Won't animate zoom if the zoom difference exceeds this value.
fadeAnimationBooleantrueWhether the tile fade animation is enabled. By default it's enabled
markerZoomAnimationBooleantrueWhether markers animate their zoom with the zoom animation, if disabled
transform3DLimitNumber2^23Defines the maximum size of a CSS translation transform. The default

Interaction Options

OptionTypeDefaultDescription
zoomSnapNumber1Forces the map's zoom level to always be a multiple of this, particularly
zoomDeltaNumber1Controls how much the map's zoom level will change after a
trackResizeBooleantrueWhether the map automatically handles browser window resize to update itself.

Events

EventDataDescription
resizeFired when the map is resized.
locationerrorFired when geolocation (using the locate method) failed.
locationfoundFired when geolocation (using the locate method)
unloadFired when the map is destroyed with remove method.
viewresetFired when the map needs to redraw its content (this usually happens
loadFired when the map is initialized (when its center and zoom are set
zoomstartFired when the map zoom is about to change (e.g. before zoom animation).
movestartFired when the view of the map starts changing (e.g. user starts dragging the map).
zoomFired repeatedly during any change in zoom level,
moveFired repeatedly during any movement of the map,
zoomendFired when the map zoom changed, after any animations.
moveendFired when the center of the map stops changing
clickFired when the user clicks (or taps) the map.
dblclickFired when the user double-clicks (or double-taps) the map.
pointerdownFired when the user pushes the pointer on the map.
pointerupFired when the user releases the pointer on the map.
pointeroverFired when the pointer enters the map.
pointeroutFired when the pointer leaves the map.
pointermoveFired while the pointer moves over the map.
contextmenuFired when the user pushes the right mouse button on the map, prevents
keypressFired when the user presses a key from the keyboard that produces a character value while the map is focused.
keydownFired when the user presses a key from the keyboard while the map is focused. Unlike the keypress event,
keyupFired when the user releases a key from the keyboard while the map is focused.
preclickFired before pointer click on the map (sometimes useful when you
zoomanimFired at least once per zoom animation. For continuous zoom, like pinch zooming, fired once per frame during zoom.