Skip to content

Popup

Used to open popups in certain places of the map. Use Map.openPopup to open popups while making sure that only one popup is open at one time (recommended for usability), or use Map.addLayer to open as many as you want.

Usage example

If you want to just bind a popup to marker click and then open it, it's really easy:

js
marker.bindPopup(popupContent).openPopup();

Path overlays like polylines also have a bindPopup method.

A popup can be also standalone:

js
const popup = new Popup()
.setLatLng(latlng)
.setContent('<p>Hello world!<br />This is a nice popup.</p>')
.openOn(map);

or

js
const popup = new Popup(latlng, {content: '<p>Hello world!<br />This is a nice popup.</p>'})
.openOn(map);

Options

OptionTypeDefaultDescription
paneString'popupPane'Map pane where the popup will be added.
offsetPointPoint(0,The offset of the popup position.
maxWidthNumber300Max width of the popup, in pixels.
minWidthNumber50Min width of the popup, in pixels.
maxHeightNumbernullIf set, creates a scrollable container of the given height
autoPanBooleantrueSet it to false if you don't want the map to do panning animation
autoPanPaddingTopLeftPointnullThe margin between the popup and the top left corner of the map
autoPanPaddingBottomRightPointnullThe margin between the popup and the bottom right corner of the map
autoPanPaddingPointPoint(5,Equivalent of setting both top left and bottom right autopan padding to the same value.
keepInViewBooleanfalseSet it to true if you want to prevent users from panning the popup
closeButtonBooleantrueControls the presence of a close button in the popup.
closeButtonLabelString'CloseSpecifies the 'aria-label' attribute of the close button.
autoCloseBooleantrueSet it to false if you want to override the default behavior of
closeOnEscapeKeyBooleantrueSet it to false if you want to override the default behavior of
closeOnClickBoolean*Set it if you want to override the default behavior of the popup closing when user clicks
classNameString''A custom CSS class name to assign to the popup.
trackResizeBooleantrueWhether the popup shall react to changes in the size of its contents

Events

EventDataDescription
popupopenFired when a popup is opened in the map
popupopenFired when a popup bound to this layer is opened
popupcloseFired when a popup in the map is closed
popupcloseFired when a popup bound to this layer is closed
autopanstartFired when the map starts autopanning when opening a popup.