MapLibre

API Reference (beta) for <MapLibre />

Property Type Description
map
optional bindable
Map
-
class
optional
string
-
default: ""
inlineStyle
optional
string
Inline CSS `style` for the map container HTML element. Not to be confused with the map's style settings.
default: ""
center
optional bindable
LngLat | {
  lng: number,
  lat: number
} | {
  lon: number,
  lat: number
} | [number, number]
The initial geographical centerpoint of the map. If `center` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `[0, 0]` Note: MapLibre GL JS uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
padding
optional
PaddingOptions
-
fov
optional
number
Vertical field of view in degrees
cursor
optional
string
-
autoloadGlobalCss
optional
boolean
Loads and applies maplibre-gl.css from a CDN. Set to false if you want to include it manually.
default: true
showTileBoundaries
optional
boolean
-
showPadding
optional
boolean
-
showCollisionBoxes
optional
boolean
-
showOverdrawInspector
optional
boolean
-
repaint
optional
boolean
-
vertices
optional
boolean
-
children
optional
Snippet<[]>
-
bearing
optional bindable
number
The initial bearing (rotation) of the map, measured in degrees counter-clockwise from north. If `bearing` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
elevation
optional bindable
number
The elevation of the initial geographical centerpoint of the map, in meters above sea level. If `elevation` is not specified in the constructor options, it will default to `0`.
pitch
optional bindable
number
The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-85). If `pitch` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`. Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
roll
optional bindable
number
The initial roll angle of the map, measured in degrees counter-clockwise about the camera boresight. If `roll` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
zoom
optional bindable
number
The initial zoom level of the map. If `zoom` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
hash
optional
string | boolean
If `true`, the map's position (zoom, center latitude, center longitude, bearing, and pitch) will be synced with the hash fragment of the page's URL. For example, `http://path/to/my/page.html#2.59/39.26/53.07/-24.1/60`. An additional string may optionally be provided to indicate a parameter-styled hash, e.g. http://path/to/my/page.html#map=2.59/39.26/53.07/-24.1/60&foo=bar, where foo is a custom parameter and bar is an arbitrary hash distinct from the map hash.
interactive
optional
boolean
If `false`, no mouse, touch, or keyboard listeners will be attached to the map, so it will not respond to interaction.
bearingSnap
optional
number
The threshold, measured in degrees, that determines when the map's bearing will snap to north. For example, with a `bearingSnap` of 7, if the user rotates the map within 7 degrees of north, the map will automatically snap to exact north.
attributionControl
optional
false | AttributionControlOptions
If set, an will be added to the map with the provided options. To disable the attribution control, pass `false`. Note: showing the logo of MapLibre is not required for using MapLibre.
maplibreLogo
optional
boolean
If `true`, the MapLibre logo will be shown.
logoPosition
optional
"top-left" | "top-right" | "bottom-left" | "bottom-right"
A string representing the position of the MapLibre wordmark on the map. Valid options are `top-left`,`top-right`, `bottom-left`, or `bottom-right`.
canvasContextAttributes
optional
WebGLContextAttributesWithType
Set of WebGLContextAttributes that are applied to the WebGL context of the map. See https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext for more details. `contextType` can be set to `webgl2` or `webgl` to force a WebGL version. Not setting it, Maplibre will do it's best to get a suitable context.
refreshExpiredTiles
optional
boolean
If `false`, the map won't attempt to re-request tiles once they expire per their HTTP `cacheControl`/`expires` headers.
maxBounds
optional
LngLatBounds | [LngLat | {
  lng: number,
  lat: number
} | {
  lon: number,
  lat: number
} | [number, number], LngLat | {
  lng: number,
  lat: number
} | {
  lon: number,
  lat: number
} | [number, number]] | [number, number, number, number]
If set, the map will be constrained to the given bounds.
scrollZoom
optional
boolean | AroundCenterOptions
If `true`, the "scroll to zoom" interaction is enabled. are passed as options to .
minZoom
optional
number | null
The minimum zoom level of the map (0-24).
maxZoom
optional
number | null
The maximum zoom level of the map (0-24).
minPitch
optional
number | null
The minimum pitch of the map (0-180).
maxPitch
optional
number | null
The maximum pitch of the map (0-180).
boxZoom
optional
boolean
If `true`, the "box zoom" interaction is enabled (see ).
dragRotate
optional
boolean
If `true`, the "drag to rotate" interaction is enabled (see ).
dragPan
optional
boolean | DragPanOptions
If `true`, the "drag to pan" interaction is enabled. An `Object` value is passed as options to .
keyboard
optional
boolean
If `true`, keyboard shortcuts are enabled (see ).
doubleClickZoom
optional
boolean
If `true`, the "double click to zoom" interaction is enabled (see ).
touchZoomRotate
optional
boolean | AroundCenterOptions
If `true`, the "pinch to rotate and zoom" interaction is enabled. An `Object` value is passed as options to .
touchPitch
optional
boolean | AroundCenterOptions
If `true`, the "drag to pitch" interaction is enabled. An `Object` value is passed as options to .
cooperativeGestures
optional
boolean
If `true` or set to an options object, the map is only accessible on desktop while holding Command/Ctrl and only accessible on mobile with two fingers. Interacting with the map using normal gestures will trigger an informational screen. With this option enabled, "drag to pitch" requires a three-finger gesture. Cooperative gestures are disabled when a map enters fullscreen using .
trackResize
optional
boolean
If `true`, the map will automatically resize when the browser window resizes.
renderWorldCopies
optional
boolean
If `true`, multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude. If set to `false`: - When the map is zoomed out far enough that a single representation of the world does not fill the map's entire container, there will be blank space beyond 180 and -180 degrees longitude. - Features that cross 180 and -180 degrees longitude will be cut in two (with one portion on the right edge of the map and the other on the left edge of the map) at every zoom level.
maxTileCacheSize
optional
number | null
The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport which can be set using `maxTileCacheZoomLevels` constructor options.
maxTileCacheZoomLevels
optional
number
The maximum number of zoom levels for which to store tiles for a given source. Tile cache dynamic size is calculated by multiplying `maxTileCacheZoomLevels` with the approximate number of tiles in the viewport for a given source.
transformRequest
optional
RequestTransformFunction() | null
A callback run before the Map makes a request for an external URL. The callback can be used to modify the url, set headers, or set the credentials property for cross-origin requests. Expected to return an object with a `url` property and optionally `headers` and `credentials` properties.
transformCameraUpdate
optional
CameraUpdateTransformFunction() | null
A callback run before the map's camera is moved due to user input or animation. The callback can be used to modify the new center, zoom, pitch and bearing. Expected to return an object containing center, zoom, pitch or bearing values to overwrite.
locale
optional
any
A patch to apply to the default localization table for UI strings, e.g. control tooltips. The `locale` object maps namespaced UI string IDs to translated strings in the target language; see `src/ui/default_locale.js` for an example with all supported string IDs. The object may specify all UI strings (thereby adding support for a new translation) or only a subset of strings (thereby patching the default translation table).
fadeDuration
optional
number
Controls the duration of the fade-in/fade-out animation for label collisions after initial map load, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading.
crossSourceCollisions
optional
boolean
If `true`, symbols from multiple sources can collide with each other during collision detection. If `false`, collision detection is run separately for the symbols in each source.
collectResourceTiming
optional
boolean
If `true`, Resource Timing API information will be collected for requests made by GeoJSON and Vector Tile web workers (this information is normally inaccessible from the main Javascript thread). Information will be returned in a `resourceTiming` property of relevant `data` events.
clickTolerance
optional
number
The max number of pixels a user can shift the mouse pointer during a click for it to be considered a valid click (as opposed to a mouse drag).
bounds
optional
LngLatBounds | [LngLat | {
  lng: number,
  lat: number
} | {
  lon: number,
  lat: number
} | [number, number], LngLat | {
  lng: number,
  lat: number
} | {
  lon: number,
  lat: number
} | [number, number]] | [number, number, number, number]
The initial bounds of the map. If `bounds` is specified, it overrides `center` and `zoom` constructor options.
fitBoundsOptions
optional
FitBoundsOptions
A options object to use _only_ when fitting the initial `bounds` provided above.
localIdeographFontFamily
optional
string | false
Defines a CSS font-family for locally overriding generation of Chinese, Japanese, and Korean characters. For these characters, font settings from the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold). Set to `false`, to enable font settings from the map's style for these glyph ranges. The purpose of this option is to avoid bandwidth-intensive glyph server requests. (See [Use locally generated ideographs](https://maplibre.org/maplibre-gl-js/docs/examples/local-ideographs).)
style
optional
string | StyleSpecification
The map's MapLibre style. This must be a JSON object conforming to the schema described in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/), or a URL to such JSON. When the style is not specified, calling is required to render the map.
pitchWithRotate
optional
boolean
If `false`, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled.
rollEnabled
optional
boolean
If `false`, the map's roll control with "drag to rotate" interaction will be disabled.
pixelRatio
optional
number
The pixel ratio. The canvas' `width` attribute will be `container.clientWidth * pixelRatio` and its `height` attribute will be `container.clientHeight * pixelRatio`. Defaults to `devicePixelRatio` if not specified.
validateStyle
optional
boolean
If false, style validation will be skipped. Useful in production environment.
maxCanvasSize
optional
[number, number]
The canvas' `width` and `height` max size. The values are passed as an array where the first element is max width and the second element is max height. You shouldn't set this above WebGl `MAX_TEXTURE_SIZE`.
cancelPendingTileRequestsWhileZooming
optional
boolean
Determines whether to cancel, or retain, tiles from the current viewport which are still loading but which belong to a farther (smaller) zoom level than the current one. * If `true`, when zooming in, tiles which didn't manage to load for previous zoom levels will become canceled. This might save some computing resources for slower devices, but the map details might appear more abruptly at the end of the zoom. * If `false`, when zooming in, the previous zoom level(s) tiles will progressively appear, giving a smoother map details experience. However, more tiles will be rendered in a short period of time.
centerClampedToGround
optional
boolean
If true, the elevation of the center point will automatically be set to the terrain elevation (or zero if terrain is not enabled). If false, the elevation of the center point will default to sea level and will not automatically update. Defaults to true. Needs to be set to false to keep the camera above ground when pitch \> 90 degrees.
onerror
optional
(ev: ErrorEvent) => void
-
onload
optional
(ev: MapLibreEvent<unknown>) => void
-
onidle
optional
(ev: MapLibreEvent<unknown>) => void
-
onremove
optional
(ev: MapLibreEvent<unknown>) => void
-
onrender
optional
(ev: MapLibreEvent<unknown>) => void
-
onresize
optional
(ev: MapLibreEvent<unknown>) => void
-
onwebglcontextlost
optional
(ev: MapContextEvent) => void
-
onwebglcontextrestored
optional
(ev: MapContextEvent) => void
-
ondataloading
optional
(ev: MapDataEvent) => void
-
ondata
optional
(ev: MapDataEvent) => void
-
ontiledataloading
optional
(ev: MapDataEvent) => void
-
onsourcedataloading
optional
(ev: MapSourceDataEvent) => void
-
onstyledataloading
optional
(ev: MapStyleDataEvent) => void
-
onsourcedata
optional
(ev: MapSourceDataEvent) => void
-
onstyledata
optional
(ev: MapStyleDataEvent) => void
-
onstyleimagemissing
optional
(ev: MapStyleImageMissingEvent) => void
-
ondataabort
optional
(ev: MapDataEvent) => void
-
onsourcedataabort
optional
(ev: MapSourceDataEvent) => void
-
onboxzoomcancel
optional
(ev: MapLibreZoomEvent) => void
-
onboxzoomstart
optional
(ev: MapLibreZoomEvent) => void
-
onboxzoomend
optional
(ev: MapLibreZoomEvent) => void
-
ontouchcancel
optional
(ev: MapTouchEvent) => void
-
ontouchmove
optional
(ev: MapTouchEvent) => void
-
ontouchend
optional
(ev: MapTouchEvent) => void
-
ontouchstart
optional
(ev: MapTouchEvent) => void
-
onclick
optional
(ev: MapMouseEvent) => void
-
oncontextmenu
optional
(ev: MapMouseEvent) => void
-
ondblclick
optional
(ev: MapMouseEvent) => void
-
onmousemove
optional
(ev: MapMouseEvent) => void
-
onmouseup
optional
(ev: MapMouseEvent) => void
-
onmousedown
optional
(ev: MapMouseEvent) => void
-
onmouseout
optional
(ev: MapMouseEvent) => void
-
onmouseover
optional
(ev: MapMouseEvent) => void
-
onmovestart
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | WheelEvent | undefined>) => void
-
onmove
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | WheelEvent | undefined>) => void
-
onmoveend
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | WheelEvent | undefined>) => void
-
onzoomstart
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | WheelEvent | undefined>) => void
-
onzoom
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | WheelEvent | undefined>) => void
-
onzoomend
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | WheelEvent | undefined>) => void
-
onrotatestart
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | undefined>) => void
-
onrotate
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | undefined>) => void
-
onrotateend
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | undefined>) => void
-
ondragstart
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | undefined>) => void
-
ondrag
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | undefined>) => void
-
ondragend
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | undefined>) => void
-
onpitchstart
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | undefined>) => void
-
onpitch
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | undefined>) => void
-
onpitchend
optional
(ev: MapLibreEvent<MouseEvent | TouchEvent | undefined>) => void
-
onwheel
optional
(ev: MapWheelEvent) => void
-
onterrain
optional
(ev: MapTerrainEvent) => void
-
oncooperativegestureprevented
optional
(ev: MapLibreEvent<TouchEvent | WheelEvent> | {
  gestureType: "wheel_zoom" | "touch_pan"
}) => void
-
onprojectiontransition
optional
(ev: MapProjectionEvent) => void
-