MaplairMap extends Evented
The central class of the API — it is used to create a map on a page and manipulate it.
Panes
Panes are DOM elements used to control the ordering of layers on the map. You can
access panes with map.getPane or map.getPanes
methods. New panes can be created with the map.createPane method.
Every map has the following default panes that differ only in zIndex.
| Pane | zIndex | Description |
|---|---|---|
mapPane |
'auto' |
Pane that contains all other map panes |
tilePane |
200 | Pane for GridLayers and TileLayers |
overlayPane |
400 | Pane for vectors (Paths, like Polylines and Polygons), ImageOverlays and VideoOverlays |
shadowPane |
500 | Pane for overlay shadows (e.g. Marker shadows) |
markerPane |
600 | Pane for Icons of Markers |
tooltipPane |
650 | Pane for Tooltips |
popupPane |
700 | Pane for Popups |
Map state change events
The map state change events movestart, move, moveend, zoomstart, zoom,
zoomend and zoomanim caused by the user (e.g. dragging, scrolling, pinching,
pressing a key or clicking a zoom button) have an originalEvent property with the
DOM event that started the change. It is undefined for changes made by code (e.g.
setView()), which allows to tell them apart, e.g. to avoid feedback loops when
synchronizing the view. The move and zoom events also have flyTo: true on each
flyTo animation frame, and pinch: true while the user pinch-zooms
the map.
Usage example
// initialize the map on the "map" div with a given center and zoom
const map = new MaplairMap('map', {
center: [51.505, -0.09],
zoom: 13
});
Constructor
| Constructor | Description |
|---|---|
new MaplairMap(id: string | HTMLElement, options?: MaplairMapOptions) | Instantiates a map object given the DOM ID of a
|
Options
| Option | Type | Default | Description |
|---|---|---|---|
crs | CRS | EPSG3857 | The Coordinate Reference System to use. Don't change this if you're not sure what it means. |
center | LatLngExpression | Initial geographic center of the map. | |
zoom | number | Initial map zoom level. | |
minZoom | number | Minimum zoom level of the map. If not specified and at
least one | |
maxZoom | number | Maximum zoom level of the map. If not specified and at
least one | |
layers | Layer[] | [] | Array of layers that will be added to the map initially. |
ariaLabel | string | The accessible name of the map, announced by screen
readers, | |
maxBounds | LatLngBoundsExpression | When this option is set, the map
restricts the view to the given geographical bounds, bouncing the user back if the
user tries to pan outside the view. To set the restriction dynamically, use
| |
renderer | Renderer | The default method for drawing vector layers on the
map. A new | |
zoomAnimation | boolean | true | Whether the map zoom animation is enabled. |
zoomAnimationThreshold | number | 4 | Won't animate zoom if the zoom
difference exceeds this value (or 1 if the user prefers
reduced motion
and |
continuousZoom | boolean | false | Whether zoom animations (e.g. of the zoom
control, double click and keyboard) change the view frame by frame through fractional
zoom levels, like |
fadeAnimation | boolean | true | Whether the tile and popup fade animation is enabled. |
markerZoomAnimation | boolean | true | Whether markers animate their zoom with the zoom animation, if disabled they will disappear for the length of the animation. |
markerCulling | boolean | false | Whether markers far outside of the map view (more than half a view away) are taken off the page until the map is moved closer to them. This reduces the browser's rendering work, and the work of repositioning markers while zooming, when a map has many markers (e.g. several thousands) of which only some are visible at a time. |
transform3DLimit | number | 8388608 | Defines the maximum size of a CSS
translation transform (2^23). The default value should not be changed unless a web
browser positions layers in the wrong place after doing a large |
zoomSnap | number | 1 | Forces the map's zoom level to always be a multiple
of this, particularly right after a |
zoomDelta | number | 1 | Controls how much the map's zoom level will change
after a |
trackResize | boolean | true | Whether the map automatically handles browser
window resize to update itself. A hidden map (with the size 0, e.g. |
attributionControl | boolean | true | Whether a attribution control is added to the map by default. |
fullscreenControl | boolean | false | Whether a fullscreen control is added to the map by default. |
rotateControl | boolean | false | Whether a rotate control is added to the map by default. |
zoomControl | boolean | true | Whether a zoom control is added to the map by default. |
closePopupOnClick | boolean | true | Set it to |
renderer | Renderer | The default method for drawing vector layers on the
map. A new | |
bearing | number | 0 | Initial rotation of the map in degrees: the compass
direction pointing up, clockwise from north (e.g. Added by the optional module |
pinchRotate | boolean | false | Whether the map can be rotated by turning two
fingers, see Added by the optional module |
boxZoom | boolean | true | Whether the map can be zoomed to a rectangular area specified by dragging the pointer while pressing the shift key. |
displace | boolean|DisplaceHandlerOptions | Whether to displace
overlapping | |
doubleClickZoom | boolean|'center' | true | Whether the map can be zoomed in
by double clicking on it and zoomed out by double clicking while holding shift. If
passed |
dragging | boolean | true | Whether the map is draggable with pointer or not. |
inertia | boolean | true | If enabled, panning of the map will have an inertia effect where the map builds momentum while dragging and continues moving in the same direction for some time. Feels especially nice on touch devices. |
inertiaDeceleration | number | 3400 | The rate with which the inertial movement slows down, in pixels/second². |
inertiaMaxSpeed | number | 1400 | Max speed of the inertial movement, in pixels/second. |
easeLinearity | number | 0.2 | The linearity of the easing of the inertial movement. |
worldCopyJump | boolean | false | With this option enabled, the map tracks
when you pan to another "copy" of the world and seamlessly jumps to the original one
so that all overlays like markers and vector layers are still visible. A map with an
infinite CRS, such as |
maxBoundsViscosity | number | 0.0 | If |
keyboard | boolean | true | Makes the map focusable and allows users to
navigate the map with keyboard arrows and |
keyboardPanDelta | number | 80 | Amount of pixels to pan when pressing an arrow key. |
ariaKeyShortcuts | boolean|string | false | Sets the |
pinchZoom | boolean|'center' | true | Whether the map can be zoomed by
touch-dragging with two fingers. If passed |
bounceAtZoomLimits | boolean | true | Set it to false if you don't want the map to zoom beyond min/max zoom and then bounce back when pinch-zooming. |
touchZoom | boolean|'center' | Deprecated, use | |
scrollWheelZoom | boolean|'center'|'trackpad' | true | Whether the map can
be zoomed by using the mouse wheel and by pinching on a touchpad (or using the mouse
wheel with the Ctrl key). If passed |
wheelDebounceTime | number | 40 | Limits the rate at which a wheel can fire (in milliseconds). By default, the user can't zoom via wheel more often than once per 40 ms. |
wheelPxPerZoomLevel | number | 60 | How many scroll pixels (as reported by DomEvent.getWheelDelta) mean a change of one full zoom level. Smaller values will make wheel-zooming faster (and vice versa). |
tapDragZoom | boolean|'center' | true | Whether the map can be zoomed with
one finger by tapping once, then touching again and dragging down (zoom in) or up
(zoom out). If passed |
tapHold | boolean | true | Enables simulation of |
tapTolerance | number | 15 | The max number of pixels a user can shift his finger during touch for it to be considered a valid tap. |
Events
| Event | Data | Description |
|---|---|---|
baselayerchange | LayersControlEvent | Fired when the base layer is changed through the layers control. |
overlayadd | LayersControlEvent | Fired when an overlay is selected through the layers control. |
overlayremove | LayersControlEvent | Fired when an overlay is deselected through the layers control. |
searchresult | SearchResultEvent | Fired when a result of the search control is selected. |
dividermove | DividerMoveEvent | Fired when the divider of a SideBySideControl moves. |
timechange | TimeChangeEvent | Fired when the current time of a TimeControl changes. |
resize | ResizeEvent | Fired when the map is resized. |
unload | MaplairEvent | Fired when the map is destroyed with remove method. |
viewprereset | MaplairEvent | Fired before the map resets its view (see viewreset). |
viewreset | MaplairEvent | Fired when the map needs to redraw its content (this usually happens on map zoom or load). Very useful for creating custom overlays. |
load | MaplairEvent | Fired when the map is initialized (when its center and zoom are set for the first time). |
zoomstart | MaplairEvent | Fired when the map zoom is about to change (e.g. before zoom animation). |
movestart | MaplairEvent | Fired when the view of the map starts changing (e.g. user starts dragging the map). |
zoom | MaplairEvent | Fired repeatedly during any change in zoom level, including zoom and fly animations. |
move | MaplairEvent | Fired repeatedly during any movement of the map, including pan and fly animations. |
zoomend | MaplairEvent | Fired when the map zoom changed, after any animations. |
moveend | MaplairEvent | Fired when the center of the map stops changing (e.g. user stopped dragging the map or after non-centered zoom). |
idle | MaplairEvent | Fired when the map becomes idle: the view is not changing (no dragging, panning or zooming, including their animations) and all layers have finished loading (e.g. the tiles of tile layers, see GridLayer.isLoading()). Useful e.g. for taking screenshots or for tests. |
locationerror | MaplairErrorEvent | Fired when geolocation (using the locate method) failed. |
locationfound | LocationEvent | Fired when geolocation (using the locate method) went successfully. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the map. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the map. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the map. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer on the map. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the map. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the map. |
pointermove | MaplairPointerEvent | Fired while the pointer moves over the map. |
contextmenu | MaplairPointerEvent | Fired when the user pushes the right mouse button on the map, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
preclick | MaplairPointerEvent | Fired before pointer click on the map (sometimes useful when you want something to happen on click before any existing click handlers start running). |
keydown | MaplairKeyboardEvent | Fired when the user presses a key from the keyboard while the map is focused. |
keyup | MaplairKeyboardEvent | Fired when the user releases a key from the keyboard while the map is focused. |
crschange | CrsChangeEvent | Fired when the CRS of the map changes with setCrs(), before the view is reset. |
worldcopyjump | WorldCopyJumpEvent | Fired when worldCopyJump moves the map pane by one or more world widths. |
pixelratiochange | MaplairEvent | Fired when the devicePixelRatio of the browser changes, e.g. when moving the window to a screen with another resolution or when zooming the page. Tile layers with detectRetina and canvas renderers adapt to it. |
zoomanim | ZoomAnimEvent | Fired at least once per zoom animation. For continuous zoom, like pinch zooming, fired once per frame during zoom. |
boxzoomstart | MaplairEvent | Fired when the user starts drawing a box to zoom to. |
boxzoomend | BoxZoomEndEvent | Fired when the user has drawn a box and the map is zoomed to it. |
dragstart | MaplairEvent | Fired when the user starts dragging the map. |
drag | MaplairEvent | Fired repeatedly while the user drags the map. |
dragend | DragEndEvent | Fired when the user stops dragging the map. |
focus | MaplairEvent | Fired when the map gains focus. |
blur | MaplairEvent | Fired when the map loses focus. |
enterfullscreen | MaplairEvent | Fired when the map enters fullscreen. |
exitfullscreen | MaplairEvent | Fired when the map exits fullscreen. |
fullscreenchange | MaplairEvent | Fired when the map enters or exits fullscreen. |
layeradd | LayerEvent | Fired when a new layer is added to the map. |
layerremove | LayerEvent | Fired when some layer is removed from the map. |
zoomlevelschange | MaplairEvent | Fired when the number of zoomlevels on the map is changed due to adding or removing a layer. |
popupopen | PopupEvent | Fired when a popup is opened in the map. |
popupclose | PopupEvent | Fired when a popup in the map is closed. |
autopanstart | MaplairEvent | Fired when the map starts autopanning when opening a popup. |
tooltipopen | TooltipEvent | Fired when a tooltip is opened in the map. |
tooltipclose | TooltipEvent | Fired when a tooltip in the map is closed. |
rotate | MaplairEvent | Fired when the bearing of the map changes, see setBearing(). (maplair/map-rotation) |
Methods
Methods for modifying map state
| Method | Returns | Description |
|---|---|---|
setView(center: LatLngExpression, zoom?: number, options?: ZoomPanOptions) | this | Sets the view of the map (geographical center and zoom) with the given animation options. |
setZoom(zoom: number, options?: ZoomPanOptions) | this | Sets the zoom of the map. |
zoomIn(delta?: number, options?: ZoomOptions) | this | Increases the zoom of the map by |
zoomOut(delta?: number, options?: ZoomOptions) | this | Decreases the zoom of the map by |
setZoomAround(latlng: LatLngExpression | Point, zoom: number, options?: ZoomOptions) | this | Zooms the map while keeping a specified geographical point on the map
stationary (e.g. used internally for scroll zoom and double-click zoom). Given a
|
fitBounds(bounds: LatLngBoundsExpression, options?: FitBoundsOptions) | this | Sets a map view that contains the given geographical bounds with the maximum zoom level possible. |
fitWorld(options?: FitBoundsOptions) | this | Sets a map view that mostly contains the whole world with the maximum zoom level possible. |
panTo(center: LatLngExpression, options?: PanOptions) | this | Pans the map to a given center. |
panBy(offset: PointExpression, options?: PanOptions) | this | Pans the map by a given number of pixels (animated unless |
flyTo(targetCenter: LatLngExpression, targetZoom?: number, options?: ZoomPanOptions) | this | Sets the view of the map (geographical center and zoom) performing a smooth
pan-zoom animation. If the user prefers reduced motion (and |
flyToBounds(bounds: LatLngBoundsExpression, options?: FitBoundsOptions) | this | Sets the view of the map with a smooth animation like |
setCrs(crs: CRS) | this | Changes the Coordinate Reference System of the map, keeping its center
and (as far as possible with the zoom levels and |
setMaxBounds(bounds: LatLngBoundsExpression) | this | Restricts the map view to the given bounds (see the maxBounds option). |
setMinZoom(zoom: number) | this | Sets the lower limit for the available zoom levels (see the minZoom option). |
setMaxZoom(zoom: number) | this | Sets the upper limit for the available zoom levels (see the maxZoom option). |
panInsideBounds(bounds: LatLngBoundsExpression, options?: PanOptions) | this | Pans the map to the closest view that would lie inside the given bounds (if it's not already), controlling the animation using the options specific, if any. |
panInside(latlng: LatLngExpression, options?: PaddingOptions & PanOptions) | this | Pans the map the minimum amount to make the |
invalidateSize(options?: InvalidateSizeOptions | boolean) | this | Checks if the map container size changed and updates the map if so —
call it after you've changed the map size dynamically, also panning to
keep the center by default. If |
stop() | this | Stops the currently running |
toggleFullscreen() | this | Enters or exits the fullscreen view of the map, see |
Geolocation methods
| Method | Returns | Description |
|---|---|---|
locate(options?: LocateOptions) | this | Tries to locate the user using the Geolocation API, firing a
|
stopLocate() | this | Stops watching location previously initiated by |
Methods for getting map state
| Method | Returns | Description |
|---|---|---|
getCenter() | LatLng | Returns the geographical center of the map view. |
getZoom() | number | Returns the current zoom level of the map view. |
getBounds() | LatLngBounds | Returns the geographical bounds visible in the current map view. |
getMinZoom() | number | Returns the minimum zoom level of the map (if set in the |
getMaxZoom() | number | Returns the maximum zoom level of the map (if set in the |
getBoundsZoom(bounds: LatLngBoundsExpression, inside?: boolean, padding?: PointExpression) | number | Returns the maximum zoom level on which the given bounds fit to the map
view in its entirety. If |
getSize() | Point | Returns the current size of the map container (in pixels). |
getPixelBounds(center?: LatLngExpression, zoom?: number) | Bounds | Returns the bounds of the current map view in projected pixel
coordinates (sometimes useful in layer and overlay implementations).
If |
getPixelOrigin() | Point | Returns the projected pixel coordinates of the top left point of the map layer (useful in custom layer and overlay implementations). |
getPixelWorldBounds(zoom?: number) | Bounds | null | Returns the world's bounds in pixel coordinates for zoom level Returns |
Conversion methods
| Method | Returns | Description |
|---|---|---|
getZoomScale(toZoom: number, fromZoom?: number) | number | Returns the scale factor to be applied to a map transition from zoom level
|
getScaleZoom(scale: number, fromZoom?: number) | number | Returns the zoom level that the map would end up at, if it is at |
project(latlng: LatLngExpression, zoom?: number) | Point | Projects a geographical coordinate |
unproject(point: PointExpression, zoom?: number) | LatLng | Inverse of |
layerPointToLatLng(point: PointExpression) | LatLng | Given a pixel coordinate relative to the origin pixel, returns the corresponding geographical coordinate (for the current zoom level). |
latLngToLayerPoint(latlng: LatLngExpression) | Point | Given a geographical coordinate, returns the corresponding pixel coordinate relative to the origin pixel. |
wrapLatLng(latlng: LatLngExpression) | LatLng | Returns a |
wrapLatLngBounds(bounds: LatLngBoundsExpression) | LatLngBounds | Returns a |
distance(latlng1: LatLngExpression, latlng2: LatLngExpression) | number | Returns the distance between two geographical coordinates according to the map's CRS. By default this measures distance in meters. |
containerPointToLayerPoint(point: PointExpression) | Point | Given a pixel coordinate relative to the map container, returns the corresponding pixel coordinate relative to the origin pixel. |
layerPointToContainerPoint(point: PointExpression) | Point | Given a pixel coordinate relative to the origin pixel, returns the corresponding pixel coordinate relative to the map container. |
containerPointToLatLng(point: PointExpression) | LatLng | Given a pixel coordinate relative to the map container, returns the corresponding geographical coordinate (for the current zoom level). |
latLngToContainerPoint(latlng: LatLngExpression) | Point | Given a geographical coordinate, returns the corresponding pixel coordinate relative to the map container. |
pointerEventToContainerPoint(e: MouseEvent | PointerEvent) | Point | Given a PointerEvent object, returns the pixel coordinate relative to the map container where the event took place. |
pointerEventToLayerPoint(e: MouseEvent | PointerEvent) | Point | Given a PointerEvent object, returns the pixel coordinate relative to the origin pixel where the event took place. |
pointerEventToLatLng(e: MouseEvent | PointerEvent) | LatLng | Given a PointerEvent object, returns geographical coordinate where the event took place. |
Methods for layers and controls
| Method | Returns | Description |
|---|---|---|
addControl(control: Control) | this | Adds the given control to the map. |
removeControl(control: Control) | this | Removes the given control from the map. |
addLayer(layer: Layer) | this | Adds the given layer to the map. |
removeLayer(layer: Layer) | this | Removes the given layer from the map. |
hasLayer(layer: Layer) | boolean | Returns |
eachLayer(method: (layer: Layer) => void, context?: object) | this | Iterates over the layers of the map, optionally specifying context of the iterator function.
|
openPopup(popup: Popup | DivOverlayContent, latlng?: LatLngExpression, options?: PopupOptions) | this | Opens the specified popup while closing the previously opened (to make sure only one is opened at one time for usability). Alternatively, creates a popup with the specified content and options and opens
it in the given point on a map. String content is rendered as HTML; sanitize
untrusted input or pass an
|
closePopup(popup?: Popup, …args: any[]) | this | Closes the popup previously opened with openPopup (or the given one). |
openTooltip(tooltip: Tooltip | DivOverlayContent, latlng?: LatLngExpression, options?: TooltipOptions) | this | Opens the specified tooltip. Alternatively, creates a tooltip with the specified content and options and
opens it. String content is rendered as HTML; sanitize untrusted input or pass
an
|
closeTooltip(tooltip: Tooltip) | this | Closes the tooltip given as parameter. |
Map rotation
| Method | Returns | Description |
|---|---|---|
setBearing(bearing: number, options?: { animate?: boolean; }) | this | Rotates the map around the center of the view, so that the compass direction
Added by the optional module |
getBearing() | number | Returns the rotation of the map, see Added by the optional module |
Other methods
| Method | Returns | Description |
|---|---|---|
addHandler(name: string, HandlerClass: new (map: MaplairMap) => Handler) | this | Adds a new |
remove() | this | Destroys the map and clears all related event listeners. |
createPane(name: string, container?: HTMLElement) | HTMLElement | Creates a new map pane with the given name if it doesn't exist already,
then returns it. The pane is created as a child of |
getPane(pane: string | HTMLElement) | HTMLElement | Returns a map pane, given its name or its HTML element (its identity). |
getPanes() | Record<string, HTMLElement> | Returns a plain object containing the names of all panes as keys and the panes as values. |
getContainer() | HTMLElement | Returns the HTML element that contains the map. |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type, see |
whenReady(callback: (event: { target: MaplairMap; }) => void, context?: object) | this | Runs the given function |
isFullscreen() | boolean | Returns |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Properties
| Property | Type | Description |
|---|---|---|
attributionControl | AttributionControl | The attribution control of the map,
the default one (if the |
fullscreenControl | FullscreenControl | The default fullscreen control (only
available if the |
rotateControl | RotateControl | The default rotate control (only available if
the |
zoomControl | ZoomControl | The default zoom control (only available if the
|
boxZoom | BoxZoomHandler | Box (shift-drag with pointer) zoom handler. |
displace | DisplaceHandler | The displacement handler, if added with the
name |
doubleClickZoom | DoubleClickZoomHandler | Double click zoom handler. |
dragging | DragHandler | Map dragging handler. |
keyboard | KeyboardHandler | Keyboard navigation handler. |
pinchZoom | PinchZoomHandler | Pinch zoom handler. |
touchZoom | PinchZoomHandler | Deprecated, the same as |
scrollWheelZoom | ScrollWheelZoomHandler | Scroll wheel zoom handler. |
tapDragZoom | TapDragZoomHandler | Tap-drag zoom handler (double tap and drag with one finger). |
tapHold | TapHoldHandler | Long tap handler to simulate |
Hash
Keeps the view of the map in the hash of the URL, e.g. #13/47.2692/11.4041
(zoom, latitude, longitude, and the bearing of a rotated map) or as
geo URI #geo:47.2692,11.4041?z=13
(see the format option), so that it can be bookmarked and shared. The view
is restored from the hash (in either format) when creating the Hash and when
the hash changes (e.g. with the back button of the browser).
With the layers option, the hash also keeps the base layer and the overlays
shown on the map, e.g. #13/47.2692/11.4041?layers=OSM,Bike%20routes.
With the option mode: 'query', the view is kept in the query string instead,
e.g. ?zoom=13&lat=47.2692&lng=11.4041, keeping the other parameters of the app.
Inspired by the leaflet-hash plugin.
Usage example
const map = new MaplairMap('map').setView([47.27, 11.40], 13);
new Hash(map);
// with the layers of a layers control
const baseLayers = {OSM: osm, Topo: topo}, overlays = {'Bike routes': bikes};
new LayersControl(baseLayers, overlays).addTo(map);
new Hash(map, {layers: {...baseLayers, ...overlays}});
// in the query string, e.g. ?q=cafe&zoom=13&lat=47.2692&lng=11.4041
new Hash(map, {mode: 'query'});
Constructor
| Constructor | Description |
|---|---|
new Hash(map: MaplairMap, options?: HashOptions) | Synchronizes the view of |
Options
| Option | Type | Default | Description |
|---|---|---|---|
format | 'zoom/lat/lng'|'geo' | 'zoom/lat/lng' | The format of the hash:
|
layers | Record<string, Layer> | The layers to keep in the hash by name,
e.g. the base layers and overlays of a | |
mode | 'hash'|'query' | 'hash' | Where to keep the view: |
Methods
| Method | Returns | Description |
|---|---|---|
remove() | this | Stops synchronizing the view with the hash of the URL. |
Static members
| Method | Returns | Description |
|---|---|---|
parse(hash: string) | HashView | undefined | Parses a hash like |
format(map: MaplairMap, format?: "zoom/lat/lng" | "geo", layers?: Record<string, Layer>) | string | Returns the hash for the view of the map in the given |
parseQuery(search: string) | HashView | undefined | Parses the parameters |
formatQuery(map: MaplairMap, layers?: Record<string, Layer>, search?: string) | string | Returns the query string |
MapSync
Synchronizes the views (center, zoom and bearing) of several maps, e.g. to compare different layers side by side: whenever one of the maps moves (by the user or by code, including animations), the other maps follow.
With the options oneWay and fit: 'bounds', smaller maps can follow a main
map showing its bounds, e.g. thumbnails next to it.
Inspired by the Leaflet.Sync plugin.
Usage example
const sync = new MapSync([map1, map2]);
// later
sync.remove();
// a thumbnail showing the bounds of the main map
new MapSync([map, thumbnail], {oneWay: true, fit: 'bounds'});
Constructor
| Constructor | Description |
|---|---|
new MapSync(maps: MaplairMap[], options?: MapSyncOptions) | Synchronizes the views of the given maps, starting with the view of the first map. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
bearing | boolean | true | Whether to synchronize the bearing of rotated maps
(with the map rotation, see |
oneWay | boolean | false | Whether only the first map leads and the other maps follow it, without moving the first map when they are moved. |
fit | 'center'|'bounds' | 'center' | How the maps follow: |
Methods
| Method | Returns | Description |
|---|---|---|
remove() | this | Stops synchronizing the maps. |
Marker extends Layer
Marker is used to display clickable/draggable icons on the map. Extends Layer.
In addition to shared layer methods like addTo() and remove() and
popup methods like bindPopup() you can also use the methods below.
Usage example
new Marker([50.5, 30.5]).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new Marker(latlng: LatLngExpression, options?: MarkerOptions) | Instantiates a Marker object given a geographical point and optionally an options object. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
icon | Icon | new DefaultIcon() | Icon instance to use for rendering the
marker. See Icon documentation for details on how to customize the marker
icon. If not specified, a common instance of |
keyboard | boolean | true | Whether the marker can be tabbed to with a keyboard and, if interactive, clicked by pressing Enter or Space. |
title | string | '' | Text for the browser tooltip that appear on marker hover (no tooltip by default). Useful for accessibility. |
alt | string | Text for the | |
zIndexOffset | number | 0 | By default, marker images zIndex is set
automatically based on its latitude. Use this option if you want to put the marker on
top of all others (or below), specifying a high value like |
opacity | number | 1 | The opacity of the marker. |
rotation | number|null | null | Rotation of the marker icon in degrees,
clockwise, around the icon anchor, e.g. for the heading of a vehicle. A rotated
marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong
under a tilted one. |
riseOnHover | boolean | false | If |
riseOffset | number | 250 | The z-index offset used when the marker gets on top of others on hover or focus. |
pane | string | 'markerPane' |
|
shadowPane | string | 'shadowPane' |
|
shadow | boolean | true | Whether to show the shadow of the marker's icon. Each
shadow is an additional element on the page, so disabling shadows noticeably reduces
the browser's rendering work when showing many markers (e.g. several thousands),
especially while panning and zooming. To disable shadows for all markers, use
|
bubblingPointerEvents | boolean | false | When |
autoPanOnFocus | boolean | true | When |
draggable | boolean | false | Whether the marker is draggable with pointer or not. A focused draggable marker can also be moved with the arrow keys, by 10 pixels or 30 with Shift. |
autoPan | boolean | false | Whether to pan the map when dragging this marker near its edge or not. |
autoPanPadding | PointExpression | [50, 50] | Distance (in pixels to the left/right and to the top/bottom) of the map edge to start panning the map. |
autoPanSpeed | number | 10 | Number of pixels the map should pan by. |
rotateWithView | boolean | false | On a rotated map (see
Added by the optional module |
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
| Event | Data | Description |
|---|---|---|
dragstart | MaplairEvent | Fired when the user starts dragging the marker. |
movestart | MaplairEvent | Fired when the marker starts moving (because of dragging). |
drag | MarkerMoveEvent | Fired repeatedly while the user drags the marker. |
dragend | DragEndEvent | Fired when the user stops dragging the marker. |
moveend | MaplairEvent | Fired when the marker stops moving (because of dragging). |
move | MarkerMoveEvent | Fired when the marker is moved via setLatLng or by dragging. Old and new coordinates are included in event arguments as oldLatLng, latlng. |
moveend | MaplairEvent | Fired when the marker stops moving (after dragging or moveAlong()). (maplair/marker-movement) |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
Marker movement
| Method | Returns | Description |
|---|---|---|
moveTo(latlng: LatLngExpression, options?: MarkerMovementOptions) | this | Moves the marker smoothly to Added by the optional module |
moveAlong(latlngs: LatLngExpression[], options?: MarkerMovementOptions) | this | Moves the marker smoothly along the given points, frame by frame at a constant
speed, e.g. to follow a vehicle or to replay a track. Fires Added by the optional module |
stopMoving() | this | Stops the movement of Added by the optional module |
isMoving() | boolean | Returns Added by the optional module |
Other methods
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | Adds the icon (and shadow) of the marker to the map. |
onRemove(map: MaplairMap) | void | Removes the icon (and shadow) of the marker from the map. |
getEvents() | Record<string, Function> | Returns the map events the marker listens to, see |
getLatLng() | LatLng | Returns the current geographical position of the marker. |
setLatLng(latlng: LatLngExpression) | this | Changes the marker position to the given point. |
setZIndexOffset(offset: number) | this | Changes the zIndex offset of the marker. |
getIcon() | Icon | Returns the current icon used by the marker. |
setIcon(icon: Icon) | this | Changes the marker icon. |
getElement() | HTMLElement | Returns the instance of |
update() | this | Updates the position of the marker on the map, e.g. after a change of its options. |
getRotation() | number | null | Returns the current rotation of the marker in degrees. |
setRotation(rotation: number | null) | this | Changes the rotation of the marker; |
setOpacity(opacity: number) | this | Changes the opacity of the marker. |
toGeoJSON(precision?: number | false) | Feature | Coordinates values are rounded with |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Properties
| Property | Type | Description |
|---|---|---|
dragging | MarkerDrag | undefined | Marker dragging handler, see Interaction handlers are properties of a marker instance that allow you to
control interaction behavior in runtime, enabling or disabling certain
features such as dragging (see
|
DivOverlay extends Layer
Base model for Popup and Tooltip; use those to show content on the map. Inherit
from it for custom overlays like plugins.
Constructor
| Constructor | Description |
|---|---|
new DivOverlay(options?: DivOverlayOptions | undefined, source?: Layer | undefined) | Instantiates an overlay given an optional |
new DivOverlay(latlng: LatLngExpression, options?: DivOverlayOptions | undefined) | Instantiates an overlay given |
Options
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | false | If true, the popup/tooltip will listen to the pointer events. |
offset | PointExpression | [0, 0] | The offset of the overlay position. |
className | string | '' | A custom CSS class name to assign to the overlay. |
pane | string |
| |
overflow | boolean | false | Whether the overlay may extend beyond the map container, e.g. a tooltip of a marker near the edge of a small map. The overlay is then shown as popover in the top layer of the page, above all other content, while remaining in its map pane in the DOM (for styling and events). |
content | DivOverlayContent | '' | Sets the HTML content of the overlay while
initializing. If a function is passed the source layer will be passed to the
function. The function should return a |
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
| Event | Data | Description |
|---|---|---|
contentupdate | MaplairEvent | Fired when the content of the overlay is updated. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
openOn(map: MaplairMap, …args: any[]) | this | Adds the overlay to the map.
Alternative to |
close() | this | Closes the overlay.
Alternative to |
toggle(layer?: Layer, …args: any[]) | this | Opens or closes the overlay bound to layer depending on its current state.
Argument may be omitted only for overlay bound to layer.
Alternative to |
onAdd(map: MaplairMap) | void | Adds the overlay to the map. |
onRemove(map: MaplairMap) | void | Removes the overlay from the map. |
getLatLng() | LatLng | Returns the geographical point of the overlay. |
setLatLng(latlng: LatLngExpression) | this | Sets the geographical point where the overlay will open. |
getContent() | DivOverlayContent | Returns the content of the overlay. |
setContent(content: DivOverlayContent) | this | Sets the HTML content of the overlay. A |
getElement() | HTMLElement | Returns the HTML container of the overlay. |
update() | void | Updates the overlay content, layout and position. Useful for updating the overlay after something inside changed, e.g. image loaded. |
getEvents() | Record<string, EventListener> | Returns the map events the overlay listens to. |
isOpen() | boolean | Returns |
bringToFront() | this | Brings this overlay in front of other overlays (in the same map pane). |
bringToBack() | this | Brings this overlay to the back of other overlays (in the same map pane). |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Popup extends DivOverlay
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:
marker.bindPopup(popupContent).openPopup();
Path overlays like polylines also have a bindPopup method.
A popup can be also standalone:
const popup = new Popup()
.setLatLng(latlng)
.setContent('<p>Hello world!<br />This is a nice popup.</p>')
.openOn(map);
or
const popup = new Popup(latlng, {content: '<p>Hello world!<br />This is a nice popup.</p>'})
.openOn(map);
Security note. Popup string content is rendered as HTML. If your content
may include untrusted input (e.g. data from users or external APIs), sanitize
it with a library like DOMPurify, or
build a DOM element using textContent to render it as plain text:
const el = document.createElement('div');
el.textContent = untrustedString;
marker.bindPopup(el);
Constructor
| Constructor | Description |
|---|---|
new Popup(options?: PopupOptions | undefined, source?: Layer | undefined) | Instantiates a |
new Popup(latlng: LatLngExpression, options?: PopupOptions | undefined) | Instantiates a |
Options
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'popupPane' |
|
offset | PointExpression | [0, 7] | The offset of the popup position. |
maxWidth | number | 300 | Max width of the popup, in pixels. |
minWidth | number | 50 | Min width of the popup, in pixels. |
maxHeight | number|null | null | If set, creates a scrollable container of
the given height inside a popup if its content exceeds it. The scrollable container
can be styled using the |
autoPan | boolean | true | Set it to |
autoPanPaddingTopLeft | PointExpression|null | null | The margin between the popup and the top left corner of the map view after autopanning was performed. |
autoPanPaddingBottomRight | PointExpression|null | null | The margin between the popup and the bottom right corner of the map view after autopanning was performed. |
autoPanPadding | PointExpression | [5, 5] | Equivalent of setting both top left and bottom right autopan padding to the same value. |
keepInView | boolean | false | Set it to |
closeButton | boolean | true | Controls the presence of a close button in the popup. |
autoClose | boolean | true | Set it to |
closeOnEscapeKey | boolean | true | Set it to |
closeOnClick | boolean | Set it if you want to override the default
behavior of the popup closing when user clicks on the map. Defaults to the map's
| |
className | string | '' | A custom CSS class name to assign to the popup. |
trackResize | boolean | true | Whether the popup shall react to changes in the size of its contents (e.g. when an image inside the popup loads) and reposition itself. |
Options inherited from DivOverlay
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | false | If true, the popup/tooltip will listen to the pointer events. |
offset | PointExpression | [0, 0] | The offset of the overlay position. |
className | string | '' | A custom CSS class name to assign to the overlay. |
pane | string |
| |
overflow | boolean | false | Whether the overlay may extend beyond the map container, e.g. a tooltip of a marker near the edge of a small map. The overlay is then shown as popover in the top layer of the page, above all other content, while remaining in its map pane in the DOM (for styling and events). |
content | DivOverlayContent | '' | Sets the HTML content of the overlay while
initializing. If a function is passed the source layer will be passed to the
function. The function should return a |
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
Events inherited from DivOverlay
| Event | Data | Description |
|---|---|---|
contentupdate | MaplairEvent | Fired when the content of the overlay is updated. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
openOn(map: MaplairMap, …args: any[]) | this | Alternative to |
Methods inherited from DivOverlay
| Method | Returns | Description |
|---|---|---|
close() | this | Closes the overlay.
Alternative to |
toggle(layer?: Layer, …args: any[]) | this | Opens or closes the overlay bound to layer depending on its current state.
Argument may be omitted only for overlay bound to layer.
Alternative to |
onAdd(map: MaplairMap) | void | Adds the overlay to the map. |
onRemove(map: MaplairMap) | void | Removes the overlay from the map. |
getLatLng() | LatLng | Returns the geographical point of the overlay. |
setLatLng(latlng: LatLngExpression) | this | Sets the geographical point where the overlay will open. |
getContent() | DivOverlayContent | Returns the content of the overlay. |
setContent(content: DivOverlayContent) | this | Sets the HTML content of the overlay. A |
getElement() | HTMLElement | Returns the HTML container of the overlay. |
update() | void | Updates the overlay content, layout and position. Useful for updating the overlay after something inside changed, e.g. image loaded. |
getEvents() | Record<string, EventListener> | Returns the map events the overlay listens to. |
isOpen() | boolean | Returns |
bringToFront() | this | Brings this overlay in front of other overlays (in the same map pane). |
bringToBack() | this | Brings this overlay to the back of other overlays (in the same map pane). |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Tooltip extends DivOverlay
Used to display small texts on top of map layers.
Usage example
If you want to just bind a tooltip to marker:
marker.bindTooltip("my tooltip text").openTooltip();
Path overlays like polylines also have a bindTooltip method.
A tooltip can be also standalone:
const tooltip = new Tooltip()
.setLatLng(latlng)
.setContent('Hello world!<br />This is a nice tooltip.')
.addTo(map);
or
const tooltip = new Tooltip(latlng, {content: 'Hello world!<br />This is a nice tooltip.'})
.addTo(map);
Security note. Tooltip string content is rendered as HTML. If your content
may include untrusted input (e.g. data from users or external APIs), sanitize
it with a library like DOMPurify, or
build a DOM element using textContent to render it as plain text:
const el = document.createElement('div');
el.textContent = untrustedString;
marker.bindTooltip(el);
Note about tooltip offset. Maplair takes two options in consideration for computing tooltip offsetting:
- the
offsetTooltip option: it defaults to [0, 0], and it's specific to one tooltip. Add a positive x offset to move the tooltip to the right, and a positive y offset to move it to the bottom. Negatives will move to the left and top. - the
tooltipAnchorIcon option: this will only be considered for Marker. You should adapt this value if you use a custom icon.
Constructor
| Constructor | Description |
|---|---|
new Tooltip(options?: TooltipOptions | undefined, source?: Layer | undefined) | Instantiates a |
new Tooltip(latlng: LatLngExpression, options?: TooltipOptions | undefined) | Instantiates a |
Options
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'tooltipPane' |
|
offset | PointExpression | [0, 0] | Optional offset of the tooltip position. |
direction | 'right'|'left'|'top'|'bottom'|'center'|'auto' | 'auto' | Direction where to open the tooltip. Possible values are: |
permanent | boolean | false | Whether to open the tooltip permanently or only on pointerover. |
sticky | boolean | false | If true, the tooltip will follow the pointer instead of being fixed at the feature center. |
opacity | number | 0.9 | Tooltip container opacity. |
Options inherited from DivOverlay
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | false | If true, the popup/tooltip will listen to the pointer events. |
offset | PointExpression | [0, 0] | The offset of the overlay position. |
className | string | '' | A custom CSS class name to assign to the overlay. |
pane | string |
| |
overflow | boolean | false | Whether the overlay may extend beyond the map container, e.g. a tooltip of a marker near the edge of a small map. The overlay is then shown as popover in the top layer of the page, above all other content, while remaining in its map pane in the DOM (for styling and events). |
content | DivOverlayContent | '' | Sets the HTML content of the overlay while
initializing. If a function is passed the source layer will be passed to the
function. The function should return a |
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
Events inherited from DivOverlay
| Event | Data | Description |
|---|---|---|
contentupdate | MaplairEvent | Fired when the content of the overlay is updated. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
setOpacity(opacity: number) | void | Sets the opacity of the tooltip. |
Methods inherited from DivOverlay
| Method | Returns | Description |
|---|---|---|
openOn(map: MaplairMap, …args: any[]) | this | Adds the overlay to the map.
Alternative to |
close() | this | Closes the overlay.
Alternative to |
toggle(layer?: Layer, …args: any[]) | this | Opens or closes the overlay bound to layer depending on its current state.
Argument may be omitted only for overlay bound to layer.
Alternative to |
onAdd(map: MaplairMap) | void | Adds the overlay to the map. |
onRemove(map: MaplairMap) | void | Removes the overlay from the map. |
getLatLng() | LatLng | Returns the geographical point of the overlay. |
setLatLng(latlng: LatLngExpression) | this | Sets the geographical point where the overlay will open. |
getContent() | DivOverlayContent | Returns the content of the overlay. |
setContent(content: DivOverlayContent) | this | Sets the HTML content of the overlay. A |
getElement() | HTMLElement | Returns the HTML container of the overlay. |
update() | void | Updates the overlay content, layout and position. Useful for updating the overlay after something inside changed, e.g. image loaded. |
getEvents() | Record<string, EventListener> | Returns the map events the overlay listens to. |
isOpen() | boolean | Returns |
bringToFront() | this | Brings this overlay in front of other overlays (in the same map pane). |
bringToBack() | this | Brings this overlay to the back of other overlays (in the same map pane). |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
TileLayer extends GridLayer
Used to load and display tile layers on the map. Note that most tile servers require
attribution, which you can set under Layer. Extends GridLayer.
URL template
A string of the following form:
'https://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png'
{s} means one of the available subdomains (used sequentially to help with browser
parallel requests per domain limitation; subdomain values are specified in options;
a, b or c by default, can be omitted), {z} — zoom level, {x} and {y} —
tile coordinates. {r} can be used to add "@2x" to the URL to load retina tiles.
You can use custom keys in the template, which will be evaluated from TileLayer options, like this:
new TileLayer('https://{s}.somedomain.com/{foo}/{z}/{x}/{y}.png', {foo: 'bar'});
Layers extending TileLayer might reimplement the getTileUrl()
method.
Usage example
new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar', attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'}).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new TileLayer(url: string, options?: TileLayerOptions & Record<string, unknown>) | Instantiates a tile layer object given a URL template and optionally an options object.
|
Options
| Option | Type | Default | Description |
|---|---|---|---|
minZoom | number | 0 | The minimum zoom level down to which this layer will be displayed (inclusive). |
maxZoom | number | 18 | The maximum zoom level up to which this layer will be displayed (inclusive). |
subdomains | string|string[] | 'abc' | Subdomains of the tile service. Can be passed in the form of one string (where each letter is a subdomain name) or an array of strings. |
errorTileUrl | string | '' | URL to the tile image to show in place of the tile that failed to load. |
zoomOffset | number | 0 | The zoom number used in tile URLs will be offset with this value. |
tms | boolean | false | If |
zoomReverse | boolean | false | If set to true, the zoom number used in tile
URLs will be reversed ( |
detectRetina | boolean | false | If |
crossOrigin | boolean|string | false | Whether the crossOrigin attribute will be added to the tiles. If a String is provided, all tiles will have their crossOrigin attribute set to the String provided. This is needed if you want to access tile pixel data. Refer to CORS Settings for valid String values. |
referrerPolicy | ReferrerPolicy | 'strict-origin-when-cross-origin' | Sets the
tiles' Tile providers might require you to use a specific referrer policy (e.g. to verify
API tokens or prevent abuse). Specifically, if you are using tiles from
|
fetchOptions | RequestInit|null | null | If set, the tiles are loaded with
|
Options inherited from GridLayer
| Option | Type | Default | Description |
|---|---|---|---|
tileSize | number|Point | 256 | Width and height of tiles in the grid. Use a
number if width and height are equal, or |
opacity | number | 1 | Opacity of the tiles. Can be used in the |
placeholder | string|null | null | A CSS
|
updateWhenIdle | boolean | false | Load new tiles only when panning ends. |
updateWhenZooming | boolean | true | By default, a smooth zoom animation
(during a pinch zoom or a |
updateInterval | number | 200 | Tiles will not update more than once every
|
zIndex | number | 1 | The explicit zIndex of the tile layer. |
bounds | LatLngBoundsExpression|null | null | If set, tiles will only be
loaded inside the set |
minZoom | number | 0 | The minimum zoom level down to which this layer will be displayed (inclusive). |
maxZoom | number | The maximum zoom level up to which this layer will be displayed (inclusive). | |
maxNativeZoom | number | Maximum zoom number the tile source has available.
If it is specified, the tiles on all zoom levels higher than | |
minNativeZoom | number | Minimum zoom number the tile source has available.
If it is specified, the tiles on all zoom levels lower than | |
noWrap | boolean | false | Whether the layer is wrapped around the
antimeridian. If |
pane | string | 'tilePane' |
|
className | string | '' | A custom class name to assign to the tile layer. Empty by default. |
pixelated | boolean | false | Whether to scale the tiles with
nearest-neighbour interpolation ( |
keepBuffer | number | 2 | When panning the map, keep this many rows and columns of tiles before unloading them. |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
| Event | Data | Description |
|---|---|---|
tileabort | TileEvent | Fired when a tile was loading but is now not wanted. |
Events inherited from GridLayer
| Event | Data | Description |
|---|---|---|
loading | MaplairEvent | Fired when the grid layer starts loading tiles. |
tileunload | TileEvent | Fired when a tile is removed (e.g. when a tile goes off the screen). |
tileloadstart | TileEvent | Fired when a tile is requested and starts loading. |
tileerror | TileErrorEvent | Fired when there is an error loading a tile. |
tileload | TileEvent | Fired when a tile loads. |
load | MaplairEvent | Fired when the grid layer loaded all visible tiles. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
Extension methods
| Method | Returns | Description |
|---|---|---|
getTileUrl(coords: Point) | string | Called only internally, returns the URL for a tile given its coordinates.
Classes extending |
Other methods
| Method | Returns | Description |
|---|---|---|
setUrl(url: string, noRedraw?: boolean) | this | Updates the layer's URL template and redraws it (unless |
createTile(coords: Point, done?: TileDoneCallback) | HTMLImageElement | Called only internally, overrides GridLayer's |
Methods inherited from GridLayer
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | Creates the container of the tiles and loads the tiles. |
beforeAdd(map: MaplairMap) | void | Registers the zoom limits of the layer on the map. |
onRemove(map: MaplairMap) | void | Removes the tiles from the map. |
bringToFront() | this | Brings the tile layer to the top of all tile layers. |
bringToBack() | this | Brings the tile layer to the bottom of all tile layers. |
getContainer() | HTMLElement | Returns the HTML element that contains the tiles for this layer. |
setOpacity(opacity: number) | this | Changes the opacity of the grid layer. |
setZIndex(zIndex: number) | this | Changes the zIndex of the grid layer. |
isLoading() | boolean | Returns |
redraw() | this | Causes the layer to clear all the tiles and request them again. |
getEvents() | Record<string, Function> | Returns the map events the layer listens to, see |
getTileSize() | Point | Normalizes the tileSize option into a point. Used by
the |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
WMSTileLayer extends TileLayer
Used to display WMS services as tile
layers on the map. Extends TileLayer.
Usage example
const nexrad = new WMSTileLayer("http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi", {
layers: 'nexrad-n0r-900913',
format: 'image/png',
transparent: true,
attribution: "Weather data © 2012 IEM Nexrad"
});
Constructor
| Constructor | Description |
|---|---|
new WMSTileLayer(url: string, options: WMSTileLayerOptions & Record<string, unknown>) | Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS parameters/options object.
|
Options
| Option | Type | Default | Description |
|---|---|---|---|
layers | string | '' | (required) Comma-separated list of WMS layers to show. |
styles | string | '' | Comma-separated list of WMS styles. |
format | string | 'image/jpeg' | WMS image format (use |
transparent | boolean | false | If |
version | string | '1.1.1' | Version of the WMS service to use. |
crs | CRS|null | null | Coordinate Reference System to use for the WMS requests, defaults to map CRS. Don't change this if you're not sure what it means. |
uppercase | boolean | false | If |
Options inherited from TileLayer
| Option | Type | Default | Description |
|---|---|---|---|
minZoom | number | 0 | The minimum zoom level down to which this layer will be displayed (inclusive). |
maxZoom | number | 18 | The maximum zoom level up to which this layer will be displayed (inclusive). |
subdomains | string|string[] | 'abc' | Subdomains of the tile service. Can be passed in the form of one string (where each letter is a subdomain name) or an array of strings. |
errorTileUrl | string | '' | URL to the tile image to show in place of the tile that failed to load. |
zoomOffset | number | 0 | The zoom number used in tile URLs will be offset with this value. |
tms | boolean | false | If |
zoomReverse | boolean | false | If set to true, the zoom number used in tile
URLs will be reversed ( |
detectRetina | boolean | false | If |
crossOrigin | boolean|string | false | Whether the crossOrigin attribute will be added to the tiles. If a String is provided, all tiles will have their crossOrigin attribute set to the String provided. This is needed if you want to access tile pixel data. Refer to CORS Settings for valid String values. |
referrerPolicy | ReferrerPolicy | 'strict-origin-when-cross-origin' | Sets the
tiles' Tile providers might require you to use a specific referrer policy (e.g. to verify
API tokens or prevent abuse). Specifically, if you are using tiles from
|
fetchOptions | RequestInit|null | null | If set, the tiles are loaded with
|
Options inherited from GridLayer
| Option | Type | Default | Description |
|---|---|---|---|
tileSize | number|Point | 256 | Width and height of tiles in the grid. Use a
number if width and height are equal, or |
opacity | number | 1 | Opacity of the tiles. Can be used in the |
placeholder | string|null | null | A CSS
|
updateWhenIdle | boolean | false | Load new tiles only when panning ends. |
updateWhenZooming | boolean | true | By default, a smooth zoom animation
(during a pinch zoom or a |
updateInterval | number | 200 | Tiles will not update more than once every
|
zIndex | number | 1 | The explicit zIndex of the tile layer. |
bounds | LatLngBoundsExpression|null | null | If set, tiles will only be
loaded inside the set |
minZoom | number | 0 | The minimum zoom level down to which this layer will be displayed (inclusive). |
maxZoom | number | The maximum zoom level up to which this layer will be displayed (inclusive). | |
maxNativeZoom | number | Maximum zoom number the tile source has available.
If it is specified, the tiles on all zoom levels higher than | |
minNativeZoom | number | Minimum zoom number the tile source has available.
If it is specified, the tiles on all zoom levels lower than | |
noWrap | boolean | false | Whether the layer is wrapped around the
antimeridian. If |
pane | string | 'tilePane' |
|
className | string | '' | A custom class name to assign to the tile layer. Empty by default. |
pixelated | boolean | false | Whether to scale the tiles with
nearest-neighbour interpolation ( |
keepBuffer | number | 2 | When panning the map, keep this many rows and columns of tiles before unloading them. |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
Events inherited from TileLayer
| Event | Data | Description |
|---|---|---|
tileabort | TileEvent | Fired when a tile was loading but is now not wanted. |
Events inherited from GridLayer
| Event | Data | Description |
|---|---|---|
loading | MaplairEvent | Fired when the grid layer starts loading tiles. |
tileunload | TileEvent | Fired when a tile is removed (e.g. when a tile goes off the screen). |
tileloadstart | TileEvent | Fired when a tile is requested and starts loading. |
tileerror | TileErrorEvent | Fired when there is an error loading a tile. |
tileload | TileEvent | Fired when a tile loads. |
load | MaplairEvent | Fired when the grid layer loaded all visible tiles. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
getLegendUrl(params?: Record<string, any>) | string | Returns the URL of the legend image (a |
setParams(params: Record<string, any>, noRedraw?: boolean) | this | Merges an object with the new parameters and re-requests tiles on the current screen
(unless |
Methods inherited from TileLayer
| Method | Returns | Description |
|---|---|---|
setUrl(url: string, noRedraw?: boolean) | this | Updates the layer's URL template and redraws it (unless |
createTile(coords: Point, done?: TileDoneCallback) | HTMLImageElement | Called only internally, overrides GridLayer's |
getTileUrl(coords: Point) | string | Called only internally, returns the URL for a tile given its coordinates.
Classes extending |
Methods inherited from GridLayer
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | Creates the container of the tiles and loads the tiles. |
beforeAdd(map: MaplairMap) | void | Registers the zoom limits of the layer on the map. |
onRemove(map: MaplairMap) | void | Removes the tiles from the map. |
bringToFront() | this | Brings the tile layer to the top of all tile layers. |
bringToBack() | this | Brings the tile layer to the bottom of all tile layers. |
getContainer() | HTMLElement | Returns the HTML element that contains the tiles for this layer. |
setOpacity(opacity: number) | this | Changes the opacity of the grid layer. |
setZIndex(zIndex: number) | this | Changes the zIndex of the grid layer. |
isLoading() | boolean | Returns |
redraw() | this | Causes the layer to clear all the tiles and request them again. |
getEvents() | Record<string, Function> | Returns the map events the layer listens to, see |
getTileSize() | Point | Normalizes the tileSize option into a point. Used by
the |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Properties
| Property | Type | Description |
|---|---|---|
wmsParams | Record<string, any> | The parameters of the WMS requests, see |
Static members
| Property | Type | Description |
|---|---|---|
defaultWmsParams | Record<string, any> | The default WMS parameters, which the options override, see |
ImageOverlay extends Layer
Used to load and display a single image over specific bounds of the map. Extends Layer.
Usage example
const imageUrl = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',
imageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];
new ImageOverlay(imageUrl, imageBounds).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new ImageOverlay(url: string | HTMLImageElement, bounds: LatLngBoundsExpression, options?: ImageOverlayOptions) | Instantiates an image overlay object given the URL of the image (or an image element) and the geographical bounds it is tied to. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
opacity | number | 1 | The opacity of the image overlay. |
alt | string | '' | Text for the |
interactive | boolean | false | If |
crossOrigin | boolean|string | false | Whether the crossOrigin attribute will be added to the image. If a String is provided, the image will have its crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data. Refer to CORS Settings for valid String values. |
errorOverlayUrl | string | '' | URL to the overlay image to show in place of the overlay that failed to load. |
zIndex | number | 1 | The explicit zIndex of the overlay layer. |
className | string | '' | A custom class name to assign to the image. Empty by default. |
pixelated | boolean | false | Whether to scale the image with
nearest-neighbour interpolation ( |
decoding | string | 'auto' | Tells the browser whether to decode the image
in a synchronous fashion, as per the
|
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
| Event | Data | Description |
|---|---|---|
load | MaplairEvent | Fired when the ImageOverlay layer has loaded its image. |
error | MaplairEvent | Fired when the ImageOverlay layer fails to load its image. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | |
onRemove(map: MaplairMap) | void | |
setOpacity(opacity: number) | this | Sets the opacity of the overlay. |
setStyle(styleOpts: { opacity?: number; }) | this | Sets the opacity of the overlay from the given style options, e.g. by
|
bringToFront() | this | Brings the layer to the top of all overlays. |
bringToBack() | this | Brings the layer to the bottom of all overlays. |
setUrl(url: string) | this | Changes the URL of the image. |
setBounds(bounds: LatLngBoundsExpression) | this | Update the bounds that this ImageOverlay covers. |
getEvents() | Record<string, EventListener> | Returns the map events the overlay listens to. |
setZIndex(value: number) | this | Changes the zIndex of the image overlay. |
getBounds() | LatLngBounds | Get the bounds that this ImageOverlay covers. |
getElement() | HTMLElement | SVGElement | Returns the instance of
|
getCenter() | LatLng | Returns the center of the ImageOverlay. |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
VideoOverlay extends ImageOverlay
Used to load and display a video player over specific bounds of the map. Extends
ImageOverlay.
A video overlay uses the <video>
HTML element; getElement() returns the instance of
HTMLVideoElement
used by this overlay.
Usage example
const videoUrl = 'https://www.mapbox.com/bites/00188/patricia_nasa.webm',
videoBounds = [[ 32, -130], [ 13, -100]];
new VideoOverlay(videoUrl, videoBounds ).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new VideoOverlay(video: string | string[] | HTMLVideoElement, bounds: LatLngBoundsExpression, options?: VideoOverlayOptions | undefined) | Instantiates a video overlay object given the URL of the video (or array of URLs, or even a video element) and the geographical bounds it is tied to. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
autoplay | boolean | true | Whether the video starts playing automatically
when loaded. On some browsers autoplay will only work with |
controls | boolean | false | Whether the browser will offer controls to allow the user to control video playback, including volume, seeking, and pause/resume playback. |
loop | boolean | true | Whether the video will loop back to the beginning when played. |
keepAspectRatio | boolean | true | Whether the video will save aspect ratio after the projection. |
muted | boolean | false | Whether the video starts on mute when loaded. |
playsInline | boolean | true | Mobile browsers will play the video right where it is instead of open it up in fullscreen mode. |
Options inherited from ImageOverlay
| Option | Type | Default | Description |
|---|---|---|---|
opacity | number | 1 | The opacity of the image overlay. |
alt | string | '' | Text for the |
interactive | boolean | false | If |
crossOrigin | boolean|string | false | Whether the crossOrigin attribute will be added to the image. If a String is provided, the image will have its crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data. Refer to CORS Settings for valid String values. |
errorOverlayUrl | string | '' | URL to the overlay image to show in place of the overlay that failed to load. |
zIndex | number | 1 | The explicit zIndex of the overlay layer. |
className | string | '' | A custom class name to assign to the image. Empty by default. |
pixelated | boolean | false | Whether to scale the image with
nearest-neighbour interpolation ( |
decoding | string | 'auto' | Tells the browser whether to decode the image
in a synchronous fashion, as per the
|
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
| Event | Data | Description |
|---|---|---|
load | MaplairEvent | Fired when the video has finished loading the first frame. |
Events inherited from ImageOverlay
| Event | Data | Description |
|---|---|---|
load | MaplairEvent | Fired when the ImageOverlay layer has loaded its image. |
error | MaplairEvent | Fired when the ImageOverlay layer fails to load its image. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
Methods inherited from ImageOverlay
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | |
onRemove(map: MaplairMap) | void | |
setOpacity(opacity: number) | this | Sets the opacity of the overlay. |
setStyle(styleOpts: { opacity?: number; }) | this | Sets the opacity of the overlay from the given style options, e.g. by
|
bringToFront() | this | Brings the layer to the top of all overlays. |
bringToBack() | this | Brings the layer to the bottom of all overlays. |
setUrl(url: string) | this | Changes the URL of the image. |
setBounds(bounds: LatLngBoundsExpression) | this | Update the bounds that this ImageOverlay covers. |
getEvents() | Record<string, EventListener> | Returns the map events the overlay listens to. |
setZIndex(value: number) | this | Changes the zIndex of the image overlay. |
getBounds() | LatLngBounds | Get the bounds that this ImageOverlay covers. |
getElement() | HTMLElement | SVGElement | Returns the instance of
|
getCenter() | LatLng | Returns the center of the ImageOverlay. |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
SVGOverlay extends ImageOverlay
Used to load, display and provide DOM access to an SVG file over specific bounds of
the map. Extends ImageOverlay.
An SVG overlay uses the <svg>
element; getElement() returns the instance of
SVGElement used by this
overlay.
Usage example
const svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svgElement.setAttribute('xmlns', "http://www.w3.org/2000/svg");
svgElement.setAttribute('viewBox', "0 0 200 200");
svgElement.innerHTML = '<rect width="200" height="200"/><rect x="75" y="23" width="50" height="50" style="fill:red"/><rect x="75" y="123" width="50" height="50" style="fill:#0013ff"/>';
const svgElementBounds = [ [ 32, -130 ], [ 13, -100 ] ];
new SVGOverlay(svgElement, svgElementBounds).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new SVGOverlay(svg: SVGElement, bounds: LatLngBoundsExpression, options?: ImageOverlayOptions | undefined) | Instantiates an image overlay object given an SVG element and the geographical bounds it is tied to. A viewBox attribute is required on the SVG element to zoom in and out properly. |
Events
Events inherited from ImageOverlay
| Event | Data | Description |
|---|---|---|
load | MaplairEvent | Fired when the ImageOverlay layer has loaded its image. |
error | MaplairEvent | Fired when the ImageOverlay layer fails to load its image. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
Methods inherited from ImageOverlay
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | |
onRemove(map: MaplairMap) | void | |
setOpacity(opacity: number) | this | Sets the opacity of the overlay. |
setStyle(styleOpts: { opacity?: number; }) | this | Sets the opacity of the overlay from the given style options, e.g. by
|
bringToFront() | this | Brings the layer to the top of all overlays. |
bringToBack() | this | Brings the layer to the bottom of all overlays. |
setUrl(url: string) | this | Changes the URL of the image. |
setBounds(bounds: LatLngBoundsExpression) | this | Update the bounds that this ImageOverlay covers. |
getEvents() | Record<string, EventListener> | Returns the map events the overlay listens to. |
setZIndex(value: number) | this | Changes the zIndex of the image overlay. |
getBounds() | LatLngBounds | Get the bounds that this ImageOverlay covers. |
getElement() | HTMLElement | SVGElement | Returns the instance of
|
getCenter() | LatLng | Returns the center of the ImageOverlay. |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
HeatLayer extends BlanketOverlay
A heatmap of points, each with an optional intensity, drawn on a canvas: the points are drawn as blurred circles adding up, and colored by a gradient. Nearby points are merged into a grid for speed, so that tens of thousands of points stay fast.
Inspired by the Leaflet.heat plugin and its simpleheat algorithm.
Usage example
new HeatLayer([
[47.27, 11.40, 0.5], // latitude, longitude, intensity
[47.28, 11.41],
new LatLng(47.26, 11.39)
], {radius: 20}).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new HeatLayer(latlngs?: LatLngExpression[], options?: HeatLayerOptions) | Creates a heatmap of the given points: |
Options
| Option | Type | Default | Description |
|---|---|---|---|
radius | number | 25 | The radius of each point in pixels. |
blur | number | 15 | The amount of blur in pixels. |
max | number | 1 | The intensity with the strongest color. |
maxZoom | number | The zoom level where the points reach the full intensity; below it, the intensity is halved per zoom level. By default the maximum zoom of the map. | |
minOpacity | number | 0.05 | The minimum opacity of the heat. |
gradient | Record<number, string> | {0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'} | The colors for the intensities from |
pane | string | 'overlayPane' | The map pane of the layer. |
Options inherited from BlanketOverlay
| Option | Type | Default | Description |
|---|---|---|---|
padding | number | 0.1 | How much to extend the clip area around the map view (relative to its size) e.g. 0.1 would be 10% of map view in each direction. |
continuous | boolean | false | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
setLatLngs(latlngs: LatLngExpression[]) | this | Replaces the points of the heatmap. |
addLatLng(latlng: LatLngExpression) | this | Adds a point to the heatmap. |
getLatLngs() | LatLngExpression[] | Returns the points of the heatmap. |
setOptions(options: HeatLayerOptions) | this | Changes the options, e.g. the |
redraw() | this | Redraws the heatmap. |
Methods inherited from BlanketOverlay
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | |
onRemove(map: MaplairMap) | void | |
getEvents() | Record<string, EventListener> | Returns the map events the blanket listens to. |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Path extends Layer
An abstract class that contains options and methods shared between vector overlays
(Polyline, Polygon, Rectangle, Circle, CircleMarker). Do not use it
directly. Extends Layer.
Options
| Option | Type | Default | Description |
|---|---|---|---|
stroke | boolean | true | Whether to draw stroke along the path. Set it to
|
color | string | '#3388ff' | Stroke color. |
weight | number | 3 | Stroke width in pixels. |
opacity | number | 1 | Stroke opacity. |
lineCap | string | 'round' | A string that defines shape to be used at the end of the stroke. |
lineJoin | string | 'round' | A string that defines shape to be used at the corners of the stroke. |
dashArray | string|null | null | A string that defines the stroke dash pattern. |
dashOffset | string|null | null | A string that defines the distance into the dash pattern to start the dash. |
fill | boolean | false | Whether to fill the path with color. Set it to
|
fillColor | string|null | null | Fill color. Defaults to the value of the
|
fillOpacity | number | 0.2 | Fill opacity. |
fillRule | string | 'evenodd' | A string that defines how the inside of a shape is determined. |
className | string | Custom class name set on an element. Only for SVG renderer.
Applied when the element is created; | |
renderer | Renderer | Use this specific instance of | |
dashSpeed | number | 0 | Animates the dashes of the Added by the optional module |
arrowheads | boolean|{size?: number, repeat?: number, color?: string} | false | Arrowheads along a polyline: Added by the optional module |
text | string|{content: string, repeat?: boolean, center?: boolean, offset?: number, fontSize?: number, color?: string}|null | null | Text along a polyline, e.g. a street name: the text, or an object with the
Added by the optional module |
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
beforeAdd(map: MaplairMap) | void | Gets the renderer of the path from the map, before it is added. |
onAdd() | void | Adds the path to its renderer. |
onRemove() | void | Removes the path from its renderer. |
redraw() | this | Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(style: PathOptions) | this | Changes the appearance of a Path based on the options in the |
bringToFront() | this | Brings the layer to the top of all path layers. |
bringToBack() | this | Brings the layer to the bottom of all path layers. |
getElement() | SVGPathElement | undefined | Returns the SVG |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getEvents() | Record<string, Function> | Should return an object
like |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Polyline extends Path
A class for drawing polyline overlays on a map. Extends Path.
Usage example
// create a red polyline from an array of LatLng points
const latlngs = [
[45.51, -122.68],
[37.77, -122.43],
[34.04, -118.2]
];
const polyline = new Polyline(latlngs, {color: 'red'}).addTo(map);
// zoom the map to the polyline
map.fitBounds(polyline.getBounds());
You can also pass a multi-dimensional array to represent a MultiPolyline shape:
// create a red polyline from an array of arrays of LatLng points
const latlngs = [
[[45.51, -122.68],
[37.77, -122.43],
[34.04, -118.2]],
[[40.78, -73.91],
[41.83, -87.62],
[32.76, -96.72]]
];
Constructor
| Constructor | Description |
|---|---|
new Polyline(latlngs: LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][], options?: PolylineOptions) | Instantiates a polyline object given an array of geographical points and
optionally an options object. You can create a |
Options
| Option | Type | Default | Description |
|---|---|---|---|
smoothFactor | number | 0.5 | How much to simplify the polyline on each zoom level (Douglas–Peucker epsilon, in pixels). Higher values mean faster rendering but less accuracy; lower values mean more accuracy but slower rendering. |
noClip | boolean | false | Disable polyline clipping. |
Options inherited from Path
| Option | Type | Default | Description |
|---|---|---|---|
stroke | boolean | true | Whether to draw stroke along the path. Set it to
|
color | string | '#3388ff' | Stroke color. |
weight | number | 3 | Stroke width in pixels. |
opacity | number | 1 | Stroke opacity. |
lineCap | string | 'round' | A string that defines shape to be used at the end of the stroke. |
lineJoin | string | 'round' | A string that defines shape to be used at the corners of the stroke. |
dashArray | string|null | null | A string that defines the stroke dash pattern. |
dashOffset | string|null | null | A string that defines the distance into the dash pattern to start the dash. |
fill | boolean | false | Whether to fill the path with color. Set it to
|
fillColor | string|null | null | Fill color. Defaults to the value of the
|
fillOpacity | number | 0.2 | Fill opacity. |
fillRule | string | 'evenodd' | A string that defines how the inside of a shape is determined. |
className | string | Custom class name set on an element. Only for SVG renderer.
Applied when the element is created; | |
renderer | Renderer | Use this specific instance of | |
dashSpeed | number | 0 | Animates the dashes of the Added by the optional module |
arrowheads | boolean|{size?: number, repeat?: number, color?: string} | false | Arrowheads along a polyline: Added by the optional module |
text | string|{content: string, repeat?: boolean, center?: boolean, offset?: number, fontSize?: number, color?: string}|null | null | Text along a polyline, e.g. a street name: the text, or an object with the
Added by the optional module |
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
getLatLngs() | LatLng[] | LatLng[][] | LatLng[][][] | Returns an array of the points in the path, or nested arrays of points in case of multi-polyline. |
setLatLngs(latlngs: LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][]) | this | Replaces all the points in the polyline with the given array of geographical points. |
isEmpty() | boolean | Returns |
closestLayerPoint(p: PointExpression) | (Point & { distance: number; }) | null | Returns the point closest to |
getCenter() | LatLng | Returns the center (centroid) of the polyline. |
getBounds() | LatLngBounds | Returns the |
addLatLng(latlng: LatLngExpression, latlngs?: LatLng[]) | this | Adds a given point to the polyline. By default, adds to the first ring of
the polyline in case of a multi-polyline, but can be overridden by passing
a specific ring as a LatLng array (that you can earlier access with
|
toGeoJSON(precision?: number | false) | Feature | Coordinates values are rounded with |
Methods inherited from Path
| Method | Returns | Description |
|---|---|---|
beforeAdd(map: MaplairMap) | void | Gets the renderer of the path from the map, before it is added. |
onAdd() | void | Adds the path to its renderer. |
onRemove() | void | Removes the path from its renderer. |
redraw() | this | Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(style: PathOptions) | this | Changes the appearance of a Path based on the options in the |
bringToFront() | this | Brings the layer to the top of all path layers. |
bringToBack() | this | Brings the layer to the bottom of all path layers. |
getElement() | SVGPathElement | undefined | Returns the SVG |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getEvents() | Record<string, Function> | Should return an object
like |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Polygon extends Polyline
A class for drawing polygon overlays on a map. Extends Polyline.
Note that points you pass when creating a polygon shouldn't have an additional last point equal to the first one — it's better to filter out such points.
Usage example
// create a red polygon from an array of LatLng points
const latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]];
const polygon = new Polygon(latlngs, {color: 'red'}).addTo(map);
// zoom the map to the polygon
map.fitBounds(polygon.getBounds());
You can also pass an array of arrays of latlngs, with the first array representing the outer shape and the other arrays representing holes in the outer shape:
const latlngs = [
[[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring
[[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole
];
Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.
const latlngs = [
[ // first polygon
[[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring
[[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole
],
[ // second polygon
[[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]
]
];
Constructor
| Constructor | Description |
|---|---|
new Polygon(latlngs: LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][], options?: PolygonOptions | undefined) | Instantiates a polygon object given an array of geographical points (or arrays of them for holes and multi-polygons) and optionally an options object. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
fill | boolean | true | Whether to fill the polygon with color. |
Options inherited from Polyline
| Option | Type | Default | Description |
|---|---|---|---|
smoothFactor | number | 0.5 | How much to simplify the polyline on each zoom level (Douglas–Peucker epsilon, in pixels). Higher values mean faster rendering but less accuracy; lower values mean more accuracy but slower rendering. |
noClip | boolean | false | Disable polyline clipping. |
Options inherited from Path
| Option | Type | Default | Description |
|---|---|---|---|
stroke | boolean | true | Whether to draw stroke along the path. Set it to
|
color | string | '#3388ff' | Stroke color. |
weight | number | 3 | Stroke width in pixels. |
opacity | number | 1 | Stroke opacity. |
lineCap | string | 'round' | A string that defines shape to be used at the end of the stroke. |
lineJoin | string | 'round' | A string that defines shape to be used at the corners of the stroke. |
dashArray | string|null | null | A string that defines the stroke dash pattern. |
dashOffset | string|null | null | A string that defines the distance into the dash pattern to start the dash. |
fill | boolean | false | Whether to fill the path with color. Set it to
|
fillColor | string|null | null | Fill color. Defaults to the value of the
|
fillOpacity | number | 0.2 | Fill opacity. |
fillRule | string | 'evenodd' | A string that defines how the inside of a shape is determined. |
className | string | Custom class name set on an element. Only for SVG renderer.
Applied when the element is created; | |
renderer | Renderer | Use this specific instance of | |
dashSpeed | number | 0 | Animates the dashes of the Added by the optional module |
arrowheads | boolean|{size?: number, repeat?: number, color?: string} | false | Arrowheads along a polyline: Added by the optional module |
text | string|{content: string, repeat?: boolean, center?: boolean, offset?: number, fontSize?: number, color?: string}|null | null | Text along a polyline, e.g. a street name: the text, or an object with the
Added by the optional module |
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
Methods inherited from Polyline
| Method | Returns | Description |
|---|---|---|
getLatLngs() | LatLng[] | LatLng[][] | LatLng[][][] | Returns an array of the points in the path, or nested arrays of points in case of multi-polyline. |
setLatLngs(latlngs: LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][]) | this | Replaces all the points in the polyline with the given array of geographical points. |
isEmpty() | boolean | Returns |
closestLayerPoint(p: PointExpression) | (Point & { distance: number; }) | null | Returns the point closest to |
getCenter() | LatLng | Returns the center (centroid) of the polyline. |
getBounds() | LatLngBounds | Returns the |
addLatLng(latlng: LatLngExpression, latlngs?: LatLng[]) | this | Adds a given point to the polyline. By default, adds to the first ring of
the polyline in case of a multi-polyline, but can be overridden by passing
a specific ring as a LatLng array (that you can earlier access with
|
toGeoJSON(precision?: number | false) | Feature | Coordinates values are rounded with |
Methods inherited from Path
| Method | Returns | Description |
|---|---|---|
beforeAdd(map: MaplairMap) | void | Gets the renderer of the path from the map, before it is added. |
onAdd() | void | Adds the path to its renderer. |
onRemove() | void | Removes the path from its renderer. |
redraw() | this | Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(style: PathOptions) | this | Changes the appearance of a Path based on the options in the |
bringToFront() | this | Brings the layer to the top of all path layers. |
bringToBack() | this | Brings the layer to the bottom of all path layers. |
getElement() | SVGPathElement | undefined | Returns the SVG |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getEvents() | Record<string, Function> | Should return an object
like |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Rectangle extends Polygon
A class for drawing rectangle overlays on a map. Extends Polygon.
Usage example
// define rectangle geographical bounds
const bounds = [[54.559322, -5.767822], [56.1210604, -3.021240]];
// create an orange rectangle
new Rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map);
// zoom the map to the rectangle bounds
map.fitBounds(bounds);
Constructor
| Constructor | Description |
|---|---|
new Rectangle(latLngBounds: LatLngBoundsExpression, options?: PolygonOptions) | Instantiates a rectangle object given the geographical bounds, and an optional options object. |
Events
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
setBounds(latLngBounds: LatLngBoundsExpression) | this | Redraws the rectangle with the passed bounds. |
Methods inherited from Polyline
| Method | Returns | Description |
|---|---|---|
getLatLngs() | LatLng[] | LatLng[][] | LatLng[][][] | Returns an array of the points in the path, or nested arrays of points in case of multi-polyline. |
setLatLngs(latlngs: LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][]) | this | Replaces all the points in the polyline with the given array of geographical points. |
isEmpty() | boolean | Returns |
closestLayerPoint(p: PointExpression) | (Point & { distance: number; }) | null | Returns the point closest to |
getCenter() | LatLng | Returns the center (centroid) of the polyline. |
getBounds() | LatLngBounds | Returns the |
addLatLng(latlng: LatLngExpression, latlngs?: LatLng[]) | this | Adds a given point to the polyline. By default, adds to the first ring of
the polyline in case of a multi-polyline, but can be overridden by passing
a specific ring as a LatLng array (that you can earlier access with
|
toGeoJSON(precision?: number | false) | Feature | Coordinates values are rounded with |
Methods inherited from Path
| Method | Returns | Description |
|---|---|---|
beforeAdd(map: MaplairMap) | void | Gets the renderer of the path from the map, before it is added. |
onAdd() | void | Adds the path to its renderer. |
onRemove() | void | Removes the path from its renderer. |
redraw() | this | Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(style: PathOptions) | this | Changes the appearance of a Path based on the options in the |
bringToFront() | this | Brings the layer to the top of all path layers. |
bringToBack() | this | Brings the layer to the bottom of all path layers. |
getElement() | SVGPathElement | undefined | Returns the SVG |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getEvents() | Record<string, Function> | Should return an object
like |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Circle extends CircleMarker
A class for drawing circle overlays on a map with radius specified in meters.
Extends CircleMarker, its setRadius() and getRadius() use meters.
It's an approximation and starts to diverge from a real circle closer to poles (due to projection distortion).
Usage example
new Circle([50.5, 30.5], {radius: 200}).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new Circle(latlng: LatLngExpression, options?: CircleOptions) | Instantiates a circle object given a geographical point, and an options object which contains the circle radius. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
radius | number | Radius of the circle, in meters. |
Options inherited from CircleMarker
| Option | Type | Default | Description |
|---|---|---|---|
fill | boolean | true | Whether to fill the circle with color. |
radius | number | 10 | Radius of the circle marker, in CSS pixels. |
displace | boolean | Whether to include this marker in the displacement of
the map, see | |
displaceId | string | Stable identifier shared across marker instances that
represent the same thing on different layers, so that |
Options inherited from Path
| Option | Type | Default | Description |
|---|---|---|---|
stroke | boolean | true | Whether to draw stroke along the path. Set it to
|
color | string | '#3388ff' | Stroke color. |
weight | number | 3 | Stroke width in pixels. |
opacity | number | 1 | Stroke opacity. |
lineCap | string | 'round' | A string that defines shape to be used at the end of the stroke. |
lineJoin | string | 'round' | A string that defines shape to be used at the corners of the stroke. |
dashArray | string|null | null | A string that defines the stroke dash pattern. |
dashOffset | string|null | null | A string that defines the distance into the dash pattern to start the dash. |
fill | boolean | false | Whether to fill the path with color. Set it to
|
fillColor | string|null | null | Fill color. Defaults to the value of the
|
fillOpacity | number | 0.2 | Fill opacity. |
fillRule | string | 'evenodd' | A string that defines how the inside of a shape is determined. |
className | string | Custom class name set on an element. Only for SVG renderer.
Applied when the element is created; | |
renderer | Renderer | Use this specific instance of | |
dashSpeed | number | 0 | Animates the dashes of the Added by the optional module |
arrowheads | boolean|{size?: number, repeat?: number, color?: string} | false | Arrowheads along a polyline: Added by the optional module |
text | string|{content: string, repeat?: boolean, center?: boolean, offset?: number, fontSize?: number, color?: string}|null | null | Text along a polyline, e.g. a street name: the text, or an object with the
Added by the optional module |
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
Events inherited from CircleMarker
| Event | Data | Description |
|---|---|---|
move | CircleMarkerMoveEvent | Fired when the marker is moved via setLatLng. Old and new coordinates are included in event arguments as oldLatLng, latlng. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
getBounds() | LatLngBounds | Returns the |
Methods inherited from CircleMarker
| Method | Returns | Description |
|---|---|---|
setLatLng(latlng: LatLngExpression) | this | Sets the position of a circle marker to a new location. |
getLatLng() | LatLng | Returns the current geographical position of the circle marker. |
setRadius(radius: number) | this | Sets the radius of a circle marker. Units are in CSS pixels. |
getRadius() | number | Returns the current radius of the circle. Units are in CSS pixels. |
setStyle(options: CircleMarkerOptions) | this | Changes the appearance of the circle marker, also its |
toGeoJSON(precision?: number | false) | Feature | Coordinates values are rounded with |
Methods inherited from Path
| Method | Returns | Description |
|---|---|---|
beforeAdd(map: MaplairMap) | void | Gets the renderer of the path from the map, before it is added. |
onAdd() | void | Adds the path to its renderer. |
onRemove() | void | Removes the path from its renderer. |
redraw() | this | Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
bringToFront() | this | Brings the layer to the top of all path layers. |
bringToBack() | this | Brings the layer to the bottom of all path layers. |
getElement() | SVGPathElement | undefined | Returns the SVG |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getEvents() | Record<string, Function> | Should return an object
like |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
CircleMarker extends Path
A circle of a fixed size with radius specified in CSS pixels. Extends Path.
Constructor
| Constructor | Description |
|---|---|
new CircleMarker(latlng: LatLngExpression, options?: CircleMarkerOptions) | Instantiates a circle marker object given a geographical point, and an optional options object. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
fill | boolean | true | Whether to fill the circle with color. |
radius | number | 10 | Radius of the circle marker, in CSS pixels. |
displace | boolean | Whether to include this marker in the displacement of
the map, see | |
displaceId | string | Stable identifier shared across marker instances that
represent the same thing on different layers, so that |
Options inherited from Path
| Option | Type | Default | Description |
|---|---|---|---|
stroke | boolean | true | Whether to draw stroke along the path. Set it to
|
color | string | '#3388ff' | Stroke color. |
weight | number | 3 | Stroke width in pixels. |
opacity | number | 1 | Stroke opacity. |
lineCap | string | 'round' | A string that defines shape to be used at the end of the stroke. |
lineJoin | string | 'round' | A string that defines shape to be used at the corners of the stroke. |
dashArray | string|null | null | A string that defines the stroke dash pattern. |
dashOffset | string|null | null | A string that defines the distance into the dash pattern to start the dash. |
fill | boolean | false | Whether to fill the path with color. Set it to
|
fillColor | string|null | null | Fill color. Defaults to the value of the
|
fillOpacity | number | 0.2 | Fill opacity. |
fillRule | string | 'evenodd' | A string that defines how the inside of a shape is determined. |
className | string | Custom class name set on an element. Only for SVG renderer.
Applied when the element is created; | |
renderer | Renderer | Use this specific instance of | |
dashSpeed | number | 0 | Animates the dashes of the Added by the optional module |
arrowheads | boolean|{size?: number, repeat?: number, color?: string} | false | Arrowheads along a polyline: Added by the optional module |
text | string|{content: string, repeat?: boolean, center?: boolean, offset?: number, fontSize?: number, color?: string}|null | null | Text along a polyline, e.g. a street name: the text, or an object with the
Added by the optional module |
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
| Event | Data | Description |
|---|---|---|
move | CircleMarkerMoveEvent | Fired when the marker is moved via setLatLng. Old and new coordinates are included in event arguments as oldLatLng, latlng. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
setLatLng(latlng: LatLngExpression) | this | Sets the position of a circle marker to a new location. |
getLatLng() | LatLng | Returns the current geographical position of the circle marker. |
setRadius(radius: number) | this | Sets the radius of a circle marker. Units are in CSS pixels. |
getRadius() | number | Returns the current radius of the circle. Units are in CSS pixels. |
setStyle(options: CircleMarkerOptions) | this | Changes the appearance of the circle marker, also its |
toGeoJSON(precision?: number | false) | Feature | Coordinates values are rounded with |
Methods inherited from Path
| Method | Returns | Description |
|---|---|---|
beforeAdd(map: MaplairMap) | void | Gets the renderer of the path from the map, before it is added. |
onAdd() | void | Adds the path to its renderer. |
onRemove() | void | Removes the path from its renderer. |
redraw() | this | Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
bringToFront() | this | Brings the layer to the top of all path layers. |
bringToBack() | this | Brings the layer to the bottom of all path layers. |
getElement() | SVGPathElement | undefined | Returns the SVG |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getEvents() | Record<string, Function> | Should return an object
like |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
SVG extends Renderer
Allows vector layers to be displayed with SVG.
Inherits Renderer.
Usage example
Use SVG by default for all paths in the map:
const map = new MaplairMap('map', {
renderer: new SVG()
});
Use a SVG renderer with extra padding for specific vector geometries:
const map = new MaplairMap('map');
const myRenderer = new SVG({ padding: 0.5 });
const line = new Polyline( coordinates, { renderer: myRenderer } );
const circle = new Circle( center, { renderer: myRenderer, radius: 100 } );
Events
Events inherited from Renderer
| Event | Data | Description |
|---|---|---|
update | MaplairEvent | Fired when the renderer updates its bounds, center and zoom, for example when its map has moved. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
Methods inherited from Renderer
| Method | Returns | Description |
|---|---|---|
onRemove() | void | Removes the container of the renderer from the map. |
Methods inherited from BlanketOverlay
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | |
getEvents() | Record<string, EventListener> | Returns the map events the blanket listens to. |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Static members
| Method | Returns | Description |
|---|---|---|
create(name: string) | SVGElement | Returns a instance of SVGElement, corresponding to the class name passed. For example, using 'line' will return an instance of SVGLineElement. |
pointsToPath(rings: Point[][], closed?: boolean) | string | Generates a SVG path string for multiple rings, with each ring turning into "M..L..L.." instructions. |
Canvas extends Renderer
Allows vector layers to be displayed with <canvas>.
Inherits Renderer.
Usage example
Use Canvas by default for all paths in the map:
const map = new MaplairMap('map', {
renderer: new Canvas()
});
Use a Canvas renderer with extra padding for specific vector geometries:
const map = new MaplairMap('map');
const myRenderer = new Canvas({ padding: 0.5 });
const line = new Polyline( coordinates, { renderer: myRenderer } );
const circle = new Circle( center, { renderer: myRenderer, radius: 100 } );
Constructor
| Constructor | Description |
|---|---|
new Canvas(options?: CanvasOptions | undefined) | Creates a Canvas renderer with the given options. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
tolerance | number | 0 | How much to extend the click tolerance around a path/object on the map. |
Options inherited from BlanketOverlay
| Option | Type | Default | Description |
|---|---|---|---|
padding | number | 0.1 | How much to extend the clip area around the map view (relative to its size) e.g. 0.1 would be 10% of map view in each direction. |
continuous | boolean | false | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
Events inherited from Renderer
| Event | Data | Description |
|---|---|---|
update | MaplairEvent | Fired when the renderer updates its bounds, center and zoom, for example when its map has moved. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
Methods inherited from Renderer
| Method | Returns | Description |
|---|---|---|
onRemove() | void | Removes the container of the renderer from the map. |
Methods inherited from BlanketOverlay
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | |
getEvents() | Record<string, EventListener> | Returns the map events the blanket listens to. |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
LayerGroup extends Layer
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. Extends Layer.
Usage example
new LayerGroup([marker1, marker2])
.addLayer(polyline)
.addTo(map);
Constructor
| Constructor | Description |
|---|---|
new LayerGroup(layers?: Layer[], options?: InteractiveLayerOptions) | Creates a layer group, optionally given an initial set of layers and an
|
Events
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
addLayer(layer: Layer) | this | Adds the given layer to the group. |
removeLayer(layer: Layer | number) | this | Removes the given layer, or the layer with the given internal ID, from the group. |
hasLayer(layer: Layer | number) | boolean | Returns |
clearLayers() | this | Removes all the layers from the group. |
onAdd(map: MaplairMap) | void | Adds the layers of the group to the map. |
onRemove(map: MaplairMap) | void | Removes the layers of the group from the map. |
eachLayer(method: (layer: Layer) => void, context?: object) | this | Iterates over the layers of the group, optionally specifying context of the iterator function.
|
getLayer(id: number) | Layer | undefined | Returns the layer with the given internal ID. |
getLayers() | Layer[] | Returns an array of all the layers added to the group. |
setZIndex(zIndex: number) | this | Calls |
getLayerId(layer: Layer) | number | Returns the internal ID for a layer. |
toGeoJSON(precision?: number | false) | Feature | FeatureCollection | Coordinates values are rounded with |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getEvents() | Record<string, Function> | Should return an object
like |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
FeatureGroup extends LayerGroup
Extended LayerGroup that makes it easier to do the same thing to all its member layers:
bindPopupbinds a popup to all of the layers at once (likewise withbindTooltip)- Events are propagated to the
FeatureGroup, so if the group has an event handler, it will handle events from any of the layers. This includes pointer events and custom events. - Has
layeraddandlayerremoveevents
Usage example
new FeatureGroup([marker1, marker2, polyline])
.bindPopup('Hello world!')
.on('click', function() { alert('Clicked on a member of the group!'); })
.addTo(map);
Events
| Event | Data | Description |
|---|---|---|
layeradd | LayerEvent | Fired when a layer is added to this FeatureGroup. |
layerremove | LayerEvent | Fired when a layer is removed from this FeatureGroup. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
addLayer(layer: Layer) | this | Adds the given layer to the group. |
removeLayer(layer: Layer | number) | this | Removes the given layer, or the layer with the given internal ID, from the group. |
setStyle(style: PathOptions) | this | Sets the given path options to each layer of the group that has a |
setInteractive(interactive: boolean) | this | Changes the |
bringToFront() | this | Brings the layer group to the top of all other layers. |
bringToBack() | this | Brings the layer group to the back of all other layers. |
getBounds() | LatLngBounds | Returns the |
Methods inherited from LayerGroup
| Method | Returns | Description |
|---|---|---|
hasLayer(layer: Layer | number) | boolean | Returns |
clearLayers() | this | Removes all the layers from the group. |
onAdd(map: MaplairMap) | void | Adds the layers of the group to the map. |
onRemove(map: MaplairMap) | void | Removes the layers of the group from the map. |
eachLayer(method: (layer: Layer) => void, context?: object) | this | Iterates over the layers of the group, optionally specifying context of the iterator function.
|
getLayer(id: number) | Layer | undefined | Returns the layer with the given internal ID. |
getLayers() | Layer[] | Returns an array of all the layers added to the group. |
setZIndex(zIndex: number) | this | Calls |
getLayerId(layer: Layer) | number | Returns the internal ID for a layer. |
toGeoJSON(precision?: number | false) | Feature | FeatureCollection | Coordinates values are rounded with |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getEvents() | Record<string, Function> | Should return an object
like |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
GeoJSON extends FeatureGroup
Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse
GeoJSON data and display it on the map. Extends FeatureGroup.
There are several static functions which can be called without instantiating
GeoJSON.
Usage example
new GeoJSON(data, {
style: function (feature) {
return {color: feature.properties.color};
}
}).bindPopup(function (layer) {
return layer.feature.properties.description;
}).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new GeoJSON(geojson?: GeoJSONData | GeoJSONData[] | null, options?: GeoJSONOptions) | Creates a GeoJSON layer. Optionally accepts an object in
GeoJSON format to display on the map
(you can alternatively add it later with |
Options
| Option | Type | Default | Description |
|---|---|---|---|
pointToLayer | (geoJsonPoint: Feature, latlng: LatLng) => Layer | A
| |
style | PathOptions|((geoJsonFeature: Feature) => PathOptions) | A
| |
onEachFeature | (feature: Feature, layer: Layer) => void | A
| |
filter | (geoJsonFeature: Feature) => boolean | A
Note: dynamically changing the | |
coordsToLatLng | (coords: number[]) => LatLng | A | |
markersInheritOptions | boolean | false | Whether default Markers for "Point" type Features inherit from group options. |
url | string | undefined | A URL to load the GeoJSON data from when creating the layer. Added by the optional module |
fetchOptions | RequestInit | undefined | Options for
Added by the optional module |
fitBounds | boolean | false | Whether to fit the map to the bounds of the data once loaded. Added by the optional module |
Options inherited from InteractiveLayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
| Event | Data | Description |
|---|---|---|
loading | MaplairEvent | Fired when starting to load data with load(). (maplair/geojson-loading) |
load | GeoJSONLoadEvent | Fired when the data of load() has been added, with the data. (maplair/geojson-loading) |
error | GeoJSONLoadErrorEvent | Fired when load() fails, with the error. (maplair/geojson-loading) |
Events inherited from FeatureGroup
| Event | Data | Description |
|---|---|---|
layeradd | LayerEvent | Fired when a layer is added to this FeatureGroup. |
layerremove | LayerEvent | Fired when a layer is removed from this FeatureGroup. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
Loading GeoJSON
| Method | Returns | Description |
|---|---|---|
load(source: string | Promise<GeoJsonObject | GeoJsonObject[]>, fetchOptions?: RequestInit) | Promise<this> | Loads GeoJSON data from a URL (or a promise of the data) and replaces the layers with it. A running load is aborted. Returns a promise of this layer.
Added by the optional module |
Other methods
| Method | Returns | Description |
|---|---|---|
addData(geojson: GeoJSONData | GeoJSONData[]) | this | Adds a GeoJSON object to the layer. |
resetStyle(layer?: Layer) | this | Resets the given vector layer's style to the original GeoJSON style, useful for
resetting style after hover events. If |
setStyle(style: PathOptions | ((geoJsonFeature: Feature) => PathOptions)) | this | Changes styles of GeoJSON vector layers with the given style function. |
Methods inherited from FeatureGroup
| Method | Returns | Description |
|---|---|---|
addLayer(layer: Layer) | this | Adds the given layer to the group. |
removeLayer(layer: Layer | number) | this | Removes the given layer, or the layer with the given internal ID, from the group. |
setInteractive(interactive: boolean) | this | Changes the |
bringToFront() | this | Brings the layer group to the top of all other layers. |
bringToBack() | this | Brings the layer group to the back of all other layers. |
getBounds() | LatLngBounds | Returns the |
Methods inherited from LayerGroup
| Method | Returns | Description |
|---|---|---|
hasLayer(layer: Layer | number) | boolean | Returns |
clearLayers() | this | Removes all the layers from the group. |
onAdd(map: MaplairMap) | void | Adds the layers of the group to the map. |
onRemove(map: MaplairMap) | void | Removes the layers of the group from the map. |
eachLayer(method: (layer: Layer) => void, context?: object) | this | Iterates over the layers of the group, optionally specifying context of the iterator function.
|
getLayer(id: number) | Layer | undefined | Returns the layer with the given internal ID. |
getLayers() | Layer[] | Returns an array of all the layers added to the group. |
setZIndex(zIndex: number) | this | Calls |
getLayerId(layer: Layer) | number | Returns the internal ID for a layer. |
toGeoJSON(precision?: number | false) | Feature | FeatureCollection | Coordinates values are rounded with |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getEvents() | Record<string, Function> | Should return an object
like |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Static members
| Method | Returns | Description |
|---|---|---|
geometryToLayer(geojson: GeoJsonObject, options?: GeoJSONOptions) | Layer | null | Creates a |
coordsToLatLng(coords: number[]) | LatLng | Creates a |
coordsToLatLngs(coords: any[], levelsDeep?: number, _coordsToLatLng?: (coords: number[]) => LatLng) | any[] | Creates a multidimensional array of |
latLngToCoords(latlng: LatLngExpression, precision?: number | false) | number[] | Reverse of |
latLngsToCoords(latlngs: any[], levelsDeep?: number, close?: boolean, precision?: number | false) | any[] | Reverse of |
getFeature(layer: Layer, newGeometry: Geometry) | Feature | Returns GeoJSON geometries/features of layer with new GeoJSON geometry. |
asFeature(geojson: GeoJsonObject) | Feature | FeatureCollection | Normalize GeoJSON geometries/features into GeoJSON features. |
Classification
Classifies features
by the value of an attribute, for thematic maps: each class
has a symbol (path options such as fillColor) and a legend label. A class is
either given by value ({value: 'S2'}, or several values sharing one class
{value: ['S1', 'S2']}) or by range ({lower: 0, upper: 10} for
0 ≤ value < 10, either bound left out for an open end); both kinds may be
mixed in one classification. A feature is classified by its exact value first,
then by range, then by legend label, else it falls into the
otherValues class.
Use style as style option of GeoJSON to style
the features by their class, and
LegendControl.addClassification() to
show the classes in a legend, with the feature count per class.
Usage example
const temperature = new Classification([
{value: null, symbol: {fillColor: '#000000'}, legend: 'No data', counted: false},
{upper: 0, symbol: {fillColor: '#5bc0de'}, legend: '< 0 °C'},
{lower: 0, upper: 10, symbol: {fillColor: '#33ee33'}, legend: '0–10 °C'},
{lower: 10, symbol: {fillColor: '#f0a030'}, legend: '≥ 10 °C'}
], {name: 'Air temperature', value: 'temperature'});
const stations = new GeoJSON(data, {
pointToLayer: (feature, latlng) => new CircleMarker(latlng, {color: '#ffffff'}),
style: temperature.style
}).addTo(map);
temperature.classify(data.features[0]).legend; // e.g. '0–10 °C'
Inspired by the categorized and graduated renderers of QGIS.
Constructor
| Constructor | Description |
|---|---|
new Classification(classes: ClassificationClass[], options?: ClassificationOptions) | Creates a classification from the given classes. Each class is an object with
|
Options
| Option | Type | Default | Description |
|---|---|---|---|
name | string | '' | The name of the classification, shown as title of its legend. |
value | string|((feature: any) => any) | The value to classify by: the
name of a property of the feature, or a function receiving the feature and
returning the value. Without it, the argument of | |
normalize | (value: any) => any | A function applied to the values of the
classes and of the features before comparing them, for tolerant matching, e.g.
| |
otherValues | ClassificationClass | The class of all values not matching
any other class, with |
Methods
| Method | Returns | Description |
|---|---|---|
style(feature: any) | PathOptions | Returns the symbol of the class of the feature (an empty object for features
without class), bound to the classification for the
|
classify(feature: any) | ClassificationClass | undefined | Returns the class of the given GeoJSON feature, of a layer with a
|
legendItems() | ClassificationLegendItem[] | Returns the items of the legend, |
featureCount(features: any[]) | ClassificationFeatureCount[] | Counts the given features (or layers with a
|
Static members
| Method | Returns | Description |
|---|---|---|
quantile(values: number[], n: number) | { lower?: number; upper?: number; }[] | Returns |
equalInterval(values: number[], n: number) | { lower?: number; upper?: number; }[] | Returns |
GridLayer extends Layer
Generic class for handling a tiled grid of HTML elements, and the base class of all
tile layers. To show map tiles from a URL, use TileLayer (or WMSTileLayer).
Extend GridLayer to create a tiled grid of your own elements like <canvas>,
<img> or <div>; it handles creating and animating them for you.
Layers extending GridLayer shall reimplement the createTile()
method.
Usage example
Synchronous usage
To create a custom layer, extend GridLayer and implement the createTile() method,
which will be passed a Point object with the x, y, and z (zoom level)
coordinates to draw your tile.
class CanvasLayer extends GridLayer {
createTile(coords) {
// create a <canvas> element for drawing
const tile = DomUtil.create('canvas', 'maplair-tile');
// setup tile width and height according to the options
const size = this.getTileSize();
tile.width = size.x;
tile.height = size.y;
// get a canvas context and draw something on it using coords.x, coords.y and coords.z
const ctx = tile.getContext('2d');
// return the tile so it can be rendered on screen
return tile;
}
}
Asynchronous usage
Tile creation can also be asynchronous, this is useful when using a third-party
drawing library. Once the tile is finished drawing it can be passed to the done()
callback.
class CanvasLayer extends GridLayer {
createTile(coords, done) {
const error;
// create a <canvas> element for drawing
const tile = DomUtil.create('canvas', 'maplair-tile');
// setup tile width and height according to the options
const size = this.getTileSize();
tile.width = size.x;
tile.height = size.y;
// draw something asynchronously and pass the tile to the done() callback
setTimeout(function() {
done(error, tile);
}, 1000);
return tile;
}
}
Constructor
| Constructor | Description |
|---|---|
new GridLayer(options?: GridLayerOptions) | Creates a new instance of GridLayer with the supplied options. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
tileSize | number|Point | 256 | Width and height of tiles in the grid. Use a
number if width and height are equal, or |
opacity | number | 1 | Opacity of the tiles. Can be used in the |
placeholder | string|null | null | A CSS
|
updateWhenIdle | boolean | false | Load new tiles only when panning ends. |
updateWhenZooming | boolean | true | By default, a smooth zoom animation
(during a pinch zoom or a |
updateInterval | number | 200 | Tiles will not update more than once every
|
zIndex | number | 1 | The explicit zIndex of the tile layer. |
bounds | LatLngBoundsExpression|null | null | If set, tiles will only be
loaded inside the set |
minZoom | number | 0 | The minimum zoom level down to which this layer will be displayed (inclusive). |
maxZoom | number | The maximum zoom level up to which this layer will be displayed (inclusive). | |
maxNativeZoom | number | Maximum zoom number the tile source has available.
If it is specified, the tiles on all zoom levels higher than | |
minNativeZoom | number | Minimum zoom number the tile source has available.
If it is specified, the tiles on all zoom levels lower than | |
noWrap | boolean | false | Whether the layer is wrapped around the
antimeridian. If |
pane | string | 'tilePane' |
|
className | string | '' | A custom class name to assign to the tile layer. Empty by default. |
pixelated | boolean | false | Whether to scale the tiles with
nearest-neighbour interpolation ( |
keepBuffer | number | 2 | When panning the map, keep this many rows and columns of tiles before unloading them. |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
| Event | Data | Description |
|---|---|---|
loading | MaplairEvent | Fired when the grid layer starts loading tiles. |
tileunload | TileEvent | Fired when a tile is removed (e.g. when a tile goes off the screen). |
tileloadstart | TileEvent | Fired when a tile is requested and starts loading. |
tileerror | TileErrorEvent | Fired when there is an error loading a tile. |
tileload | TileEvent | Fired when a tile loads. |
load | MaplairEvent | Fired when the grid layer loaded all visible tiles. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
Extension methods
| Method | Returns | Description |
|---|---|---|
createTile(coords: Point, done?: TileDoneCallback | undefined) | HTMLElement | Called only internally, must be overridden by classes extending |
Other methods
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | Creates the container of the tiles and loads the tiles. |
beforeAdd(map: MaplairMap) | void | Registers the zoom limits of the layer on the map. |
onRemove(map: MaplairMap) | void | Removes the tiles from the map. |
bringToFront() | this | Brings the tile layer to the top of all tile layers. |
bringToBack() | this | Brings the tile layer to the bottom of all tile layers. |
getContainer() | HTMLElement | Returns the HTML element that contains the tiles for this layer. |
setOpacity(opacity: number) | this | Changes the opacity of the grid layer. |
setZIndex(zIndex: number) | this | Changes the zIndex of the grid layer. |
isLoading() | boolean | Returns |
redraw() | this | Causes the layer to clear all the tiles and request them again. |
getEvents() | Record<string, Function> | Returns the map events the layer listens to, see |
getTileSize() | Point | Normalizes the tileSize option into a point. Used by
the |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
LatLng
Represents a geographical point with a certain latitude and longitude.
Usage example
const latlng = new LatLng(50.5, 30.5);
All Maplair methods that accept LatLng objects also accept them in a simple Array form and simple object form (unless noted otherwise), so these lines are equivalent:
map.panTo([50, 30]);
map.panTo({lat: 50, lng: 30});
map.panTo({lat: 50, lon: 30});
map.panTo(new LatLng(50, 30));
Note that LatLng does not inherit from Maplair's Class object,
which means new classes can't inherit from it, and new methods
can't be added to it with the include function.
Constructor
| Constructor | Description |
|---|---|
new LatLng(lat: number | LatLngExpression, lng?: number, alt?: number) | Creates an object representing a geographical point with the given latitude and
longitude (and optionally altitude). Alternatively, expects a
|
Methods
| Method | Returns | Description |
|---|---|---|
equals(obj: LatLngExpression, maxMargin?: number) | boolean | Returns |
toString(precision?: number | false) | string | Returns a string representation of the point (for debugging purposes). |
distanceTo(other: LatLngExpression) | number | Returns the distance (in meters) to the given |
wrap() | LatLng | Returns a new |
toBounds(sizeInMeters: number) | LatLngBounds | Returns a new |
Properties
| Property | Type | Description |
|---|---|---|
lat | number | Latitude in degrees. |
lng | number | Longitude in degrees. |
alt | number | undefined | Altitude in meters (optional). |
Static members
| Method | Returns | Description |
|---|---|---|
from(lat: number | LatLngExpression, lng?: number, alt?: number) | LatLng | Returns the given
|
validate(lat: any, lng?: any, alt?: any) | boolean | Returns |
parse(text: string) | LatLng | null | Parses coordinates in decimal degrees: a pair of numbers (latitude first), e.g.
|
LatLngBounds
Represents a rectangular geographical area on a map.
Usage example
const corner1 = new LatLng(40.712, -74.227),
corner2 = new LatLng(40.774, -74.125),
bounds = new LatLngBounds(corner1, corner2);
All Maplair methods that accept LatLngBounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:
map.fitBounds([
[40.712, -74.227],
[40.774, -74.125]
]);
Caution: if the area crosses the antimeridian (often confused with the International Date Line), you must specify corners outside the [-180, 180] degrees longitude range.
Note that LatLngBounds does not inherit from Maplair's Class object,
which means new classes can't inherit from it, and new methods
can't be added to it with the include function.
Constructor
| Constructor | Description |
|---|---|
new LatLngBounds(corner1?: LatLngExpression | LatLngBoundsExpression, corner2?: LatLngExpression) | Creates a
|
Methods
| Method | Returns | Description |
|---|---|---|
extend(obj: LatLngExpression | LatLngBoundsExpression) | this | Extend the bounds to contain the given point or bounds. |
pad(bufferRatio: number) | LatLngBounds | Returns bounds created by extending or retracting the current bounds by a given ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in each direction. Negative values will retract the bounds. |
getCenter() | LatLng | Returns the center point of the bounds. |
getSouthWest() | LatLng | Returns the south-west point of the bounds. |
getNorthEast() | LatLng | Returns the north-east point of the bounds. |
getNorthWest() | LatLng | Returns the north-west point of the bounds. |
getSouthEast() | LatLng | Returns the south-east point of the bounds. |
getWest() | number | Returns the west longitude of the bounds. |
getSouth() | number | Returns the south latitude of the bounds. |
getEast() | number | Returns the east longitude of the bounds. |
getNorth() | number | Returns the north latitude of the bounds. |
contains(obj: LatLngBoundsExpression | LatLngExpression) | boolean | Returns |
intersects(bounds: LatLngBoundsExpression) | boolean | Returns |
overlaps(bounds: LatLngBoundsExpression) | boolean | Returns |
toBBoxString() | string | Returns a string with bounding box coordinates in a 'southwest_lng,southwest_lat,northeast_lng,northeast_lat' format. Useful for sending requests to web services that return geo data. |
equals(bounds: LatLngBoundsExpression, maxMargin?: number) | boolean | Returns |
isValid() | boolean | Returns |
Static members
| Method | Returns | Description |
|---|---|---|
from(corner1?: LatLngExpression | LatLngBoundsExpression, corner2?: LatLngExpression) | LatLngBounds | Returns the given
|
Point
Represents a point with x and y coordinates in pixels.
Usage example
const point = new Point(200, 300);
All Maplair methods and options that accept Point objects also accept them in a
simple Array form (unless noted otherwise), so these lines are equivalent:
map.panBy([200, 300]);
map.panBy(new Point(200, 300));
Note that Point does not inherit from Maplair's Class object,
which means new classes can't inherit from it, and new methods
can't be added to it with the include function.
Constructor
| Constructor | Description |
|---|---|
new Point(x: number | PointExpression, y?: number, round?: boolean) | Creates a Point object with the given
|
Methods
| Method | Returns | Description |
|---|---|---|
add(point: PointExpression) | Point | Returns the result of addition of the current and the given points. |
subtract(point: PointExpression) | Point | Returns the result of subtraction of the given point from the current. |
divideBy(num: number) | Point | Returns the result of division of the current point by the given number. |
multiplyBy(num: number) | Point | Returns the result of multiplication of the current point by the given number. |
scaleBy(point: Point) | Point | Multiply each coordinate of the current point by each coordinate of
|
unscaleBy(point: Point) | Point | Inverse of
|
round() | Point | Returns a copy of the current point with rounded coordinates. |
floor() | Point | Returns a copy of the current point with floored coordinates (rounded down). |
ceil() | Point | Returns a copy of the current point with ceiled coordinates (rounded up). |
trunc() | Point | Returns a copy of the current point with truncated coordinates (rounded towards zero). |
distanceTo(point: PointExpression) | number | Returns the cartesian distance between the current and the given points. |
equals(point: PointExpression) | boolean | Returns |
contains(point: PointExpression) | boolean | Returns |
toString() | string | Returns a string representation of the point for debugging purposes. |
Properties
| Property | Type | Description |
|---|---|---|
x | number | The |
y | number | The |
Static members
| Method | Returns | Description |
|---|---|---|
from(x: number | PointExpression, y?: number, round?: boolean) | Point | Returns the given
|
validate(x: any, y?: any) | boolean | Returns |
Bounds
Represents a rectangular area in pixel coordinates.
Usage example
const p1 = new Point(10, 10),
p2 = new Point(40, 60),
bounds = new Bounds(p1, p2);
All Maplair methods that accept Bounds objects also accept them in a simple Array
form (unless noted otherwise), so the bounds example above can be passed like this:
otherBounds.intersects([[10, 10], [40, 60]]);
Note that Bounds does not inherit from Maplair's Class object,
which means new classes can't inherit from it, and new methods
can't be added to it with the include function.
Constructor
| Constructor | Description |
|---|---|
new Bounds(a?: PointExpression | BoundsExpression, b?: PointExpression) | Creates a Bounds object from two corners coordinate pairs. Alternatively, creates a Bounds object from the given array of points, or a copy of the given Bounds object.
|
Methods
| Method | Returns | Description |
|---|---|---|
extend(obj: PointExpression | BoundsExpression) | this | Extends the bounds to contain the given point or bounds. |
getCenter(round?: boolean) | Point | Returns the center point of the bounds. |
getBottomLeft() | Point | Returns the bottom-left point of the bounds. |
getTopRight() | Point | Returns the top-right point of the bounds. |
getTopLeft() | Point | Returns the top-left point of the bounds (i.e. |
getBottomRight() | Point | Returns the bottom-right point of the bounds (i.e. |
getSize() | Point | Returns the size of the given bounds. |
contains(obj: BoundsExpression | PointExpression) | boolean | Returns |
intersects(bounds: BoundsExpression) | boolean | Returns |
overlaps(bounds: BoundsExpression) | boolean | Returns |
isValid() | boolean | Returns |
pad(bufferRatio: number) | Bounds | Returns bounds created by extending or retracting the current bounds by a given ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in each direction. Negative values will retract the bounds. |
equals(bounds: BoundsExpression) | boolean | Returns |
Properties
| Property | Type | Description |
|---|---|---|
min | Point | The top left corner of the rectangle. |
max | Point | The bottom right corner of the rectangle. |
Static members
| Method | Returns | Description |
|---|---|---|
from(a?: PointExpression | BoundsExpression, b?: PointExpression) | Bounds | Returns the given
|
Icon extends Class
Represents an icon to provide when creating a marker.
DefaultIcon extends Icon and is the blue icon Maplair uses for markers by default.
Usage example
const myIcon = new Icon({
iconUrl: 'my-icon.png',
iconRetinaUrl: 'my-icon@2x.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
shadowUrl: 'my-icon-shadow.png',
shadowRetinaUrl: 'my-icon-shadow@2x.png',
shadowSize: [68, 95],
shadowAnchor: [22, 94]
});
new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new Icon(options?: IconOptions) | Creates an icon instance with the given options. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
iconUrl | string | (required) The URL to the icon image (absolute or relative to your script path). | |
iconRetinaUrl | string | The URL to a retina sized version of the icon image (absolute or relative to your script path). Used for Retina screen devices. | |
iconSize | PointExpression|number | Size of the icon image in pixels (a number for square icons). | |
iconAnchor | PointExpression | The coordinates of the "tip" of the icon (relative to its top left corner). The icon will be aligned so that this point is at the marker's geographical location. Centered by default if size is specified, also can be set in CSS with negative margins. | |
popupAnchor | PointExpression | [0, 0] | The coordinates of the point from which popups will "open", relative to the icon anchor. |
tooltipAnchor | PointExpression | [0, 0] | The coordinates of the point from which tooltips will "open", relative to the icon anchor. |
shadowUrl | string | The URL to the icon shadow image. If not specified, no shadow image will be created. | |
shadowRetinaUrl | string | The URL to a retina sized version of the shadow image. Used for Retina screen devices. | |
shadowSize | PointExpression|number | Size of the shadow image in pixels. | |
shadowAnchor | PointExpression | The coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not specified). | |
className | string | A custom class name to assign to both icon and shadow images. Empty by default. | |
crossOrigin | boolean|string | false | Whether the crossOrigin attribute will be added to the icon images. If a String is provided, all images will have their crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data. Refer to CORS Settings for valid String values. |
Methods
| Method | Returns | Description |
|---|---|---|
createIcon(oldIcon?: HTMLElement) | HTMLElement | Called internally when the icon has to be shown, returns a
|
createShadow(oldIcon?: HTMLElement) | HTMLElement | null | As
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
DefaultIcon extends Icon
A subclass of Icon, represents the icon to use in Markers when no icon is
specified, optionally in another color. The maple leaf marker and its shadow are
inlined as SVG data URIs, so they work with any bundler and need no image files.
In order to customize the default icon, just change the properties of
DefaultIcon.defaultOptions (which is a set of Icon options).
If you want to completely replace the default icon, override the
Marker.defaultOptions.icon with your own icon instead.
Constructor
| Constructor | Description |
|---|---|
new DefaultIcon(options?: DefaultIconOptions | undefined) | Creates the default icon, optionally with changed options. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
iconUrl | string | The maple leaf marker, inlined as an SVG data URI. | |
color | string|null | null | Paints the pin in the given CSS color instead of
the default red, overriding |
shadowUrl | string | Its shadow, inlined as an SVG data URI. | |
iconSize | PointExpression|number | [25, 41] | |
iconAnchor | PointExpression | [12, 41] | |
popupAnchor | PointExpression | [1, -34] | |
tooltipAnchor | PointExpression | [16, -28] | |
shadowSize | PointExpression|number | [41, 41] |
Options inherited from Icon
| Option | Type | Default | Description |
|---|---|---|---|
iconUrl | string | (required) The URL to the icon image (absolute or relative to your script path). | |
iconRetinaUrl | string | The URL to a retina sized version of the icon image (absolute or relative to your script path). Used for Retina screen devices. | |
iconSize | PointExpression|number | Size of the icon image in pixels (a number for square icons). | |
iconAnchor | PointExpression | The coordinates of the "tip" of the icon (relative to its top left corner). The icon will be aligned so that this point is at the marker's geographical location. Centered by default if size is specified, also can be set in CSS with negative margins. | |
popupAnchor | PointExpression | [0, 0] | The coordinates of the point from which popups will "open", relative to the icon anchor. |
tooltipAnchor | PointExpression | [0, 0] | The coordinates of the point from which tooltips will "open", relative to the icon anchor. |
shadowUrl | string | The URL to the icon shadow image. If not specified, no shadow image will be created. | |
shadowRetinaUrl | string | The URL to a retina sized version of the shadow image. Used for Retina screen devices. | |
shadowSize | PointExpression|number | Size of the shadow image in pixels. | |
shadowAnchor | PointExpression | The coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not specified). | |
className | string | A custom class name to assign to both icon and shadow images. Empty by default. | |
crossOrigin | boolean|string | false | Whether the crossOrigin attribute will be added to the icon images. If a String is provided, all images will have their crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data. Refer to CORS Settings for valid String values. |
Methods
Methods inherited from Icon
| Method | Returns | Description |
|---|---|---|
createIcon(oldIcon?: HTMLElement) | HTMLElement | Called internally when the icon has to be shown, returns a
|
createShadow(oldIcon?: HTMLElement) | HTMLElement | null | As
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
DivIcon extends Icon
Represents a lightweight icon for markers that uses a simple <div>
element instead of an image. Inherits from Icon but ignores the iconUrl and
shadow options.
By default, it has a 'maplair-div-icon' CSS class and is styled as a little white square with a shadow.
Usage example
const myIcon = new DivIcon({className: 'my-div-icon'});
// you can set .my-div-icon styles in CSS
new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new DivIcon(options?: DivIconOptions | undefined) | Creates a |
Options
| Option | Type | Default | Description |
|---|---|---|---|
iconSize | PointExpression|number | [12, 12] | Size of the icon in pixels, also can be set through CSS. |
html | string|HTMLElement|false | false | Custom HTML code to put inside the
div element, empty by default. Alternatively, an instance of |
bgPos | PointExpression|null | null | Optional relative position of the background, in pixels. |
className | string | 'maplair-div-icon' |
Options inherited from Icon
| Option | Type | Default | Description |
|---|---|---|---|
iconUrl | string | (required) The URL to the icon image (absolute or relative to your script path). | |
iconRetinaUrl | string | The URL to a retina sized version of the icon image (absolute or relative to your script path). Used for Retina screen devices. | |
iconSize | PointExpression|number | Size of the icon image in pixels (a number for square icons). | |
iconAnchor | PointExpression | The coordinates of the "tip" of the icon (relative to its top left corner). The icon will be aligned so that this point is at the marker's geographical location. Centered by default if size is specified, also can be set in CSS with negative margins. | |
popupAnchor | PointExpression | [0, 0] | The coordinates of the point from which popups will "open", relative to the icon anchor. |
tooltipAnchor | PointExpression | [0, 0] | The coordinates of the point from which tooltips will "open", relative to the icon anchor. |
shadowUrl | string | The URL to the icon shadow image. If not specified, no shadow image will be created. | |
shadowRetinaUrl | string | The URL to a retina sized version of the shadow image. Used for Retina screen devices. | |
shadowSize | PointExpression|number | Size of the shadow image in pixels. | |
shadowAnchor | PointExpression | The coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not specified). | |
className | string | A custom class name to assign to both icon and shadow images. Empty by default. | |
crossOrigin | boolean|string | false | Whether the crossOrigin attribute will be added to the icon images. If a String is provided, all images will have their crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data. Refer to CORS Settings for valid String values. |
Methods
| Method | Returns | Description |
|---|---|---|
createShadow() | null | Returns |
Methods inherited from Icon
| Method | Returns | Description |
|---|---|---|
createIcon(oldIcon?: HTMLElement) | HTMLElement | Called internally when the icon has to be shown, returns a
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
SvgIcon extends DefaultIcon
A marker icon in the shape of the default marker (with its shadow), drawn as inline SVG in any color and with an optional glyph – a character, an emoji or an SVG path (e.g. of an icon set) – instead of the white maple leaf. No image per color is needed, and it stays sharp on any screen.
Inspired by the Leaflet.awesome-markers, leaflet-color-markers and Leaflet.ExtraMarkers plugins.
Usage example
new Marker([47.27, 11.40], {icon: new SvgIcon({color: '#2a81cb', glyph: 'P'})}).addTo(map);
new Marker([47.28, 11.41], {icon: new SvgIcon({color: 'green', glyph: '🚲'})}).addTo(map);
// a 24×24 SVG path, e.g. from Material Design Icons
new Marker([47.29, 11.42], {icon: new SvgIcon({color: 'purple', glyphPath: 'M12 2L2 22h20z'})}).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new SvgIcon(options?: SvgIconOptions | undefined) | Creates an |
Options
| Option | Type | Default | Description |
|---|---|---|---|
color | string | '#d4462c' | The fill color of the marker, any CSS color. The outline is a darker shade of it. |
glyph | string | A character or emoji (or short text) shown in the marker instead of the maple leaf. | |
glyphPath | string | The path data of an SVG glyph in a 24×24 view box (like Material Design Icons), shown in the marker instead of the maple leaf. | |
glyphColor | string | 'white' | The color of the glyph or the maple leaf. |
Options inherited from DefaultIcon
| Option | Type | Default | Description |
|---|---|---|---|
iconUrl | string | The maple leaf marker, inlined as an SVG data URI. | |
color | string|null | null | Paints the pin in the given CSS color instead of
the default red, overriding |
shadowUrl | string | Its shadow, inlined as an SVG data URI. | |
iconSize | PointExpression|number | [25, 41] | |
iconAnchor | PointExpression | [12, 41] | |
popupAnchor | PointExpression | [1, -34] | |
tooltipAnchor | PointExpression | [16, -28] | |
shadowSize | PointExpression|number | [41, 41] |
Options inherited from Icon
| Option | Type | Default | Description |
|---|---|---|---|
iconUrl | string | (required) The URL to the icon image (absolute or relative to your script path). | |
iconRetinaUrl | string | The URL to a retina sized version of the icon image (absolute or relative to your script path). Used for Retina screen devices. | |
iconSize | PointExpression|number | Size of the icon image in pixels (a number for square icons). | |
iconAnchor | PointExpression | The coordinates of the "tip" of the icon (relative to its top left corner). The icon will be aligned so that this point is at the marker's geographical location. Centered by default if size is specified, also can be set in CSS with negative margins. | |
popupAnchor | PointExpression | [0, 0] | The coordinates of the point from which popups will "open", relative to the icon anchor. |
tooltipAnchor | PointExpression | [0, 0] | The coordinates of the point from which tooltips will "open", relative to the icon anchor. |
shadowUrl | string | The URL to the icon shadow image. If not specified, no shadow image will be created. | |
shadowRetinaUrl | string | The URL to a retina sized version of the shadow image. Used for Retina screen devices. | |
shadowSize | PointExpression|number | Size of the shadow image in pixels. | |
shadowAnchor | PointExpression | The coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not specified). | |
className | string | A custom class name to assign to both icon and shadow images. Empty by default. | |
crossOrigin | boolean|string | false | Whether the crossOrigin attribute will be added to the icon images. If a String is provided, all images will have their crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data. Refer to CORS Settings for valid String values. |
Methods
Methods inherited from Icon
| Method | Returns | Description |
|---|---|---|
createIcon(oldIcon?: HTMLElement) | HTMLElement | Called internally when the icon has to be shown, returns a
|
createShadow(oldIcon?: HTMLElement) | HTMLElement | null | As
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
ZoomControl extends Control
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.
Constructor
| Constructor | Description |
|---|---|
new ZoomControl(options?: ZoomControlOptions) | Creates a zoom control. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topleft' | The position of the control (one of the map
corners). Possible values are |
zoomInText | string | The HTML of the 'zoom in' button, a plus sign drawn in SVG by default. | |
zoomOutText | string | The HTML of the 'zoom out' button, a minus sign drawn in SVG by default. |
Options inherited from Control
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
| Method | Returns | Description |
|---|---|---|
disable() | this | Disables the zoom buttons. |
enable() | this | Enables the zoom buttons (if the zoom level allows). |
Methods inherited from Control
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
addTo(map: MaplairMap) | this | Adds the control to the given map. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
AttributionControl extends Control
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.
Constructor
| Constructor | Description |
|---|---|
new AttributionControl(options?: AttributionControlOptions) | Creates an attribution control. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'bottomright' | The position of the control (one of the
map corners). Possible values are |
prefix | string|false|null | null | The HTML text shown before the
attributions. Pass |
Options inherited from Control
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
| Method | Returns | Description |
|---|---|---|
setPrefix(prefix: string | false) | this | The HTML text shown before the attributions. Pass |
addAttribution(text: string, order?: number) | this | Adds an attribution text (e.g. |
removeAttribution(text: string) | this | Removes an attribution text. |
Methods inherited from Control
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
addTo(map: MaplairMap) | this | Adds the control to the given map. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
LayersControl extends Control
The layers control gives users the ability to switch between different base layers and switch overlays on/off (check out the detailed example).
Usage example
const baseLayers = {
"Mapbox": mapbox,
"OpenStreetMap": osm
};
const overlays = {
"Marker": marker,
"Roads": roadsLayer
};
new LayersControl(baseLayers, overlays).addTo(map);
The baseLayers and overlays parameters are object literals with layer names as keys and Layer objects as values:
{
"<someName1>": layer1,
"<someName2>": layer2
}
The layer names can contain HTML, which allows you to add additional styling to the items:
{"<img src='my-layer-icon' /> <span class='my-layer-item'>My Layer</span>": myLayer}
Layers can be grouped using the option groupBy, for example layer names of the form
"Group (label)":
new LayersControl(baseLayers, overlays, {
inline: true,
groupBy(name) {
const [, group, label] = /^([^<>()]+) \((.+)\)$/.exec(name) ?? [];
return group ? {group: `${group}:`, label} : undefined;
}
}).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new LayersControl(baseLayers?: Record<string, Layer>, overlays?: Record<string, Layer>, options?: LayersControlOptions) | Creates a layers 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 | Description |
|---|---|---|---|
collapsed | boolean | true | If |
inline | boolean | false | If |
groupBy | (name: string, layer: Layer, overlay: boolean) => LayersControlGroup | undefined | A function to group the entries. For each entry, it returns the name of its group and
its label within the group, or | |
title | string | The title of the toggle button and the accessible label
of the layers list, the translation of | |
toggleContent | string|HTMLElement | The content of the toggle button of a collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an element. String content is rendered as HTML; do not pass untrusted input. | |
collapseDelay | number | 0 | Collapse delay in milliseconds. If greater than 0, the control will remain open longer, making it easier to scroll through long layer lists. |
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
autoZIndex | boolean | true | If |
hideSingleBase | boolean | false | If |
sortLayers | boolean | false | Whether to sort the layers. When |
sortFunction | (layerA: Layer, layerB: Layer, nameA: string, nameB: string) => number | A compare function
that will be used for sorting the layers, when |
Options inherited from Control
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap) | this | Adds the control to the given map. |
addBaseLayer(layer: Layer, name: string) | this | Adds a base layer (radio button entry) with the given name to the control. |
addOverlay(layer: Layer, name: string) | this | Adds an overlay (checkbox entry) with the given name to the control. |
removeLayer(layer: Layer) | this | Remove the given layer from the control. |
getLayers() | LayersControlEntry[] | Returns the entries of the control in the order they are displayed. |
selectLayer(layer: Layer) | this | Selects the given layer of the control like a click on its entry: a base layer
replaces the current base layer, an overlay is added to the map. The events
|
expand() | this | Expand the control container if collapsed. |
collapse() | this | Collapse the control container if expanded. |
Methods inherited from Control
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
LegendControl extends Control
Constructor
| Constructor | Description |
|---|---|
new LegendControl(options?: LegendControlOptions) | Creates a legend control. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'bottomright' | The position of the control (one of the
map corners). Possible values are |
collapsed | boolean | false | If |
featureCount | boolean | false | If |
bar | boolean | false | If |
Options inherited from Control
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
| Method | Returns | Description |
|---|---|---|
addClassification(layer: FeatureGroup, classification: Classification) | this | Shows the classes of |
removeClassification(layer: FeatureGroup) | this | Removes the classification of |
Methods inherited from Control
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
addTo(map: MaplairMap) | this | Adds the control to the given map. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
MiniMapControl extends Control
An overview map in a corner of the map, showing the view of the map as a rectangle (or rotated rectangle on a rotated map) at a smaller zoom level. Dragging the overview map pans the map, clicking it centers the map there, and a button collapses it.
Inspired by the Leaflet-MiniMap plugin.
Usage example
// a layer of its own, a layer can only be on one map
const overviewLayer = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png');
new MiniMapControl(overviewLayer).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new MiniMapControl(layer: Layer, options?: MiniMapControlOptions) | Creates an overview map control showing |
Options
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'bottomright' | The position of the control (one of the map
corners). Possible values are |
width | number | 150 | The width of the overview map in pixels. |
height | number | 150 | The height of the overview map in pixels. |
zoomOffset | number | -5 | The zoom level of the overview map relative to the map. |
collapsed | boolean | false | Whether the overview map is collapsed initially. |
rectangleOptions | PathOptions | {color: '#ff7800', weight: 1, fillOpacity: 0.2} | The style of the rectangle showing the view of the map. |
mapOptions | MaplairMapOptions | {} | Further options of the overview map. |
Options inherited from Control
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap) | this | Adds the control to the given map. |
getMiniMap() | MaplairMap | Returns the overview map. |
toggle() | this | Collapses or expands the overview map. |
Methods inherited from Control
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
ScaleControl extends Control
A simple scale control that shows the scale of the current center of screen in metric (m/km) and imperial (mi/ft) systems.
Usage example
new ScaleControl().addTo(map);
Constructor
| Constructor | Description |
|---|---|
new ScaleControl(options?: ScaleControlOptions) | Creates a scale control with the given options. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'bottomleft' | The position of the control (one of the map
corners). Possible values are |
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 |
Options inherited from Control
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
Methods inherited from Control
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
addTo(map: MaplairMap) | this | Adds the control to the given map. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
SearchControl extends Control
A control with a search field for places, showing the results in a list to select
one with the pointer or the keyboard. The selected result is shown on the map with a
marker. It searches with a geocoder, e.g.
Nominatim of OpenStreetMap or any other service.
Coordinates like 47.27, 11.4 or geo:47.27,11.4 are found without a service.
The public Nominatim service is free, but limited by its
usage policy: it is for
occasional searches of users, not for heavy use (an absolute maximum of one request
per second for all users of an app), and forbids auto-complete. The
Nominatim geocoder follows the technical requirements,
but you are responsible for your use of the service, which you confirm with the
acceptUsagePolicy option: for more traffic, use your own Nominatim server or a
commercial provider.
Usage example
new SearchControl({
geocoder: SearchControl.nominatim({acceptUsagePolicy: true})
}).addTo(map);
// Photon of Komoot, which allows auto-complete
new SearchControl({
autoComplete: true,
async geocoder(query, {signal}) {
const response = await fetch(`https://photon.komoot.io/api/?q=${encodeURIComponent(query)}`, {signal});
const {features} = await response.json();
return features.map(({geometry, properties}) => ({
label: [properties.name, properties.city, properties.country].filter(Boolean).join(', '),
latlng: [geometry.coordinates[1], geometry.coordinates[0]],
raw: properties
}));
}
}).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new SearchControl(options?: SearchControlOptions) | Creates a search control. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topleft' | The position of the control (one of the map
corners). Possible values are |
geocoder | Geocoder | The function searching places (required), e.g.
Nominatim. Coordinates (see
| |
collapsed | boolean | true | If |
autoComplete | boolean | false | Whether to search while typing instead of on Enter. Not with the public Nominatim service, its usage policy forbids auto-complete. |
autoCompleteDelay | number | 250 | The delay in milliseconds after typing
before searching with |
minLength | number | 3 | The minimum length of queries searched with
|
zoom | number | 16 | The zoom level for results without bounds, and the maximum zoom level for fitting the bounds of results. |
marker | boolean|((result: SearchResult) => Layer|null|undefined) | true | Whether
to show a marker at the selected result, or a function returning the layer to show
instead, e.g. a |
clearOnMapClick | boolean | false | If |
placeholder | string | The placeholder of the search field, by default the translation of "Search". | |
noResultsText | string | The message shown if nothing is found, by default the translation of "No results". |
Options inherited from Control
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
| Method | Returns | Description |
|---|---|---|
expand() | this | Expands the search field of a collapsed control and focuses it. |
collapse() | this | Collapses the control into its button, if collapsed, and hides the results. |
search(query: string) | Promise<SearchResult[]> | Searches the given text and shows the results in the list. Resolves to the results. |
select(result: SearchResult) | this | Shows the given result on the map: zooms to it, shows a
marker and fires |
clear() | this | Clears the search field, the results and the marker. |
Methods inherited from Control
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
addTo(map: MaplairMap) | this | Adds the control to the given map. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Static members
| Method | Returns | Description |
|---|---|---|
nominatim({ url, params, acceptUsagePolicy }?: { url?: string | undefined; params?: Record<string, string> | undefined; acceptUsagePolicy?: boolean | undefined; }) | Geocoder | Returns a geocoder searching with
Nominatim, by default the
public service of OpenStreetMap. Using it requires that you read and accept its
usage policy with the
|
layers(group: LayerGroup, { property, label, limit }?: { property?: string | undefined; label?: ((layer: Layer) => string | number | null | undefined) | undefined; limit?: number | undefined; }) | Geocoder | Returns a geocoder searching the layers of a layer group,
e.g. the markers of a
|
SideBySideControl extends Control
Compares layers side by side: a vertical divider across the map shows the "left" layers on its left and the "right" layers on its right side. The divider can be dragged, or moved with the arrow keys. Works with layers having a container or element of their own, e.g. tile layers and image overlays.
Inspired by the leaflet-side-by-side plugin.
Usage example
const before = new TileLayer('https://…/2020/{z}/{x}/{y}.png').addTo(map);
const after = new TileLayer('https://…/2025/{z}/{x}/{y}.png').addTo(map);
new SideBySideControl(before, after).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new SideBySideControl(leftLayers?: Layer | Layer[], rightLayers?: Layer | Layer[], options?: SideBySideControlOptions) | Creates a side-by-side control for the given layers (which have to be added to the map separately). |
Options
| Option | Type | Default | Description |
|---|---|---|---|
ratio | number | 0.5 | The initial position of the divider, from |
Options inherited from Control
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap) | this | Adds the control to the given map. The divider spans the map instead of being in a corner. |
setLeftLayers(layers: Layer | Layer[]) | this | Sets the layers shown on the left side of the divider. |
setRightLayers(layers: Layer | Layer[]) | this | Sets the layers shown on the right side of the divider. |
getRatio() | number | Returns the position of the divider, from |
setRatio(ratio: number) | this | Moves the divider, from |
Methods inherited from Control
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
FullscreenControl extends Control
A control with a button to view the map in fullscreen and to exit it again. It is
put on the map if you set its fullscreenControl option
to true. Where the browser does not support the
Fullscreen API
(e.g. Safari on iPhone) or refuses fullscreen (e.g. in an iframe without
allow="fullscreen"), the map is enlarged to the size of the window instead.
Usage example
new FullscreenControl({position: 'topright'}).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new FullscreenControl(options?: FullscreenControlOptions) | Creates a fullscreen control. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topleft' | The position of the control (one of the map
corners). Possible values are |
enterText | string | The HTML content of the button while the map is not in fullscreen, by default an expand icon. | |
exitText | string | The HTML content of the button while the map is in fullscreen, by default a collapse icon. |
Options inherited from Control
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
Methods inherited from Control
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
addTo(map: MaplairMap) | this | Adds the control to the given map. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
RotateControl extends Control
A compass showing the rotation of the map (see MaplairMap.setBearing()); clicking it
rotates the map back to north up. It is put on the map if you set its
rotateControl option to true.
Usage example
new RotateControl({position: 'topright'}).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new RotateControl(options?: RotateControlOptions) | Creates a rotate control. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topleft' | The position of the control (one of the map
corners). Possible values are |
Options inherited from Control
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
Methods inherited from Control
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
addTo(map: MaplairMap) | this | Adds the control to the given map. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
TextControl extends Control
A control showing a text or any content in a box, e.g. a title, a note on the data or a status. It is hidden while its content is empty.
Usage example
const status = new TextControl({position: 'topright', content: 'Loading…'}).addTo(map);
status.setContent(`Updated at ${new Date().toLocaleTimeString()}`);
Constructor
| Constructor | Description |
|---|---|
new TextControl(options?: TextControlOptions) | Creates a text control. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
content | string|HTMLElement | '' | The content of the control: HTML or an element. String content is rendered as HTML; do not pass untrusted input. |
className | string | '' | A custom CSS class name to assign to the control. |
Options inherited from Control
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
| Method | Returns | Description |
|---|---|---|
setContent(content: string | HTMLElement) | this | Changes the content of the control. |
getContent() | string | HTMLElement | Returns the content of the control. |
Methods inherited from Control
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
addTo(map: MaplairMap) | this | Adds the control to the given map. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
DragHandler extends Handler
Makes the map draggable (with panning inertia), enabled by default, see the map
option dragging.
Constructor
| Constructor | Description |
|---|---|
new DragHandler(map: MaplairMap) |
Methods
| Method | Returns | Description |
|---|---|---|
moved() | boolean | Returns |
moving() | boolean | Returns |
Methods inherited from Handler
| Method | Returns | Description |
|---|---|---|
enable() | this | Enables the handler. |
disable() | this | Disables the handler. |
enabled() | boolean | Returns |
addHooks() | void | Called when the handler is enabled, should add event hooks. |
removeHooks() | void | Called when the handler is disabled, should remove the event hooks added previously. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
BoxZoomHandler extends Handler
Adds shift-drag zoom interaction to the map (zoom to a selected bounding box),
enabled by default, see the map option boxZoom.
Methods
| Method | Returns | Description |
|---|---|---|
moved() | boolean | Returns |
Methods inherited from Handler
| Method | Returns | Description |
|---|---|---|
enable() | this | Enables the handler. |
disable() | this | Disables the handler. |
enabled() | boolean | Returns |
addHooks() | void | Called when the handler is enabled, should add event hooks. |
removeHooks() | void | Called when the handler is disabled, should remove the event hooks added previously. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
DoubleClickZoomHandler extends Handler
Handles double-click zoom on the map, enabled by default, see the map option
doubleClickZoom.
Constructor
| Constructor | Description |
|---|---|
new DoubleClickZoomHandler(map: MaplairMap) |
Methods
Methods inherited from Handler
| Method | Returns | Description |
|---|---|---|
enable() | this | Enables the handler. |
disable() | this | Disables the handler. |
enabled() | boolean | Returns |
addHooks() | void | Called when the handler is enabled, should add event hooks. |
removeHooks() | void | Called when the handler is disabled, should remove the event hooks added previously. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
ScrollWheelZoomHandler extends Handler
Enables mouse scroll wheel zoom on the map, as well as touchpad gestures: pinching
zooms, and with scrollWheelZoom: 'trackpad' scrolling with two fingers pans.
Enabled by default, see the map option scrollWheelZoom.
Constructor
| Constructor | Description |
|---|---|
new ScrollWheelZoomHandler(map: MaplairMap) |
Methods
Methods inherited from Handler
| Method | Returns | Description |
|---|---|---|
enable() | this | Enables the handler. |
disable() | this | Disables the handler. |
enabled() | boolean | Returns |
addHooks() | void | Called when the handler is enabled, should add event hooks. |
removeHooks() | void | Called when the handler is disabled, should remove the event hooks added previously. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
KeyboardHandler extends Handler
Handles keyboard interaction with the map, enabled by default, see the map option
keyboard. The ? key shows a list of the keyboard shortcuts.
Methods
Methods inherited from Handler
| Method | Returns | Description |
|---|---|---|
enable() | this | Enables the handler. |
disable() | this | Disables the handler. |
enabled() | boolean | Returns |
addHooks() | void | Called when the handler is enabled, should add event hooks. |
removeHooks() | void | Called when the handler is disabled, should remove the event hooks added previously. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Static members
| Property | Type | Description |
|---|---|---|
keys | Record<"left" | "right" | "down" | "up" | "zoomIn" | "zoomOut", string[]> | The values
of the keys for panning and zooming the map, so zoom keys follow the keyboard
layout and cover the numpad too; |
PinchZoomHandler extends Handler
Adds pinch zoom to the map on supported mobile browsers, enabled by default, see the
map option pinchZoom.
Constructor
| Constructor | Description |
|---|---|
new PinchZoomHandler(map: MaplairMap) |
Methods
Methods inherited from Handler
| Method | Returns | Description |
|---|---|---|
enable() | this | Enables the handler. |
disable() | this | Disables the handler. |
enabled() | boolean | Returns |
addHooks() | void | Called when the handler is enabled, should add event hooks. |
removeHooks() | void | Called when the handler is disabled, should remove the event hooks added previously. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
TapDragZoomHandler extends Handler
Zooms the map with one finger on touch devices: tap once, then touch again and drag
down to zoom in or up to zoom out (as known from MapLibre GL JS and Google Maps).
Enabled by default, see the map option tapDragZoom.
Constructor
| Constructor | Description |
|---|---|
new TapDragZoomHandler(map: MaplairMap) |
Methods
Methods inherited from Handler
| Method | Returns | Description |
|---|---|---|
enable() | this | Enables the handler. |
disable() | this | Disables the handler. |
enabled() | boolean | Returns |
addHooks() | void | Called when the handler is enabled, should add event hooks. |
removeHooks() | void | Called when the handler is disabled, should remove the event hooks added previously. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
TapHoldHandler extends Handler
Simulates the contextmenu event on long hold, which otherwise is not fired by
mobile Safari, see the map option tapHold.
Constructor
| Constructor | Description |
|---|---|
new TapHoldHandler(map: MaplairMap) |
Methods
Methods inherited from Handler
| Method | Returns | Description |
|---|---|---|
enable() | this | Enables the handler. |
disable() | this | Disables the handler. |
enabled() | boolean | Returns |
addHooks() | void | Called when the handler is enabled, should add event hooks. |
removeHooks() | void | Called when the handler is disabled, should remove the event hooks added previously. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
DisplaceHandler extends Handler
Cartographic displacement of overlapping CircleMarkers: keeps all circle
markers created with displace: true free of overlap.
Overlap is a screen space phenomenon: whether two markers cover each other
depends on their pixel radius and the current zoom level. The displacement is
therefore computed in projected pixel space and recomputed on every zoom. The
true position of each marker is kept by the handler, the displaced position is
applied via setLatLng. Since every run starts over from the true position,
markers never drift.
maxDistance bounds how far a marker may be moved away from the truth, in
meters. It is worth noting what such a limit costs at low zoom levels: if a
marker is 11 km wide on the ground, separating two coincident ones moves each
of them by some 6 km, so a limit below that leaves them overlapping.
Unlike the default handlers, it isn't added to every map, so that bundlers can
drop it from applications that don't use it. Add it to the map class (or to a
single map with DisplaceHandler.addTo(map, 'displace')), then enable it with
the map option displace, which is either true or an object overriding the
handler's options. It can be toggled at runtime via map.displace.enable() /
map.displace.disable(); disabling restores the true positions.
Usage example
import { CircleMarker, DisplaceHandler, MaplairMap } from 'maplair';
MaplairMap.addInitHook('addHandler', 'displace', DisplaceHandler);
const map = new MaplairMap('map', {displace: { maxDistance: 10_000} });
new CircleMarker(latlng, { displace: true, radius: 6 }).addTo(map);
Constructor
| Constructor | Description |
|---|---|
new DisplaceHandler(map: MaplairMap) |
Options
| Option | Type | Default | Description |
|---|---|---|---|
gap | number | 2 | Additional pixel distance between the outlines of two markers. |
iterations | number | 80 | Maximum number of relaxation passes per relayout. |
maxDistance | number | Infinity | Maximum distance in meters a marker may be moved away from its true position. Markers which would have to move further stay overlapping. Meters rather than pixels, since the point of the limit is to bound the geographic error. A limit in meters also scales itself: it only bites at the zoom levels where a pixel is worth a lot of ground. |
Methods
| Method | Returns | Description |
|---|---|---|
schedule() | void | Requests a relayout in the next animation frame, at most one per frame. |
relayout() | void | Computes the displacement for all tracked markers in the pixel space of the current zoom level and writes the displaced positions back. |
Methods inherited from Handler
| Method | Returns | Description |
|---|---|---|
enable() | this | Enables the handler. |
disable() | this | Disables the handler. |
enabled() | boolean | Returns |
addHooks() | void | Called when the handler is enabled, should add event hooks. |
removeHooks() | void | Called when the handler is disabled, should remove the event hooks added previously. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
MarkerDrag extends Handler
The handler of Marker which makes the markers draggable, see the
dragging property of markers and its draggable option.
Constructor
| Constructor | Description |
|---|---|
new MarkerDrag(marker: Marker) | Creates the dragging handler of the given marker. |
Methods
| Method | Returns | Description |
|---|---|---|
moved() | boolean | Returns |
Methods inherited from Handler
| Method | Returns | Description |
|---|---|---|
enable() | this | Enables the handler. |
disable() | this | Disables the handler. |
enabled() | boolean | Returns |
addHooks() | void | Called when the handler is enabled, should add event hooks. |
removeHooks() | void | Called when the handler is disabled, should remove the event hooks added previously. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Util
Functions
| Method | Returns | Description |
|---|---|---|
stamp(obj: object) | number | Returns the unique ID of an object, assigning it one if it doesn't have it. |
throttle(fn: (...args: any[]) => void, time: number, context?: object) | (...args: any[]) => void | Returns a function which executes function
|
wrapNum(x: number, range: [number, number], includeMax?: boolean) | number | Returns the number |
falseFn() | false | A function which always returns |
formatNum(num: number, precision?: number | false) | number | Returns the number |
toNumber(value: unknown) | number | Returns |
splitWords(str: string) | string[] | Trims and splits the string on whitespace and returns the array of parts. |
setOptions(obj: object, options?: object) | object | Merges the given properties to the |
template(str: string, data: Record<string, any>) | string | Simple templating facility, accepts a template string of the form |
Properties
| Property | Type | Description |
|---|---|---|
lastId | number | Last unique ID used by |
Transformation
Represents an affine transformation: a set of coefficients a, b, c, d
for transforming a point of a form (x, y) into (a*x + b, c*y + d) and doing
the reverse. Used by Maplair in its projections code.
Usage example
const transformation = new Transformation(2, 5, -1, 10),
p = new Point(1, 2),
p2 = transformation.transform(p), // new Point(7, 8)
p3 = transformation.untransform(p2); // new Point(1, 2)
Constructor
| Constructor | Description |
|---|---|
new Transformation(a: number | [number, number, number, number], b?: number, c?: number, d?: number) | Instantiates a Transformation object with the given coefficients. Alternatively,
expects a coefficients array of the form |
Methods
| Method | Returns | Description |
|---|---|---|
transform(point: Point, scale?: number) | Point | Returns a transformed point, optionally multiplied by the given scale.
Only accepts actual |
untransform(point: Point, scale?: number) | Point | Returns the reverse transformation of the given point, optionally divided
by the given scale. Only accepts actual |
LineUtil
Functions
| Method | Returns | Description |
|---|---|---|
simplify(points: Point[], tolerance: number) | Point[] | Dramatically reduces the number of points in a polyline while retaining its shape and returns a new array of simplified points, using the Ramer-Douglas-Peucker algorithm. Used for a huge performance boost when processing/displaying Maplair polylines for each zoom level and also reducing visual noise. tolerance affects the amount of simplification (lesser value means higher quality but slower and with more points). Also released as a separated micro-library Simplify.js. |
pointToSegmentDistance(p: Point, p1: Point, p2: Point) | number | Returns the distance between point |
closestPointOnSegment(p: Point, p1: Point, p2: Point) | Point | Returns the closest point from a point |
clipSegment(a: Point, b: Point, bounds: Bounds, useLastCode?: boolean, round?: boolean) | [Point, Point] | false | Clips the segment a to b by rectangular bounds with the
Cohen-Sutherland algorithm
(modifying the segment points directly!). Used by Maplair to only show polyline
points that are on the screen or near, increasing performance. Returns |
isFlat(latlngs: LatLngExpression[] | LatLngExpression[][]) | boolean | Returns true if |
polylineCenter(latlngs: LatLngExpression[] | LatLngExpression[][], crs: typeof CRS) | LatLng | Returns the center (centroid) of the passed LatLngs (first ring) from a polyline. |
PolyUtil
Functions
| Method | Returns | Description |
|---|---|---|
clipPolygon(points: Point[], bounds: Bounds, round?: boolean) | Point[] | Clips the polygon geometry defined by the given |
polygonCenter(latlngs: LatLngExpression[] | LatLngExpression[][], crs: typeof CRS) | LatLng | Returns the center (centroid) of the passed LatLngs (first ring) from a polygon. |
centroid(coords: LatLngExpression[]) | LatLng | Returns the 'center of mass' of the passed LatLngs. |
I18n
Utility functions to deal with translations.
Translations of Maplair's built-in strings are maintained on
Transifex and published in the
i18n directory of the package. Load one before creating the map, see the example.
Usage example
import {I18n} from 'maplair';
import de from 'maplair/i18n/de.json' with {type: 'json'};
I18n.registerLocale('de', de);
I18n.setLocale('de');
Static members
| Method | Returns | Description |
|---|---|---|
registerLocale(locale: string, messages?: Record<string, string>) | void | Define localized strings for a given locale, defined by |
setLocale(locale: string | null) | void | Define or change the locale code to be used when translating strings. Note that changing the locale does not affect already instantiated objects. |
getLocale() | string | null | Returns the current locale code, that will be used when translating strings. |
translate(string: string, data?: Record<string, any>) | string | Actually try to translate the |
DomEvent
Functions
| Method | Returns | Description |
|---|---|---|
on(obj: EventTarget, types: string | Record<string, (ev: any) => void>, fn?: ((ev: any) => void) | object, context?: object) | void | Adds a listener function ( |
off(obj: EventTarget, types?: string | Record<string, (ev: any) => void>, fn?: ((ev: any) => void) | object, context?: object, …args: any[]) | void | Removes a previously added listener function.
Note that if you passed a custom context to on, you must pass the same
context to |
stopPropagation(e: Event | { originalEvent: Event; }) | void | Stop the given event from propagation to parent elements. Used inside the listener functions:
Also accepts a Maplair event with an |
disableScrollPropagation(el: HTMLElement) | void | Adds |
disableClickPropagation(el: HTMLElement) | void | Adds |
preventDefault(e: Event) | void | Prevents the default action of the DOM Event |
stop(e: Event) | void | Does |
getPointerPosition(e: MouseEvent | Touch, container?: HTMLElement) | Point | Gets normalized pointer position from a DOM event relative to the
|
getWheelPxFactor() | number | Gets the wheel pixel factor based on the devicePixelRatio. |
getWheelDelta(e: WheelEvent) | number | Gets normalized wheel delta from a wheel DOM event, in vertical pixels scrolled (negative if scrolling down). Events from pointing devices without precise scrolling are mapped to a best guess of 60 pixels. |
DomUtil
Functions
| Method | Returns | Description |
|---|---|---|
get(id: string | HTMLElement) | HTMLElement | null | Returns an element given its DOM id, or returns the element itself if it was passed directly. |
create(tagName: string, className?: string, container?: HTMLElement) | HTMLElement | Creates an HTML element with |
toFront(el: Element) | void | Makes |
toBack(el: Element) | void | Makes |
setTransform(el: HTMLElement | SVGElement, offset?: Point, scale?: number) | void | Resets the 3D CSS transform of |
setPosition(el: HTMLElement | SVGElement, point: Point, flat?: boolean) | void | Sets the position of |
getPosition(el: HTMLElement | SVGElement) | Point | Returns the coordinates of an element previously positioned with setPosition. |
disableImageDrag() | void | Prevents the user from generating |
enableImageDrag() | void | Cancels the effects of a previous
|
getSizedParentNode(element: HTMLElement) | HTMLElement | Finds the closest parent node which size (width and height) is not null. |
getScale(element: HTMLElement) | { x: number; y: number; boundingClientRect: DOMRect; } | Computes the CSS scale currently applied on the element.
Returns an object with |
Draggable extends Evented
A class for making DOM elements draggable. Used internally for map and marker dragging. Works on any DOM element.
Usage example
const draggable = new Draggable(elementToDrag);
draggable.enable();
Constructor
| Constructor | Description |
|---|---|
new Draggable(element: HTMLElement, dragStartTarget?: HTMLElement, options?: DraggableOptions) | Creates a |
Options
| Option | Type | Default | Description |
|---|---|---|---|
clickTolerance | number | 3 | The max number of pixels a user can shift the pointer during a click for it to be considered a valid click (as opposed to a pointer drag). |
Events
| Event | Data | Description |
|---|---|---|
down | MaplairEvent | Fired when a drag is about to start. |
dragstart | DraggableEvent | Fired when a drag starts. |
predrag | DraggableEvent | Fired continuously during dragging before each corresponding update of the element's position. |
drag | DraggableEvent | Fired continuously during dragging. |
dragend | DragEndEvent | Fired when the drag ends (with noInertia: true if the drag was finished without inertia, e.g. by disabling the draggable). |
Methods
| Method | Returns | Description |
|---|---|---|
enable() | void | Enables the dragging ability. |
disable() | void | Disables the dragging ability. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Class
Class powers the OOP facilities of Maplair and is used to create almost all of the Maplair classes documented here.
It implements a simple classical inheritance model using JavaScript's standard
extends keyword, and introduces several special properties for convenient code
organization — options and init hooks.
Options
options is a special property whose defaults, the static defaultOptions of the
class, are merged with those of the parent class instead of overriding them
completely, which makes managing configuration of objects and default values
convenient:
class MyClass extends Class {
static defaultOptions = {
myOption1: 'foo',
myOption2: 'bar'
};
}
class MyChildClass extends MyClass {
static defaultOptions = {
myOption1: 'baz',
myOption3: 5
};
}
const a = new MyChildClass();
a.options.myOption1; // 'baz'
a.options.myOption2; // 'bar'
a.options.myOption3; // 5
There's also Util.setOptions, a method for
conveniently merging options passed to constructor with the defaults
defined in the class:
class MyClass extends Class {
static defaultOptions = {
foo: 'bar',
bla: 5
};
constructor(options) {
super();
Util.setOptions(this, options);
...
}
}
const a = new MyClass({bla: 10});
a.options; // {foo: 'bar', bla: 10}
Note that the options object allows any keys, not just the options defined by the class and its base classes. This means you can use the options object to store application specific information, as long as you avoid keys that are already used by the class in question.
Mixins
You can add methods and properties from other objects using the include method
(such objects are called mixins):
const MyMixin = {
foo() { ... },
bar: 5
};
class MyClass extends Class {}
MyClass.include(MyMixin);
const a = new MyClass();
a.foo();
Constructor hooks
If you're a plugin developer, you often need to add additional initialization code
to existing classes (e.g. editing hooks for Polyline). Maplair comes with a way to
do it easily using the addInitHook method:
Polyline.addInitHook(function () {
// ... do something in constructor additionally
// e.g. add event listeners, set custom properties etc.
this.editing = new PolylineEditor(this);
});
You can also use the following shortcut when you just need to make one additional method call:
MyClass.addInitHook('methodName', arg1, arg2, …);
The hooks of a class run at the end of its constructor, which calls
callInitHooks — so they can rely on everything the
constructor sets up. All Maplair classes do so. Hooks of parent classes run
first, and parent classes without a constructor of their own (such as Layer
or Path) have their hooks run along with their subclasses. Each hook runs
once per object.
Note that the hooks of a parent class run before the constructor of a subclass
continues. To support hooks on your own classes, call this.callInitHooks()
at the end of their constructor:
class MyMarker extends Marker {
constructor(latlng, options) {
super(latlng, options); // runs the hooks of Marker (and of Layer etc.)
this.extra = 'ready';
this.callInitHooks(); // runs the hooks of MyMarker
}
}
Usage example
class MyClass extends Class {
constructor(greeter) {
super();
this.greeter = greeter;
this.callInitHooks(MyClass); // optional, see constructor hooks above
}
greet(name) {
alert(this.greeter + ', ' + name)
}
}
// create instance of MyClass, passing "Hello" to the constructor
const a = new MyClass("Hello");
// call greet method, alerting "Hello, World"
a.greet("World");
Methods
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Static members
| Method | Returns | Description |
|---|---|---|
include(props: object) | T | Includes a mixin into the current class: copies the properties
of |
mergeOptions(options: object) | T | Merges |
setDefaultOptions(options: object) | T | Use Deprecated alias of |
addInitHook(fn: ((this: any) => void) | string, …args: any[]) | T | Adds a constructor hook to the class: a function
(called with the object as
|
Evented extends Class
A set of methods shared between event-powered classes (like Map and Marker). Generally, events allow you to execute some function when something happens with an object (e.g. the user clicks on the map, causing the map to fire 'click' event).
Usage example
map.on('click', function(e) {
alert(e.latlng);
} );
Maplair deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function:
function onClick(e) { ... }
map.on('click', onClick);
map.off('click', onClick);
Methods
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Layer extends Evented
The base class of all Maplair layers, with the methods they share.
Every layer should extend from Layer and (re-)implement the following methods:
onAdd(map: MaplairMap): thisshould contain code that creates DOM elements for the layer, adds them tomap paneswhere they should belong and puts listeners on relevant map events. Called onmap.addLayer(layer).onRemove(map: MaplairMap): thisshould contain all clean up code that removes the layer's elements from the DOM and removes listeners previously added inonAdd. Called onmap.removeLayer(layer).getEvents(): Object(optional) should return an object like{ viewreset: this._reset }foron. The event handlers in this object will be automatically added and removed from the map with your layer.getAttribution(): String(optional) should return a string containing HTML to be shown on theAttribution controlwhenever the layer is visible.getLegend(): HTMLElement|String(optional) should return an element (or a string containing HTML) to be shown on theLegendControlwhenever the layer is visible. Firelegendchangeon the layer when the legend changes.beforeAdd(map: MaplairMap): this(optional) is called onmap.addLayer(layer), before the layer is added to the map, before events are initialized, without waiting until the map is in a usable state. Use for early initialization only.
Usage example
const layer = new Marker(latlng).addTo(map);
layer.addTo(map);
layer.remove();
Options
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
Popup methods
| Method | Returns | Description |
|---|---|---|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
Tooltip methods
| Method | Returns | Description |
|---|---|---|
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Other methods
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
onAdd(map: MaplairMap) | void | Should contain code that creates DOM
elements for the layer, adds them to |
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the layer's elements from the DOM and removes listeners previously added in
|
getEvents() | Record<string, Function> | Should return an object
like |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Properties
| Property | Type | Description |
|---|---|---|
feature | Feature | The GeoJSON feature the layer was created from (by
|
InteractiveLayerOptions extends LayerOptions
Options of interactive layers. Some layers can be made interactive - when the user
interacts with such a layer, pointer events like click and pointerover can be
handled. Use the event handling methods to handle these events.
Properties
| Option | Type | Default | Description |
|---|---|---|---|
interactive | boolean | true | If |
bubblingPointerEvents | boolean | true | When |
Properties inherited from LayerOptions
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Control extends Class
Base class for map controls such as ZoomControl, AttributionControl,
LayersControl and ScaleControl, which handles positioning them. Extend it to
create your own controls.
Every control should extend from Control and (re-)implement the following methods:
onAdd(map: MaplairMap): HTMLElementshould return the container DOM element for the control and add listeners on relevant map events. Called oncontrol.addTo(map).onRemove(map: MaplairMap)(optional) should contain all clean up code that removes the listeners previously added inonAdd. Called oncontrol.remove().getEvents(): Object(optional) should return an object like{zoomend: this._update}foron. The event handlers in this object will be automatically added and removed from the map with your control.
Constructor
| Constructor | Description |
|---|---|
new Control(options?: ControlOptions) |
Options
| Option | Type | Default | Description |
|---|---|---|---|
position | string | 'topright' | The position of the control (one of the map
corners). Possible values are |
order | number | 0 | The position of the control within its corner: controls with a lower order are closer to the corner of the map, those with the same order in the order of adding. |
Methods
| Method | Returns | Description |
|---|---|---|
getPosition() | string | Returns the position of the control. |
setPosition(position: string) | this | Sets the position of the control. |
getContainer() | HTMLElement | Returns the HTMLElement that contains the control. |
addTo(map: MaplairMap) | this | Adds the control to the given map. |
remove() | this | Removes the control from the map it is currently active on. |
onAdd(map: MaplairMap) | HTMLElement | Should return the container DOM
element for the control and add listeners on relevant map events. Called on
|
onRemove(map: MaplairMap) | void | Should contain all clean up code that
removes the listeners previously added in |
getEvents() | Record<string, Function> | Should return an object like
|
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Handler extends Class
Abstract class for map interaction handlers, the base class of the handlers that
are used internally to inject interaction features like dragging to classes like
MaplairMap and Marker.
Classes inheriting from Handler implement the two following extension methods:
addHooks()is called when the handler is enabled, should add event hooks.removeHooks()is called when the handler is disabled, should remove the event hooks added previously.
Constructor
| Constructor | Description |
|---|---|
new Handler(map: MaplairMap) |
|
Methods
| Method | Returns | Description |
|---|---|---|
enable() | this | Enables the handler. |
disable() | this | Disables the handler. |
enabled() | boolean | Returns |
addHooks() | void | Called when the handler is enabled, should add event hooks. |
removeHooks() | void | Called when the handler is disabled, should remove the event hooks added previously. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Static members
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap, name: string) | T | Adds a new handler of this class to the given map with the given name, which is then available as the property of the map with this name. |
Projection
BlanketOverlay extends Layer
Represents an HTML element that covers ("blankets") the entire surface of the map.
Do not use this class directly. It's meant for Renderer, and for plugins
that rely on one single HTML element.
Subclasses must define the following methods:
_initContainer()must initialize the HTML element to use as blanket, and store it asthis._container. The base implementation creates a blank<div>._destroyContainer()must destroy the HTML element inthis._containerand free any other resources. The base implementation destroys the element and removes any event handlers attached to it._resizeContainer(): Point: the base implementation resizes the container (based on the map's size and taking into account the padding), returning the new size in CSS pixels. Subclass implementations shall reset container parameters and data structures as needed._onZoomEnd(ev?: PointerEvent)(optional) runs on the map'szoomendevent._onViewReset(ev?: PointerEvent)(optional) runs on the map'sviewresetevent._onSettled()runs whenever the map state settles after changing (at the end of pan/zoom animations, etc). This should trigger the bulk of any rendering logic. If thecontinuousoption is set totrue, then this also runs on any map state change (including during pan/zoom animations).
Constructor
| Constructor | Description |
|---|---|
new BlanketOverlay(options?: BlanketOverlayOptions) |
Options
| Option | Type | Default | Description |
|---|---|---|---|
padding | number | 0.1 | How much to extend the clip area around the map view (relative to its size) e.g. 0.1 would be 10% of map view in each direction. |
continuous | boolean | false | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | |
onRemove(map: MaplairMap) | void | |
getEvents() | Record<string, EventListener> | Returns the map events the blanket listens to. |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
Renderer extends BlanketOverlay
Base class for vector renderer implementations (SVG, Canvas). Handles the
DOM container of the renderer, its bounds, and its zoom animation.
A Renderer works as an implicit layer group for all Paths - the renderer
itself can be added or removed to the map. All paths use a renderer, which can
be implicit (the map will decide the type of renderer and use it automatically)
or explicit (using the renderer option of the path).
Do not use this class directly, use SVG and Canvas instead.
The continuous option inherited from BlanketOverlay cannot be set to true
(otherwise, renderers get out of place during a pinch-zoom operation).
Constructor
| Constructor | Description |
|---|---|
new Renderer(options?: RendererOptions) |
Options
Options inherited from BlanketOverlay
| Option | Type | Default | Description |
|---|---|---|---|
padding | number | 0.1 | How much to extend the clip area around the map view (relative to its size) e.g. 0.1 would be 10% of map view in each direction. |
continuous | boolean | false | When |
Options inherited from Layer
| Option | Type | Default | Description |
|---|---|---|---|
pane | string | 'overlayPane' | By default the layer will be added to the
map's overlay pane ( |
attribution | string|null | null | String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
attributionOrder | number | 0 | The position of the attribution in the
attribution control: attributions are sorted by it, then by the order of adding,
e.g. |
Events
| Event | Data | Description |
|---|---|---|
update | MaplairEvent | Fired when the renderer updates its bounds, center and zoom, for example when its map has moved. |
Events inherited from Layer
| Event | Data | Description |
|---|---|---|
add | MaplairEvent | Fired after the layer is added to a map. |
remove | MaplairEvent | Fired after the layer is removed from a map. |
click | MaplairPointerEvent | Fired when the user clicks (or taps) the layer, if it is interactive. |
dblclick | MaplairPointerEvent | Fired when the user double-clicks (or double-taps) the layer, if it is interactive. |
pointerdown | MaplairPointerEvent | Fired when the user pushes the pointer on the layer, if it is interactive. |
pointerup | MaplairPointerEvent | Fired when the user releases the pointer pushed on the layer, if it is interactive. |
pointerover | MaplairPointerEvent | Fired when the pointer enters the layer, if it is interactive. |
pointerout | MaplairPointerEvent | Fired when the pointer leaves the layer, if it is interactive. |
contextmenu | MaplairPointerEvent | Fired when the user right-clicks on the layer, if it is interactive; prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
popupopen | PopupEvent | Fired when a popup bound to this layer is opened. |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed. |
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. |
Methods
| Method | Returns | Description |
|---|---|---|
onRemove() | void | Removes the container of the renderer from the map. |
Methods inherited from BlanketOverlay
| Method | Returns | Description |
|---|---|---|
onAdd(map: MaplairMap) | void | |
getEvents() | Record<string, EventListener> | Returns the map events the blanket listens to. |
Methods inherited from Layer
| Method | Returns | Description |
|---|---|---|
addTo(map: MaplairMap | LayerGroup) | this | Adds the layer to the given map or layer group. |
remove() | this | Removes the layer from the map it is currently active on. |
removeFrom(obj: MaplairMap | LayerGroup) | this | Removes the layer from the given map or |
getPane(name?: string) | HTMLElement | Returns the |
setInteractive(interactive: boolean) | this | Changes the |
addInteractiveTarget(targetEl: HTMLElement) | this | Registers |
removeInteractiveTarget(targetEl: HTMLElement) | this | Undoes |
getAttribution() | string | null | Used by the |
setAttribution(attribution: string | null) | this | Changes the attribution option, also in the attribution control while the layer is on the map. |
getLegend() | HTMLElement|string | Should return an element (or a string
containing HTML) to be shown on the |
beforeAdd(map: MaplairMap) | void | Called on
|
bindPopup(content: DivOverlayContent | Popup, options?: PopupOptions) | this | Binds a popup to the layer with the passed |
unbindPopup() | this | Removes the popup previously bound with |
openPopup(latlng?: LatLngExpression) | this | Opens the bound popup at the specified |
closePopup() | this | Closes the popup bound to this layer if it is open. |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() | boolean | Returns |
setPopupContent(content: DivOverlayContent) | this | Sets the content of the popup bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getPopup() | Popup | undefined | Returns the popup bound to this layer. |
bindTooltip(content: DivOverlayContent | Tooltip, options?: TooltipOptions) | this | Binds a tooltip to the layer with the passed |
unbindTooltip() | this | Removes the tooltip previously bound with |
openTooltip(latlng?: LatLngExpression) | this | Opens the bound tooltip at the specified |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() | boolean | Returns |
setTooltipContent(content: DivOverlayContent) | this | Sets the content of the tooltip bound to this layer. String content is rendered
as HTML; sanitize untrusted input or pass an |
getTooltip() | Tooltip | undefined | Returns the tooltip bound to this layer. |
Methods inherited from Evented
| Method | Returns | Description |
|---|---|---|
on(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Adds a listener function ( |
off(types?: string | Record<string, EventListener>, fn?: EventListener | object, context?: object, …args: any[]) | this | Removes a previously added listener function. If no function is specified, it will
remove all the listeners of that particular event from the object. Note that if you
passed a custom context to |
fire(type: string, data?: object, propagate?: boolean) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. |
listens(type: string, fn?: EventListener | boolean, context?: object, propagate?: boolean) | boolean | Returns |
once(types: string | Record<string, EventListener>, fn?: EventListener | object, context?: object) | this | Behaves as |
addEventParent(obj: Evented) | this | Adds an event parent - an |
removeEventParent(obj: Evented) | this | Removes an event parent, so it will stop receiving propagated events. |
Methods inherited from Class
| Method | Returns | Description |
|---|---|---|
callInitHooks(cls?: Function) | this | Runs the constructor hooks of the given class and
of its parent classes, which haven't run yet for this object. Classes call it
at the end of their constructor, e.g. |
CRS
Object that defines coordinate reference systems for projecting geographical points into pixel (screen) coordinates and back (and to coordinates in other units for WMS services). See spatial reference system.
Maplair defines the most usual CRSs by default. If you want to use a
CRS not defined by default, extend CRS with a projection of your own, e.g.
based on Proj4js (the Leaflet plugin
Proj4Leaflet doesn't work with Maplair).
The CRSs are classes with static properties and methods only; they are not
instantiated, the class itself is passed as the CRS, e.g. to the crs option of the
map. Maplair's CRSs extend CRS (EarthCRS for the global ones).
Besides the properties and methods below, a CRS may define:
code: string: Standard code name of the CRS passed into WMS services (e.g.'EPSG:3857').wrapLng: [number, number]: An array of two numbers defining whether the longitude (horizontal) coordinate axis wraps around a given range and how. Defaults to[-180, 180]in most geographical CRSs. Ifundefined, the longitude axis does not wrap around.wrapLat: [number, number]: LikewrapLng, but for the latitude (vertical) axis.distance(latlng1: LatLng, latlng2: LatLng): number: Returns the distance between two geographical coordinates.
Static members
| Method | Returns | Description |
|---|---|---|
latLngToPoint(latlng: LatLngExpression, zoom: number) | Point | Projects geographical coordinates into pixel coordinates for a given zoom. |
pointToLatLng(point: Point, zoom: number) | LatLng | The inverse of |
project(latlng: LatLngExpression) | Point | Projects geographical coordinates into coordinates in units accepted for this CRS (e.g. meters for EPSG:3857, for passing it to WMS services). |
unproject(point: Point) | LatLng | Given a projected coordinate returns the corresponding LatLng.
The inverse of |
scale(zoom: number) | number | Returns the scale used when transforming projected coordinates into
pixel coordinates for a particular zoom. For example, it returns
|
zoom(scale: number) | number | Inverse of |
getProjectedBounds(zoom: number) | Bounds | null | Returns the projection's bounds scaled and transformed for the provided |
wrapLatLng(latlng: LatLngExpression) | LatLng | Returns a |
wrapLatLngBounds(bounds: LatLngBoundsExpression) | LatLngBounds | Returns a |
| Property | Type | Description |
|---|---|---|
projection | Projection | undefined | The projection of the CRS. |
transformation | Transformation | undefined | The transformation of projected coordinates into pixel coordinates at zoom 0. |
infinite | boolean | If true, the coordinate space will be unbounded (infinite in both axes). |
EarthCRS extends CRS
Serves as the base for CRS that are global such that they cover the earth.
Can only be used as the base for other CRS and cannot be used directly,
since it does not have a code, projection or transformation. distance() returns
meters.
Static members
| Method | Returns | Description |
|---|---|---|
distance(latlng1: LatLng, latlng2: LatLng) | number | Returns the distance in meters between two geographical points using the Haversine approximation. |
| Property | Type | Description |
|---|---|---|
wrapLng | [number, number] | The range around which the longitude axis wraps. |
R | number | Mean Earth Radius in meters, as recommended for use by the International Union of Geodesy and Geophysics, see https://rosettacode.org/wiki/Haversine_formula |
EPSG3857 extends EarthCRS
The most common CRS for online maps, used by almost all free and commercial
tile providers. Uses Spherical Mercator projection. Set in by default in
Map's crs option.
Static members
| Property | Type | Description |
|---|---|---|
code | string | |
projection | Projection | |
transformation | Transformation |
EPSG900913 extends EPSG3857
The same as EPSG3857, with its former unofficial code EPSG:900913.
EPSG3395 extends EarthCRS
Rarely used by some commercial tile providers. Uses Elliptical Mercator projection.
Static members
| Property | Type | Description |
|---|---|---|
code | string | |
projection | Projection | |
transformation | Transformation |
EPSG4326 extends EarthCRS
A common CRS among GIS enthusiasts. Uses simple Equirectangular projection.
Maplair complies with the
TMS coordinate scheme for EPSG:4326.
If you are using a TileLayer with this CRS, ensure that there are two 256x256
pixel tiles covering the whole earth at zoom level zero, and that the tile
coordinate origin is (-180,+90), or (-180,-90) for TileLayers with
the tms option set.
Static members
| Property | Type | Description |
|---|---|---|
code | string | |
projection | Projection | |
transformation | Transformation |
SimpleCRS extends CRS
A simple CRS that maps longitude and latitude into x and y directly.
May be used for maps of flat surfaces (e.g. game maps). Note that the y
axis should still be inverted (going from bottom to top). distance() returns
simple euclidean distance.
Static members
| Method | Returns | Description |
|---|---|---|
distance(latlng1: LatLng, latlng2: LatLng) | number | Returns the euclidean distance between two points. |
| Property | Type | Description |
|---|---|---|
projection | Projection | |
transformation | Transformation |
MaplairEvent
The base event object, the argument of event listeners. All other event objects
contain these properties too. Whenever a class inheriting from Evented fires an
event, a listener function is called with an event object containing information
about the event, which depends on the event type. For example:
map.on('click', function(ev) {
alert(ev.latlng); // ev is an event object (MaplairPointerEvent in this case)
});
Properties
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
EventListener
A listener of events, called with the event object, which has more properties depending on the event type (see the event objects below).
type EventListener = (event: MaplairEvent & Record<string, any>) => void
MaplairPointerEvent extends MaplairEvent
The event object of pointer events (click, pointermove, …).
Properties
| Property | Type | Description |
|---|---|---|
latlng | LatLng | The geographical point where the pointer event occurred. |
layerPoint | Point | Pixel coordinates of the point where the pointer event occurred relative to the map layer. |
containerPoint | Point | Pixel coordinates of the point where the pointer event occurred relative to the map container. |
originalEvent | MouseEvent|PointerEvent | The original
DOM |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
MaplairKeyboardEvent extends MaplairEvent
The event object of keyboard events.
Properties
| Property | Type | Description |
|---|---|---|
originalEvent | KeyboardEvent | The original
DOM |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
LocationEvent extends MaplairEvent
The event object of locationfound.
Properties
| Property | Type | Description |
|---|---|---|
latlng | LatLng | Detected geographical location of the user. |
bounds | LatLngBounds | Geographical bounds of the area user is located in (with respect to the accuracy of location). |
accuracy | number | Accuracy of location in meters. |
altitude | number | Height of the position above the WGS84 ellipsoid in meters. |
altitudeAccuracy | number | Accuracy of altitude in meters. |
heading | number | The direction of travel in degrees counting clockwise from true North. |
speed | number | Current velocity in meters per second. |
timestamp | number | The time when the position was acquired. |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
MaplairErrorEvent extends MaplairEvent
The event object of errors, e.g. locationerror.
Properties
| Property | Type | Description |
|---|---|---|
message | string | Error message. |
code | number | Error code (if applicable). |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
LayerEvent extends MaplairEvent
The event object of adding and removing layers.
Properties
| Property | Type | Description |
|---|---|---|
layer | Layer | The layer that was added or removed. |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
LayersControlEvent extends MaplairEvent
The event object of the layers control.
Properties
| Property | Type | Description |
|---|---|---|
layer | Layer | The layer that was added or removed. |
name | string | The name of the layer that was added or removed. |
originalEvent | Event | The DOM event of the click on the entry in the
layers control, |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
SearchResultEvent extends MaplairEvent
The event object of searchresult.
Properties
| Property | Type | Description |
|---|---|---|
result | SearchResult | The selected result. |
latlng | LatLng | The position of the result. |
bounds | LatLngBounds|undefined | The extent of the result, if any. |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
TileEvent extends MaplairEvent
The event object of tile events.
Properties
| Property | Type | Description |
|---|---|---|
tile | HTMLElement | The tile element (image). |
coords | Point | Point object with the tile's |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
TileErrorEvent extends TileEvent
The event object of tileerror.
Properties
| Property | Type | Description |
|---|---|---|
error | any | Error passed to the tile's |
Properties inherited from TileEvent
| Property | Type | Description |
|---|---|---|
tile | HTMLElement | The tile element (image). |
coords | Point | Point object with the tile's |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
ResizeEvent extends MaplairEvent
The event object of resize.
Properties
| Property | Type | Description |
|---|---|---|
oldSize | Point | The old size before resize event. |
newSize | Point | The new size after the resize event. |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
CrsChangeEvent extends MaplairEvent
The event object of crschange.
Properties
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
GeoJSONEvent extends MaplairEvent
The event object of adding GeoJSON features.
Properties
| Property | Type | Description |
|---|---|---|
layer | Layer | The layer for the GeoJSON feature that is being added to the map. |
properties | object | GeoJSON properties of the feature. |
geometryType | string | GeoJSON geometry type of the feature. |
id | string|number | GeoJSON ID of the feature (if present). |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
PopupEvent extends MaplairEvent
The event object of opening and closing popups.
Properties
| Property | Type | Description |
|---|---|---|
popup | Popup | The popup that was opened or closed. |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
TooltipEvent extends MaplairEvent
The event object of opening and closing tooltips.
Properties
| Property | Type | Description |
|---|---|---|
tooltip | Tooltip | The tooltip that was opened or closed. |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
DragEndEvent extends MaplairEvent
The event object of dragend.
Properties
| Property | Type | Description |
|---|---|---|
distance | number | The distance in pixels the draggable element was moved by. |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
ZoomAnimEvent extends MaplairEvent
The event object of zoomanim.
Properties
| Property | Type | Description |
|---|---|---|
center | LatLng | The current center of the map. |
zoom | number | The current zoom level of the map. |
noUpdate | boolean | Whether layers should update their contents due to this event. |
Properties inherited from MaplairEvent
| Property | Type | Description |
|---|---|---|
type | string | The event type (e.g. |
target | any | The object that fired the event. For propagated events, the last object in the propagation chain that fired the event. |
sourceTarget | any | The object that originally fired the event. For
non-propagated events, this will be the same as the |
propagatedFrom | any | For propagated events, the last object that propagated the event to its event parent. |
LatLngExpression
A geographical point: a LatLng, an array of the form [lat, lng] or
[lat, lng, alt], or a plain object of the form {lat, lng} or {lat, lng, alt}
(lon can be used in place of lng). Accepted by all Maplair methods which accept
LatLng objects (unless noted otherwise). Plain arrays (number[]) are accepted
for JavaScript, where array literals in variables are no tuples.
type LatLngExpression = LatLng | [number, number] | [number, number, number] | number[] | { lat: number; lng: number; alt?: number; } | { lat: number; lon: number; alt?: number; }
LatLngBoundsExpression
A geographical area: a LatLngBounds, or an array of geographical points (usually
two diagonally opposite corners), e.g. [[40.712, -74.227], [40.774, -74.125]].
Accepted by all Maplair methods which accept LatLngBounds objects (unless noted
otherwise).
type LatLngBoundsExpression = LatLngBounds | LatLngExpression[]
PointExpression
A point in pixels: a Point, an array of the form [x, y], or a plain object of
the form {x, y}. Accepted by all Maplair methods and options which accept Point
objects (unless noted otherwise).
type PointExpression = Point | [number, number] | number[] | { x: number; y: number; }
BoundsExpression
A rectangular area in pixel coordinates: a Bounds, or an array of points (usually
two diagonally opposite corners), e.g. [[10, 10], [40, 60]]. Accepted by all
Maplair methods which accept Bounds objects (unless noted otherwise).
type BoundsExpression = Bounds | PointExpression[]
ZoomOptions
Options of the MaplairMap methods which modify the zoom level.
Properties
| Property | Type | Description |
|---|---|---|
animate | boolean | If not specified, zoom animation will happen if the
zoom origin is inside the current view, and if the user prefers reduced motion, only
when zooming by at most one level. If |
PanOptions
Options of the MaplairMap methods which modify the center of the map.
Properties
| Option | Type | Default | Description |
|---|---|---|---|
animate | boolean | If | |
duration | number | 0.25 | Duration of animated panning, in seconds. |
easeLinearity | number | 0.25 | The curvature factor of panning animation easing (third parameter of the Cubic Bezier curve). 1.0 means linear animation, and the smaller this number, the more bowed the curve. |
noMoveStart | boolean | false | If |
ZoomPanOptions extends ZoomOptions, PanOptions
Options of the MaplairMap methods which modify the zoom level and the center.
Properties
| Property | Type | Description |
|---|---|---|
animate | boolean | Whether to animate the change: like |
reset | boolean | If |
zoom | ZoomOptions | Options for the zoom part of the change, taking
precedence over |
pan | PanOptions | Options for the pan part of the change, taking
precedence over |
Properties inherited from ZoomOptions
| Property | Type | Description |
|---|---|---|
animate | boolean | If not specified, zoom animation will happen if the
zoom origin is inside the current view, and if the user prefers reduced motion, only
when zooming by at most one level. If |
Properties inherited from PanOptions
| Property | Type | Description |
|---|---|---|
animate | boolean | If |
duration | number | Duration of animated panning, in seconds. |
easeLinearity | number | The curvature factor of panning animation easing (third parameter of the Cubic Bezier curve). 1.0 means linear animation, and the smaller this number, the more bowed the curve. |
noMoveStart | boolean | If |
FitBoundsOptions extends ZoomPanOptions, PaddingOptions
Options of MaplairMap.fitBounds() and similar methods.
Properties
| Option | Type | Default | Description |
|---|---|---|---|
maxZoom | number|null | null | The maximum possible zoom to use. |
Properties inherited from ZoomPanOptions
| Option | Type | Default | Description |
|---|---|---|---|
animate | boolean | Whether to animate the change: like | |
reset | boolean | If | |
zoom | ZoomOptions | Options for the zoom part of the change, taking
precedence over | |
pan | PanOptions | Options for the pan part of the change, taking
precedence over |
Properties inherited from PaddingOptions
| Option | Type | Default | Description |
|---|---|---|---|
paddingTopLeft | PointExpression | [0, 0] | Sets the amount of padding in the top left corner of a map container that shouldn't be accounted for when setting the view to fit bounds. Useful if you have some control overlays on the map like a sidebar and you don't want them to obscure objects you're zooming to. |
paddingBottomRight | PointExpression | [0, 0] | The same for the bottom right corner of the map. |
padding | PointExpression | [0, 0] | Equivalent of setting both top left and bottom right padding to the same value. |
Properties inherited from ZoomOptions
| Option | Type | Default | Description |
|---|---|---|---|
animate | boolean | If not specified, zoom animation will happen if the
zoom origin is inside the current view, and if the user prefers reduced motion, only
when zooming by at most one level. If |
Properties inherited from PanOptions
| Option | Type | Default | Description |
|---|---|---|---|
animate | boolean | If | |
duration | number | 0.25 | Duration of animated panning, in seconds. |
easeLinearity | number | 0.25 | The curvature factor of panning animation easing (third parameter of the Cubic Bezier curve). 1.0 means linear animation, and the smaller this number, the more bowed the curve. |
noMoveStart | boolean | false | If |
InvalidateSizeOptions extends PanOptions
Options of MaplairMap.invalidateSize().
Properties
| Option | Type | Default | Description |
|---|---|---|---|
animate | boolean | false | If |
pan | boolean | true | If |
debounceMoveend | boolean | false | If |
Properties inherited from PanOptions
| Option | Type | Default | Description |
|---|---|---|---|
animate | boolean | If | |
duration | number | 0.25 | Duration of animated panning, in seconds. |
easeLinearity | number | 0.25 | The curvature factor of panning animation easing (third parameter of the Cubic Bezier curve). 1.0 means linear animation, and the smaller this number, the more bowed the curve. |
noMoveStart | boolean | false | If |
LocateOptions
Options of the geolocation methods of MaplairMap, e.g. locate().
Properties
| Option | Type | Default | Description |
|---|---|---|---|
watch | boolean | false | If |
setView | boolean | false | If |
maxZoom | number | Infinity | The maximum zoom for automatic view setting
when using |
timeout | number | 10000 | Number of milliseconds to wait for a response from
geolocation before firing a |
maximumAge | number | 0 | Maximum age of detected location. If less than this
amount of milliseconds passed since last geolocation response, |
enableHighAccuracy | boolean | false | Enables high accuracy, see description in the W3C spec. |
PaddingOptions
Padding options of MaplairMap methods, e.g. panInside().
Properties
| Option | Type | Default | Description |
|---|---|---|---|
paddingTopLeft | PointExpression | [0, 0] | Sets the amount of padding in the top left corner of a map container that shouldn't be accounted for when setting the view to fit bounds. Useful if you have some control overlays on the map like a sidebar and you don't want them to obscure objects you're zooming to. |
paddingBottomRight | PointExpression | [0, 0] | The same for the bottom right corner of the map. |
padding | PointExpression | [0, 0] | Equivalent of setting both top left and bottom right padding to the same value. |
SearchResult
A result of a search, returned by a geocoder.
Properties
| Property | Type | Description |
|---|---|---|
label | string | The text shown in the list of results, e.g. an address. |
latlng | LatLngExpression | The position of the result. |
bounds | LatLngBoundsExpression | The extent of the result, e.g. of a city, which the map fits to instead of zooming to the position. |
raw | any | The original result of the service, for use in event listeners. |
layer | Layer | The found layer, by |
Geocoder
A function searching places for a query, see the geocoder
option. It should pass the signal to fetch(): searches are aborted when the user
starts another one. Optional properties of the function: attribution, an attribution
text which the control adds to the map, and autoComplete: false if the service
forbids searching while typing (overriding the
autoComplete option).
type Geocoder = ((query: string, options: { signal: AbortSignal; }) => Promise<SearchResult[]>) & { attribution?: string; autoComplete?: boolean; }
version
A constant that represents the Maplair version in use.
Properties
| Property | Type | Description |
|---|---|---|
version | string | A constant that represents the Maplair version in use. |