Map
The Map
object represents the map on your page. It exposes methods
and properties that enable you to programmatically change the map,
and fires events as users interact with it.
You create a Map
by specifying a container
and other options.
Then SDK JS initializes the map on the page and returns your Map
object.
Example
Parameters
options.container (HTMLElement | string)
|
The HTML element in which SDK JS will render the map, or
the element's string
id
. The specified element must have no children.
|
---|---|
options.style | The map's style. This must be:
|
options.language |
Define the language of the map. This can be done directly with a language ISO code (eg. "en")
or with a built-in Languages shorthand (eg. Language.ENGLISH)
This applies only for the map instance, supersedes the config.primaryLanguage .
|
options.apiKey |
Define the MapTiler Cloud API key to be used.
This is equivalent to setting config.apiKey and will overwrite it.
|
options.center
default: [0,0]
|
The initial geographical centerpoint of the map. If
center
is not specified in the constructor options, SDKJS 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: SDK JS uses longitude, latitude coordinate order (as opposed to latitude, longitude) to
match GeoJSON.
|
options.zoom
default:
0 |
The initial zoom level of the map. If
zoom
is not specified in the constructor options, SDK 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
.
|
options.bearing
default:
0 |
The initial bearing (rotation) of the map, measured in degrees
counter-clockwise from north. If
bearing
is not specified in the constructor options, SDK 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
.
|
options.pitch
default:
0 |
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, SDK 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.
|
options.bounds | The initial bounds of the map. If
bounds
is specified, it overrides
center
and
zoom
constructor options.
|
options.hash
default:
false |
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.
|
options.terrain
default:
false |
If
true
, the map's loads a 3D terrain, based on a MapTiler "raster-dem" source.
|
options.terrainExaggeration
default:
1 |
3D terrain exaggeration factor. |
options.geolocate
(boolean |
GeolocationType.POINT |
GeolocationType.COUNTRY )
default:
false |
Center map on the visitor's location by using the IP geolocation API. There are two strategies:
geolocate options will not be taken into consideration in the following cases:
|
options.attributionControl
default:
true |
If
true
, an
AttributionControl
will be added to the map.
|
options.navigationControl
default:
true |
If
true
, an
MaptilerNavigationControl
will be added to the map.
Valid options are
top-left
,
top-right
,
bottom-left
,
bottom-right
.
|
options.terrainControl
default:
false |
If
true
, an
MaptilerTerrainControl
will be added to the map.
Valid options are
top-left
,
top-right
,
bottom-left
,
bottom-right
.
|
options.geolocateControl
default:
true |
If
true
, an
MaptilerGeolocateControl
will be added to the map.
Valid options are
top-left
,
top-right
,
bottom-left
,
bottom-right
.
|
options.scaleControl
default:
false |
If
true
, an
ScaleControl
will be added to the map.
Valid options are
top-left
,
top-right
,
bottom-left
,
bottom-right
.
|
options.fullscreenControl
default:
false |
If
true
, an
FullscreenControl
will be added to the map.
Valid options are
top-left
,
top-right
,
bottom-left
,
bottom-right
.
|
options.minimap
(boolean |
string |
MinimapOptionsInput)
default:
false |
If
true
, an
MaptilerMinimapControl
will be added to the map.
Valid options are
top-left
,
top-right
,
bottom-left
,
bottom-right
.
or MinimapOptionsInput
|
options.minZoom
default:
0 |
The minimum zoom level of the map (0-24). |
options.maxZoom
default:
22 |
The maximum zoom level of the map (0-24). |
options.minPitch
default:
0 |
The minimum pitch of the map (0-85). 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. |
options.maxPitch
default:
60 |
The maximum pitch of the map (0-85). 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. |
options.maxBounds | If set, the map will be constrained to the given bounds. |
options.interactive
default:
true |
If
false
, no mouse, touch, or keyboard listeners will be attached to the map, so it will not respond to
interaction.
|
options.bearingSnap
default:
7 |
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.
|
options.pitchWithRotate
default:
true |
If
false
, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled.
|
options.clickTolerance
default:
3 |
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). |
options.maptilerLogo
default:
true |
If
true
, the MapTiler logo will be shown. false will only work on premium accounts
|
options.logoPosition
default:
'bottom-left' |
A string representing the position of the MapTiler wordmark on
the map. Valid options are
top-left
,
top-right
,
bottom-left
,
bottom-right
.
|
options.failIfMajorPerformanceCaveat
default:
false |
If
true
, map creation will fail if the performance of SDK JS would be dramatically worse than expected (i.e. a software renderer would be used).
|
options.preserveDrawingBuffer
default:
false |
If
true
, the map's canvas can be exported to a PNG using
map.getCanvas().toDataURL()
. This is
false
by default as a performance optimization.
|
options.antialias | If
true
, the gl context will be created with MSAA antialiasing, which can be useful for antialiasing custom
layers. this is
false
by default as a performance optimization.
|
options.refreshExpiredTiles
default:
true |
If
false
, the map won't attempt to re-request tiles once they expire per their HTTP
cacheControl
/
expires
headers.
|
options.scrollZoom
default:
true |
If
true
, the "scroll to zoom" interaction is enabled. An
Object
value is passed as options to
ScrollZoomHandler#enable
.
|
options.boxZoom
default:
true |
If
true
, the "box zoom" interaction is enabled (see
BoxZoomHandler
).
|
options.dragRotate
default:
true |
If
true
, the "drag to rotate" interaction is enabled (see
DragRotateHandler
).
|
options.dragPan
default:
true |
If
true
, the "drag to pan" interaction is enabled. An
Object
value is passed as options to
DragPanHandler#enable
.
|
options.keyboard
default:
true |
If
true
, keyboard shortcuts are enabled (see
KeyboardHandler
).
|
options.doubleClickZoom
default:
true |
If
true
, the "double click to zoom" interaction is enabled (see
DoubleClickZoomHandler
).
|
options.touchZoomRotate
default:
true |
If
true
, the "pinch to rotate and zoom" interaction is enabled. An
Object
value is passed as options to
TouchZoomRotateHandler#enable
.
|
options.touchPitch
default:
true |
If
true
, the "drag to pitch" interaction is enabled. An
Object
value is passed as options to
TouchPitchHandler#enable
.
|
options.cooperativeGestures (boolean
| GestureOptions)
default:
false |
If
true
or set to an options object, 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 FullscreenControl.
A valid options object includes the following properties to customize the text on the informational
screen. The values below are the defaults.
|
options.trackResize
default:
true |
If
true
, the map will automatically resize when the browser window resizes.
|
options.fitBoundsOptions | A
Map#fitBounds
options object to use
only
when fitting the initial
bounds
provided above.
|
options.renderWorldCopies
default:
true |
If
true
, multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude. If
set to
false
:
|
options.maxTileCacheSize
default:
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. |
options.localIdeographFontFamily
default:
'sans-serif' |
Defines a CSS
font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs', 'Hiragana',
'Katakana' and 'Hangul Syllables' ranges.
In these ranges, 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
.)
|
options.transformRequest
RequestTransformFunction
default:
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.
Example
|
options.collectResourceTiming
default:
false |
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.
|
options.fadeDuration
default:
300 |
Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading. |
options.crossSourceCollisions
default:
true |
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.
|
options.locale
default:
null |
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).
|
options.pixelRatio | 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.
|
options. cancelPendingTileRequestsWhileZooming
default:
true |
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.
|
Methods
Add an image to the style. This image can be displayed on the map like any other icon in the style's
sprite using the image's ID with
icon-image
,
background-pattern
,
fill-pattern
,
or line-pattern
.
A Map.event:error event will be fired if there
is not enough space in the sprite to add this image.
HTMLImageElement
|
ImageBitmap
|
ImageData
|
{width: number
,
height: number
,
data: (Uint8Array
|
Uint8ClampedArray
)} |
StyleImageInterface
))
: The
image as an
HTMLImageElement
,
ImageData
,
ImageBitmap
or object with
width
,
height
, and
data
properties with the same format as
ImageData
.
(Partial<StyleImageMetadata>)
: Options object. Defaults to {}
options.pixelRatio any?
default:
1 |
The ratio of pixels in the image to physical pixels on the screen |
---|---|
options.sdf any?
default:
false |
Whether the image should be interpreted as an SDF image |
options.stretchX any?
|
[[x1, x2], ...]
If
icon-text-fit
is used in a layer with this image, this option defines the part(s) of the image that can be
stretched horizontally.
|
options.stretchY any?
|
[[y1, y2], ...]
If
icon-text-fit
is used in a layer with this image, this option defines the part(s) of the image that can be
stretched vertically.
|
options.content any?
|
[x1, y1, x2, y2]
If
icon-text-fit
is used in a layer with this image, this option defines the part of the image that can be
covered by the content in
text-field
.
|
- Use
HTMLImageElement
: Add an icon to the map - Use
ImageData
: Add a generated icon to the map
Adds a GL style layer to the map's style.
A layer defines how data from a specified source will be styled. Read more about layer types and available paint and layout properties in the GL Style Specification.
Object
)
: conforming
to either the GL Style Specification's
layer definition
or,
less commonly, the
CustomLayerInterface
specification.
The GL Style Specification's layer definition is appropriate for most layers.
layer.id | A unique identifer that you define. |
---|---|
layer.type | The type of layer (for example
fill
or
symbol
).
A list of layer types is available in the
GL Style
Specification
.
(This can also be |
layer.source (string
| SourceSpecification)?
|
The data source for the layer.
Reference a source that has
already been defined
using the source's unique id.
Reference a
new source
using a source object (as defined in the
GL Style
Specification
) directly.
This is
required
for all
layer.type
options
except
for
custom
and
background
.
|
layer.sourceLayer | (optional) The name of the source layer within the
specified
layer.source
to use for this style layer.
This is only applicable for vector tile sources and is
required
when
layer.source
is of the type
vector
.
|
layer.filter | (optional) An expression specifying conditions on source
features.
Only features that match the filter are displayed.
The GL Style Specification includes more information on the limitations of the
filter
parameter
and a complete list of available
expressions
.
If no filter is provided, all features in the source (or source layer for vector tilesets) will
be displayed.
|
layer.paint | (optional) Paint properties for the layer.
Available paint properties vary by
layer.type
.
A full list of paint properties for each layer type is available in the
GL Style
Specification
.
If no paint properties are specified, default values will be used.
|
layer.layout | (optional) Layout properties for the layer.
Available layout properties vary by
layer.type
.
A full list of layout properties for each layer type is available in the
GL Style
Specification
.
If no layout properties are specified, default values will be used.
|
layer.maxzoom | (optional) The maximum zoom level for the layer.
At zoom levels equal to or greater than the maxzoom, the layer will be hidden.
The value can be any number between
0
and
24
(inclusive).
If no maxzoom is provided, the layer will be visible at all zoom levels for which there are
tiles available.
|
layer.minzoom | (optional) The minimum zoom level for the layer.
At zoom levels less than the minzoom, the layer will be hidden.
The value can be any number between
0
and
24
(inclusive).
If no minzoom is provided, the layer will be visible at all zoom levels for which there are
tiles available.
|
layer.metadata | (optional) Arbitrary properties useful to track with the layer, but do not influence rendering. |
layer.renderingMode | This is only applicable for layers with the type
custom
.
See
CustomLayerInterface
for more information.
|
string
?)
: The
ID of an existing layer to insert the new layer before,
resulting in the new layer appearing visually beneath the existing layer.
If this argument is not specified, the layer will be appended to the end of the layers array
and appear visually above all other layers.
Map
: this
Adds a source to the map's style.
Object
)
: The
source object, conforming to the
GL Style Specification's
source definition
or
CanvasSourceOptions
.
Map
: this
- GeoJSON source: Add live realtime data
The map's BoxZoomHandler, which
implements zooming using a drag gesture with the Shift key pressed.
Find more details and examples using boxZoom
in the BoxZoomHandler section.
Calculates pitch, zoom and bearing for looking at @param newCenter with the camera position being @param newCenter and returns them as Cameraoptions.
number
)
: Optional altitude of the center to look at. If none
given the ground height
will be used. Defaults to
0
CameraOptions
:
the calculated camera options
(LngLatBoundsLike)
Calculate
the center for these bounds in the viewport and use
the highest zoom level up to and including
Map#getMaxZoom()
that fits
in the viewport. LngLatBounds represent a box that is always axis-aligned with bearing 0.
(CameraForBoundsOptions?)
Options
object
options.padding (number
| PaddingOptions)?
|
The amount of padding in pixels to add to the given bounds. |
---|---|
options.bearing
default: 0
|
Desired map bearing at end of animation, in degrees. |
options.offset
default: [0,0]
|
The center of the given bounds relative to the map's center, measured in pixels. |
options.maxZoom | The maximum zoom level to allow when the camera would transition to the specified bounds. |
CenterZoomBearing
:
If map is able to fit to provided bounds, returns
center
,
zoom
, and
bearing
.
If map is unable to fit, method will warn and return undefined.
Centering the map on the actual visitor location. Used when geolocate is to POINT but could be triggered manually.
As a more precise option, if the user has previously granted access to the browser location (more precise) then this is going to be used.
Promise
:
void
The map's CooperativeGesturesHandler,
which allows the user to see cooperative gesture info when user tries to zoom in/out.
Find more details and examples using cooperativeGestures
in the CooperativeGesturesHandler section.
The map's DoubleClickZoomHandler,
which allows the user to zoom by double clicking.
Find more details and examples using doubleClickZoom
in the DoubleClickZoomHandler section.
The map's DragPanHandler, which
implements dragging the map with a mouse or touch gesture.
Find more details and examples using dragPan
in the DragPanHandler section.
The map's DragRotateHandler, which
implements rotating the map while dragging with the right
mouse button or with the Control key pressed. Find more details and examples using dragRotate
in the DragRotateHandler section.
Changes any combination of center
, zoom
, bearing
,
pitch
, and padding
with an
animated transition
between old and new values. The map will retain its current values for any
details not specified in options
.
Note: The transition will happen instantly if the user has enabled
the reduced motion
accesibility feature enabled in their operating
system,
unless options
includes essential: true
.
(any)
Options
describing the destination and animation of the transition.
Accepts
CameraOptions
and
AnimationOptions
.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
:
this
Enables the 3D terrain visualization.
Pans and zooms the map to contain its visible area within the specified geographical bounds. This function will also reset the map's bearing to 0 if bearing is nonzero.
(LngLatBoundsLike)
Center
these bounds in the viewport and use the highest
zoom level up to and including
Map#getMaxZoom()
that fits them in the viewport.
(FitBoundsOptions?)
Options supports
all properties from
AnimationOptions
and
CameraOptions
in addition to the fields below.
options.padding (number
| PaddingOptions)?
|
The amount of padding in pixels to add to the given bounds. |
---|---|
options.linear
default: false
|
If
true
, the map transitions using
Map#easeTo
. If
false
, the map transitions using
Map#flyTo
. See
those functions and
AnimationOptions
for information about options available.
|
options.easing | An easing function for the animated transition. See AnimationOptions . |
options.offset
default: [0,0]
|
The center of the given bounds relative to the map's center, measured in pixels. |
options.maxZoom | The maximum zoom level to allow when the map view transitions to the specified bounds. |
(Object?)
Additional
properties to be added to event objects of events triggered by this method.
Map
: this
Pans, rotates and zooms the map to to fit the box made by points p0 and p1 once the map is rotated to the specified bearing. To zoom without rotating, pass in the current map bearing.
(FitBoundsOptions?)
Options object
options.padding (number
| PaddingOptions)?
|
The amount of padding in pixels to add to the given bounds. |
---|---|
options.linear
default: false
|
If
true
, the map transitions using
Map#easeTo
. If
false
, the map transitions using
Map#flyTo
. See
those functions and
AnimationOptions
for information about options available.
|
options.easing | An easing function for the animated transition. See AnimationOptions . |
options.offset
default: [0,0]
|
The center of the given bounds relative to the map's center, measured in pixels. |
options.maxZoom | The maximum zoom level to allow when the map view transitions to the specified bounds. |
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
: this
- Used by BoxZoomHandler
Changes any combination of center, zoom, bearing, and pitch, animating the transition along a curve that evokes flight. The animation seamlessly incorporates zooming and panning to help the user maintain her bearings even after traversing a great distance.
Note: The animation will be skipped, and this will behave equivalently to jumpTo
if the user has the reduced motion
accesibility feature enabled in
their operating system,
unless 'options' includes essential: true
.
(FlyToOptions)
Options describing the
destination and animation of the transition.
Accepts
CameraOptions
,
AnimationOptions
,
and the following additional options.
options.curve
default: 1.42
|
The zooming "curve" that will occur along the
flight path. A high value maximizes zooming for an exaggerated animation, while a low
value minimizes zooming for an effect closer to
Map#easeTo
. 1.42 is the average
value selected by participants in the user study discussed in
van Wijk (2003)
. A value of
Math.pow(6, 0.25)
would be equivalent to the root mean squared average velocity. A
value of 1 would produce a circular motion.
|
---|---|
options.minZoom | The zero-based zoom level at the peak of the flight path.
If
options.curve
is specified, this option is ignored.
|
options.speed
default: 1.2
|
The average speed of the animation defined in relation to
options.curve
. A speed of 1.2 means that the map appears to move along the flight path
by 1.2 times
options.curve
screenfuls every second. A
screenful
is the map's visible span.
It does not correspond to a fixed physical distance, but varies by zoom level.
|
options.screenSpeed | The average speed of the animation measured in screenfuls
per second, assuming a linear timing curve. If
options.speed
is specified, this option is ignored.
|
options.maxDuration | The animation's maximum duration, measured in milliseconds. If duration exceeds maximum duration, it resets to 0. |
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
:
this
Returns the map's current bearing. The bearing is the compass direction that is "up"; for example, a bearing of 90° orients the map so that east is up.
number
:
The map's current bearing.
Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
LngLatBounds
:
The geographical bounds of the map as
LngLatBounds
.
Returns the HTML element containing the map's <canvas>
element.
If you want to add non-GL overlays to the map, you should append them to this element.
This is the element to which event bindings for map interactivity (such as panning and zooming) are
attached. It will receive bubbled events from child elements such as the <canvas>
, but
not from
map controls.
HTMLElement
:
The container of the map's
<canvas>
.
Gets the state
of a feature.
A feature's state
is a set of user-defined key-value pairs that
are assigned to a feature at
runtime.
Features are identified by their feature.id
attribute, which can
be any number or string.
Note: To access the values in a feature's state object for the purposes of styling the feature, use
the feature-state
expression.
(Object)
Feature
identifier. Feature objects returned from
Map#queryRenderedFeatures
or event handlers can be used as feature identifiers.
Object
:
The state of the feature: a set of key-value pairs that was assigned to the feature at runtime.
Returns an image, specified by ID, currently available in the map. This includes both images from the style's original sprite and any images that have been added at runtime using addImage.
StyleImage
: An image in the map with the specified ID.
Returns the layer with the specified ID in the map's style.
StyleLayer
: The layer with
the specified ID, or
undefined
if the ID corresponds to no existing layers.
Returns the value of a layout property in the specified style layer.
any
: The value of
the specified layout property.
Returns the maximum geographical bounds the map is constrained to, or null
if none set.
(LngLatBounds | null)
:
The map object.
Returns the current padding applied around the map viewport.
PaddingOptions
:
The current padding around the map viewport.
Returns the value of a paint property in the specified style layer.
any
: The value of
the specified paint property.
Returns the state of renderWorldCopies
. 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.
boolean
:
renderWorldCopies
Get the SDK config object. This is convenient to dispatch the SDK configuration to externally built layers that do not directly have access to the SDK configuration but do have access to a Map instance.
config
: the
SDK config object
Returns the source with the specified ID in the map's style.
This method is often used to update a source using the instance members for the relevant
source type as defined in Sources.
For example, setting the data
for a GeoJSON source or updating the
url
and
coordinates
of an image source.
(Source | undefined)
:
The style source with the specified ID or
undefined
if the ID
corresponds to no existing sources.
The shape of the object varies by source type.
A list of options for each source type is available on the GL Style Specification's
Sources
page.
Check whether or not an image with a specific ID exists in the style. This checks both images in the style's original sprite and any images that have been added at runtime using Map#addImage.
boolean
:
A Boolean indicating whether the image exists.
Returns a Boolean indicating whether the source is loaded. Returns true
if the source with
the given ID in the map's style has no outstanding network requests, otherwise false
.
boolean
:
A Boolean indicating whether the source is loaded.
Changes any combination of center, zoom, bearing, and pitch, without
an animated transition. The map will retain its current values for any
details not specified in options
.
(JumpToOptions)
Options object
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
:
this
The map's KeyboardHandler, which allows
the user to zoom, rotate, and pan the map using keyboard
shortcuts. Find more details and examples using keyboard
in the KeyboardHandler section.
Returns an Array of strings containing the IDs of all images currently available in the map. This includes both images from the style's original sprite and any images that have been added at runtime using Map#addImage.
Array<string>
:
An Array of strings containing the names of all sprites/images currently available in the map.
Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
boolean
:
true
if there is at least one registered listener
for specified event type, false
otherwise
Load an image from an external URL to be used with Map#addImage. External domains must support CORS.
Promise<GetResourceResponse<ImageBitmap | HTMLImageElement>>
:
A promise that is resolved when the image is loaded.
Moves a layer to a different z-position.
(string?)
The
ID of an existing layer to insert the new layer before. When viewing the map, the
id
layer will appear beneath the
beforeId
layer. If
beforeId
is omitted, the layer will be appended to the end of the layers array and appear above all other layers on
the map.
Map
: this
Removes an event listener for layer-specific events previously added with Map#on
. See Map Events for a full list of events and their description.
Map
: this
Overload of the off
method that allows to listen to events without specifying a layer.
Adds a listener for events of a specified type, optionally limited to features in a specified style layer. See Map Events for a full list of events and their description.
(string)
The
event type to listen for. Events compatible with the optional
layerIds
parameter are triggered
when the cursor enters a visible portion of the specified layer from outside that layer or outside the map
canvas.
(string)
The
ID of a style layer. Event will only be triggered if its location
is within a visible feature in this layer. The event will have a
features
property containing
an array of the matching features. If
layer
is not supplied, the event will not have a
features
property.
Please note that many event types are not compatible with the optional
layer
parameter.
Map
: this
Overload of the on
method that allows to listen to events specifying multiple layers.
(string)
The
event type to listen for. Events compatible with the optional
layerIds
parameter are triggered
when the cursor enters a visible portion of the specified layer from outside that layer or outside the map
canvas.
(string[])
The array of style layer IDs. Event will only be triggered if its location
is within a visible feature in this layer. The event will have a
features
property containing
an array of the matching features. If
layer
is not supplied, the event will not have a
features
property.
Please note that many event types are not compatible with the optional
layer
parameter.
Map
: this
Overload of the on
method that allows to listen to events without specifying a layer.
Adds a listener that will be called only once to a specified event type occurring on features in a specified style layer. See Map Events for a full list of events and their description.
(string)
The
event type to listen for; one of
'mousedown'
,
'mouseup'
,
'click'
,
'dblclick'
,
'mousemove'
,
'mouseenter'
,
'mouseleave'
,
'mouseover'
,
'mouseout'
,
'contextmenu'
,
'touchstart'
,
'touchend'
, or
'touchcancel'
.
mouseenter
and
mouseover
events are triggered when the cursor enters
a visible portion of the specified layer from outside that layer or outside the map canvas.
mouseleave
and
mouseout
events are triggered when the cursor leaves a visible portion of the specified layer, or leaves
the map canvas.
(string)
The
ID of a style layer. Only events whose location is within a visible
feature in this layer will trigger the listener. The event will have a
features
property containing
an array of the matching features.
Map
:
this
Overload of the once
method that allows to listen to events specifying multiple layers.
(string)
The
event type to listen for; one of
'mousedown'
,
'mouseup'
,
'click'
,
'dblclick'
,
'mousemove'
,
'mouseenter'
,
'mouseleave'
,
'mouseover'
,
'mouseout'
,
'contextmenu'
,
'touchstart'
,
'touchend'
, or
'touchcancel'
.
mouseenter
and
mouseover
events are triggered when the cursor enters
a visible portion of the specified layer from outside that layer or outside the map canvas.
mouseleave
and
mouseout
events are triggered when the cursor leaves a visible portion of the specified layer, or leaves
the map canvas.
(string[])
The array of style layer IDs. Only events whose location is within a visible
feature in this layer will trigger the listener. The event will have a
features
property containing
an array of the matching features.
Map
:
this
Overload of the once
method that allows to listen to events without specifying a layer.
Awaits for the Map instance to be "loaded" as well as with terrain being non-null for the first time and returns a Promise to the Map.
If the Map instance is already loaded with terrain, the Promise is resolved directly, otherwise, it is resolved as a result of the "loadWithTerrain" event.
Map
:
this
Pans the map by the specified offset.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
:
this
Pans the map to the specified location with an animated transition.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
:
this
Returns an array of MapGeoJSONFeature objects representing visible features that satisfy the query parameters.
((PointLike | Array<PointLike>)?)
The
geometry of the query region:
either a single point or southwest and northeast points describing a bounding box.
Omitting this parameter (i.e. calling
Map#queryRenderedFeatures
with zero arguments,
or with only a
options
argument) is equivalent to passing a bounding box encompassing the entire
map viewport.
(Object?)
Options
object.
options.layers | An array of style layer IDs for the query to inspect. Only features within these layers will be returned. If this parameter is undefined, all layers will be checked. |
---|---|
options.filter | A filter to limit query results. |
options.validate
default: true
|
Whether to check if the [options.filter] conforms to the MapLibre GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function. |
Array<MapGeoJSONFeature>
:
An array of MapGeoJSONFeature objects.
The properties
value of each returned feature object contains
the properties of its source
feature. For GeoJSON sources, only
string and numeric property values are supported (i.e. null
,
Array
, and
Object
values are not supported).
Each feature includes top-level layer
, source
, and sourceLayer
properties. The layer
property is an object
representing the style layer to which the feature belongs. Layout and paint properties in this object
contain values
which are fully evaluated for the given zoom level and feature.
Only features that are currently rendered are included. Some features will not be included, like:
- Features from layers whose
visibility
property is"none"
. - Features from layers whose zoom range excludes the current zoom level.
- Symbol features that have been hidden due to text or icon collision.
Features from all other layers are included, including features that may have no visible contribution to the rendered result; for example, because the layer's opacity or color alpha component is set to
The topmost rendered feature appears first in the returned array, and subsequent features are sorted by descending z-order. Features that are rendered multiple times (due to wrapping across the antimeridian at low zoom levels) are returned only once (though subject to the following caveat).
Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering.
Returns an array of MapGeoJSONFeature objects representing features within the specified vector tile or GeoJSON source that satisfy the query parameters.
(Object?)
Options
object.
parameters.sourceLayer | The name of the source layer to query. For vector tile sources, this parameter is required. For GeoJSON sources, it is ignored. |
---|---|
parameters.filter | A filter to limit query results. |
parameters.validate
default: true
|
Whether to check if the [parameters.filter] conforms to the MapLibre GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function. |
Array<MapGeoJSONFeature>
:
An array of MapGeoJSONFeature objects.
In contrast to Map#queryRenderedFeatures, this function returns all features matching the query parameters, whether or not they are rendered by the current style (i.e. visible). The domain of the query includes all currently-loaded vector tiles and GeoJSON source tiles: this function does not check tiles outside the currently visible viewport.
Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering.
Get the elevation difference between a given point and a point that is currently in the middle of the screen. This method should be used for proper positioning of custom 3d objects. Returns null if terrain is not enabled. This method is subject to change in Maplibre GL JS v5.
number
elevation offset in meters
Clean up and release all internal resources associated with this map.
This includes DOM elements, event bindings, web workers, and WebGL resources.
Use this method when you are done using the map and wish to ensure that it no longer consumes browser resources. Afterwards, you must not call any other methods on the map.
Removes the state
of a feature, setting it back to the default
behavior.
If only a target.source
is specified, it will remove the state for
all features from that
source.
If target.id
is also specified, it will remove all keys for that
feature's state.
If key
is also specified, it removes only that key from that
feature's state.
Features are identified by their feature.id
attribute, which can
be any number or string.
(Object)
Identifier
of where to remove state. It can be a source, a feature, or a specific key of feature.
Feature objects returned from
Map#queryRenderedFeatures
or event handlers can be used as feature identifiers.
Remove an image from a style. This can be an image from the style's original sprite or any images that have been added at runtime using Map#addImage.
Removes the layer with the given ID from the map's style.
If no such layer exists, an error
event is fired.
Gets and sets a Boolean indicating whether the map will continuously repaint. This information is useful for analyzing performance.
Rotates the map so that north is up (0° bearing), with an animated transition.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
: this
Rotates and pitches the map so that north is up (0° bearing) and pitch is 0°, with an animated transition.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
: this
Resizes the map according to the dimensions of its
container
element.
Checks if the map container size changed and updates the map if it has changed.
This method must be called after the map's container
is resized
programmatically
or when the map is shown after being initially hidden with CSS.
(any?)
Additional properties to be
passed to
movestart
,
move
,
resize
, and
moveend
events that get triggered as a result of resize. This can be useful for differentiating the
source of an event (for example, user-initiated or programmatically-triggered events).
Map
:
this
Rotates the map to the specified bearing, with an animated transition. The bearing is the compass direction that is "up"; for example, a bearing of 90° orients the map so that east is up.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
: this
The map's ScrollZoomHandler, which
implements zooming in and out with a scroll wheel or trackpad.
Find more details and examples using scrollZoom
in the ScrollZoomHandler section.
Sets the map's bearing (rotation). The bearing is the compass direction that is "up"; for example, a bearing of 90° orients the map so that east is up.
Equivalent to jumpTo({bearing: bearing})
.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
: this
Sets the map's geographical centerpoint. Equivalent to jumpTo({center: center})
.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
: this
Sets the state
of a feature.
A feature's state
is a set of user-defined key-value pairs that
are assigned to a feature at
runtime.
When using this method, the state
object is merged with any
existing key-value pairs in the
feature's state.
Features are identified by their feature.id
attribute, which can
be any number or string.
This method can only be used with sources that have a feature.id
attribute. The
feature.id
attribute can be defined in three ways:
- For vector or GeoJSON sources, including an
id
attribute in the original data file. - For vector or GeoJSON sources, using the
promoteId
option at the time the source is defined. - For GeoJSON sources, using the
generateId
option to auto-assign anid
based on the feature's index in the source data. If you change feature data usingmap.getSource('some id').setData(..)
, you may need to re-apply state taking into account updatedid
values.
Note: You can use the feature-state
expression to access the values in a feature's state object for the purposes of styling.
(Object)
Feature
identifier. Feature objects returned from
Map#queryRenderedFeatures
or event handlers can be used as feature identifiers.
Sets the filter for the specified style layer.
Filters control which features a style layer renders from its source.
Any feature for which the filter expression evaluates to true
will
be
rendered on the map. Those that are false will be hidden.
Use setFilter
to show a subset of your source data.
To clear the filter, pass null
or undefined
as the second parameter.
((Array | null | undefined))
The
filter, conforming to the GL Style Specification's
filter definition
. If
null
or
undefined
is provided, the function removes any existing filter from the layer.
(Object?)
(default
{}
)Options object.
options.validate
default: true
|
Whether to check if the filter conforms to the MapLibre GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function. |
---|
Map
: this
Sets the map labels language. This method is just a shortcut to .setPrimaryLanguage
(string |
Language)
The
language to be applied. The language generally depends on the style. Whenever a label is not supported in the defined language, it falls back to maptilersdk.Language.LATIN
.
Languages that are written right-to-left such as arabic and hebrew are fully supported by default. No need to install any plugin!
Map
: this
Sets the zoom extent for the specified style layer. The zoom extent includes the minimum zoom level and maximum zoom level) at which the layer will be rendered.
Note: For style layers using vector sources, style layers cannot be rendered at zoom levels lower than the minimum zoom level of the source layer because the data does not exist at those zoom levels. If the minimum zoom level of the source layer is higher than the minimum zoom level defined in the style layer, the style layer will not be rendered at all zoom levels in the zoom range.
Map
: this
Sets the value of a layout property in the specified style layer.
(any)
The value of
the layout property. Must be of a type appropriate for the property, as defined in the
GL Style Specification
.
(Object?)
(default
{}
)Options object.
options.validate
default: true
|
Whether to check if
value
conforms to the MapLibre GL Style Specification. Disabling validation is a performance
optimization that should only be used if you have previously validated the values you will be
passing to this function.
|
---|
Map
: this
Sets the any combination of light values.
(Object?)
(default
{}
)Options object.
options.validate
default: true
|
Whether to check if the filter conforms to the GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function. |
---|
Map
: this
Sets or clears the map's geographical bounds.
Pan and zoom operations are constrained within these bounds. If a pan or zoom is performed that would display regions outside these bounds, the map will instead display a position and zoom level as close as possible to the operation's request while still remaining within the bounds.
((LngLatBoundsLike | null | undefined))
The
maximum bounds to set. If
null
or
undefined
is provided, the function removes the map's maximum bounds.
Map
: this
Sets or clears the map's maximum pitch. If the map's current pitch is higher than the new maximum, the map will pitch to the new maximum.
((number | null | undefined))
The
maximum pitch to set (0-85). 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.
If
null
or
undefined
is provided, the function removes the current maximum pitch (sets it to 60).
Map
: this
Sets or clears the map's maximum zoom level. If the map's current zoom level is higher than the new maximum, the map will zoom to the new maximum.
((number | null | undefined))
The
maximum zoom level to set.
If
null
or
undefined
is provided, the function removes the current maximum zoom (sets it to 22).
Map
: this
Sets or clears the map's minimum pitch. If the map's current pitch is lower than the new minimum, the map will pitch to the new minimum.
((number | null | undefined))
The
minimum pitch to set (0-85). 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.
If
null
or
undefined
is provided, the function removes the current minimum pitch (i.e. sets it to 0).
Map
: this
Sets or clears the map's minimum zoom level. If the map's current zoom level is lower than the new minimum, the map will zoom to the new minimum.
It is not always possible to zoom out and reach the set minZoom
.
Other factors such as map height may restrict zooming. For example,
if the map is 512px tall it will not be possible to zoom below zoom 0
no matter what the minZoom
is set to.
((number | null | undefined))
The
minimum zoom level to set (-2 - 24).
If
null
or
undefined
is provided, the function removes the current minimum zoom (i.e. sets it to -2).
Map
: this
Sets the padding in pixels around the viewport.
Equivalent to jumpTo({padding: padding})
.
(PaddingOptions)
The
desired padding. Format: { left: number, right: number, top: number, bottom: number }
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
: this
Sets the value of a paint property in the specified style layer.
(any)
The value of
the paint property to set.
Must be of a type appropriate for the property, as defined in the
GL Style Specification
.
(Object?)
(default
{}
)Options object.
options.validate
default: true
|
Whether to check if
value
conforms to the MapLibre GL Style Specification. Disabling validation is a performance
optimization that should only be used if you have previously validated the values you will be
passing to this function.
|
---|
Map
: this
Sets the map's pitch (tilt). Equivalent to jumpTo({pitch: pitch})
.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
: this
Sets the map's pixel ratio. This allows to override devicePixelRatio
.
After this call, the canvas' width
attribute will be
container.clientWidth * pixelRatio
and its height attribute will be container.clientHeight * pixelRatio
.
Sets the map labels language.
(string |
Language)
The
language to be applied. The language generally depends on the style. Whenever a label is not supported in the defined language, it falls back to maptilersdk.Language.LATIN
.
Languages that are written right-to-left such as arabic and hebrew are fully supported by default. No need to install any plugin!
Map
: this
Sets the state of renderWorldCopies
.
(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.
undefined
is treated as true
, null
is treated as
false
.
Map
: this
Sets the map labels secondary language.
(string |
Language)
The
language to be applied. The language generally depends on the style. Whenever a label is not supported in the defined language, it falls back to maptilersdk.Language.LATIN
.
Languages that are written right-to-left such as arabic and hebrew are fully supported by default. No need to install any plugin!
Map
: this
Updates the map's style object with a new value.
If a style is already set when this is used and options.diff is set to true, the map renderer will attempt to compare the given style against the map's current state and perform only the changes necessary to make the map style match the desired state. Changes in sprites (images used for icons and patterns) and glyphs (fonts for label text) cannot be diffed. If the sprites or fonts used in the current style and the given style are different in any way, the map renderer will force a full update, removing the current style and building the given one from scratch.
((ReferenceMapStyle |
MapStyleVariant |
string |
StyleSpecification | null))
The map's style. This must be:
- ReferenceMapStyle (e.g. MapStyle.STREETS)
- MapStyleVariant (e.g. MapStyle.STREETS.DARK)
- MapTIler Style ID (e.g. “streets-v2”)
- uuid of custom style
- an a JSON object conforming to the schema described in the GL Style Specification
- a URL to such JSON
- null
(Object?)
Options
object.
options.diff
default: true
|
If false, force a 'full' update, removing the current style and building the given one instead of attempting a diff-based update. |
---|---|
options.transformStyle | TransformStyleFunction is a convenience function that allows to modify a style after it is fetched but before it is committed to the map state. |
options.localIdeographFontFamily
default: 'sans-serif'
|
Defines a CSS
font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs',
'Hiragana', 'Katakana' and 'Hangul Syllables' ranges.
In these ranges, 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.
Forces a full update.
|
options.validate | If false, style validation will be skipped. Useful in production environment. |
Map
: this
Loads a 3D terrain mesh, based on a "raster-dem" source.
(TerrainSpecification?)
Options
object.
Map
: this
Sets the 3D terrain exageration factor. This method is just a shortcut to .enableTerrain
Updates the requestManager's transform request with a new function
(RequestTransformFunction)
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
Map
: this
Sets the map's zoom level. Equivalent to jumpTo({zoom: zoom})
.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
: this
Gets and sets a Boolean indicating whether the map will render boxes around all symbols in the data source, revealing which symbols were rendered or which were hidden due to collisions. This information is useful for debugging.
Gets and sets a Boolean indicating whether the map should color-code each fragment to show how many times it has been shaded. White fragments have been shaded 8 or more times. Black fragments have been shaded 0 times. This information is useful for debugging.
Gets and sets a Boolean indicating whether the map will visualize the padding offsets.
Gets and sets a Boolean indicating whether the map will render an outline around each tile and the tile ID. These tile boundaries are useful for debugging.
The uncompressed file size of the first vector source is drawn in the top left corner of each tile, next to the tile ID.
Snaps the map so that north is up (0° bearing), if the current bearing is close enough to it (i.e. within
the
bearingSnap
threshold).
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
: this
The map's TouchPitchHandler, which
allows the user to pitch the map with touch gestures.
Find more details and examples using touchPitch
in the TouchPitchHandler section.
The map's TouchZoomRotateHandler,
which allows the user to zoom or rotate the map with touch gestures.
Find more details and examples using touchZoomRotate
in the TouchZoomRotateHandler section.
A callback (CameraUpdateTransformFunction) used to defer camera updates or apply arbitrary constraints. If specified, this Camera instance can be used as a stateless component in React etc.
Trigger the rendering of a single frame. Use this method with custom layers to repaint the map when the layer changes. Calling this multiple times before the next frame is rendered will still result in only a single frame being rendered.
Update an existing image in a style. This image can be displayed on the map like any other icon in the
style's
sprite using the image's ID with
icon-image
,
background-pattern
,
fill-pattern
,
or line-pattern
.
((HTMLImageElement | ImageBitmap | ImageData | {width: number, height: number, data: (Uint8Array | Uint8ClampedArray)} | StyleImageInterface))
The
image as an
HTMLImageElement
,
ImageData
,
ImageBitmap
or object with
width
,
height
, and
data
properties with the same format as
ImageData
.
Increases the map's zoom level by 1.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
:
this
Decreases the map's zoom level by 1.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
: this
Zooms the map to the specified zoom level, with an animated transition.
(any?)
Additional properties to be
added to event objects of events triggered by this method.
Map
:
this
Events
Fired when the user cancels a "box zoom" interaction, or when the bounding box does not meet the minimum size threshold. See BoxZoomHandler.
(MapLibreZoomEvent)
Fired when a pointing device (usually a mouse) is pressed and released at the same point on the map.
Note: This event is compatible with the optional layerId
parameter.
If layerId
is included as the second argument in Map#on, the event listener will fire only when the
point that is pressed and released contains a visible portion of the specifed layer.
(MapMouseEvent)
Fired whenever the cooperativeGestures option prevents a gesture from being handled by the map. This is useful for showing your own UI when this happens.
"wheel_zoom"
| "touch_pan"
)
Fired when a request for one of the map's sources' tiles is aborted. Fired when a request for one of the map's sources' data is aborted. See MapDataEvent for more information.
(MapDataEvent)
Fired when any map data (style, source, tile, etc) begins loading or
changing asyncronously. All dataloading
events are followed by a
data
,
dataabort
or error
event.
See MapDataEvent for more information.
(MapDataEvent)
Fired when a pointing device (usually a mouse) is pressed and released twice at the same point on the map in rapid succession.
Note: This event is compatible with the optional layerId
parameter.
If layerId
is included as the second argument in Map#on, the event listener will fire only
when the point that is clicked twice contains a visible portion of the specifed layer.
(MapMouseEvent)
Fired repeatedly during a "drag to pan" interaction. See DragPanHandler.
((MapMouseEvent | MapTouchEvent))
Fired when an error occurs. This is GL JS's primary error reporting
mechanism. We use an event instead of throw
to better accommodate
asyncronous operations. If no listeners are bound to the error
event, the
error will be printed to the console.
({error: {message: string}})
Fired after the last frame rendered before the map enters an "idle" state:
- No camera transitions are in progress
- All currently requested tiles have loaded
- All fade/transition animations have completed
Fired immediately after all necessary resources have been downloaded and the first visually complete rendering of the map has occurred.
Fired only once in a Map
instance lifecycle, when both the load
event and the terrain
event with non-null terrain are fired.
Fired when a pointing device (usually a mouse) is pressed within the map.
Note: This event is compatible with the optional layerId
parameter.
If layerId
is included as the second argument in Map#on, the event listener will fire only when the
the cursor is pressed while inside a visible portion of the specifed layer.
(MapMouseEvent)
Fired when a pointing device (usually a mouse) enters a visible portion of a specified layer from outside that layer or outside the map canvas.
Important: This event can only be listened for when Map#on includes three arguments, where the second argument specifies the desired layer.
(MapMouseEvent)
Fired when a pointing device (usually a mouse) leaves a visible portion of a specified layer, or leaves the map canvas.
Important: This event can only be listened for when Map#on includes three arguements, where the second argument specifies the desired layer.
(MapMouseEvent)
Fired when a pointing device (usually a mouse) is moved while the cursor is inside the map. As you move the cursor across the map, the event will fire every time the cursor changes position within the map.
Note: This event is compatible with the optional layerId
parameter.
If layerId
is included as the second argument in Map#on, the event listener will fire only when the
the cursor is inside a visible portion of the specified layer.
(MapMouseEvent)
Fired when a pointing device (usually a mouse) is moved within the map. As you move the cursor across a web page containing a map, the event will fire each time it enters the map or any child elements.
Note: This event is compatible with the optional layerId
parameter.
If layerId
is included as the second argument in Map#on, the event listener will fire only when the
the cursor is moved inside a visible portion of the specifed layer.
(MapMouseEvent)
Fired when a pointing device (usually a mouse) is released within the map.
Note: This event is compatible with the optional layerId
parameter.
If layerId
is included as the second argument in Map#on, the event listener will fire only when the
the cursor is released while inside a visible portion of the specifed layer.
(MapMouseEvent)
Fired repeatedly during an animated transition from one view to another, as the result of either user interaction or methods such as Map#flyTo.
((MapMouseEvent | MapTouchEvent))
Fired just after the map completes a transition from one view to another, as the result of either user interaction or methods such as Map#jumpTo.
({originalEvent: DragEvent})
Fired just before the map begins a transition from one view to another, as the result of either user interaction or methods such as Map#jumpTo.
({originalEvent: DragEvent})
Fired repeatedly during the map's pitch (tilt) animation between one state and another as the result of either user interaction or methods such as Map#flyTo.
(MapEventData)
Fired immediately after the map's pitch (tilt) finishes changing as the result of either user interaction or methods such as Map#flyTo.
(MapEventData)
Fired whenever the map's pitch (tilt) begins a change as the result of either user interaction or methods such as Map#flyTo .
(MapEventData)
Called only once after load
and wait for all the controls managed by
the Map constructor to be dealt with (as one relies on async logic).
Since the ready
event waits that all the basic controls
are nicely positioned, it is safer to use ready
than
load
if you plan to add other custom comtrols with
the .addControl()
method.
Fired whenever the map is drawn to the screen, as the result of
- a change to the map's position, zoom, pitch, or bearing
- a change to the map's style
- a change to a GeoJSON source
- the loading of a vector tile, GeoJSON file, glyph, or sprite
Fired repeatedly during a "drag to rotate" interaction. See DragRotateHandler.
((MapMouseEvent | MapTouchEvent))
Fired when a "drag to rotate" interaction ends. See DragRotateHandler.
((MapMouseEvent | MapTouchEvent))
Fired when a "drag to rotate" interaction starts. See DragRotateHandler.
((MapMouseEvent | MapTouchEvent))
Fired when one of the map's sources loads or changes, including if a tile belonging to a source loads or changes. See MapDataEvent for more information.
(MapDataEvent)
Fired when a request for one of the map's sources' data is aborted. See MapDataEvent for more information.
(MapDataEvent)
Fired when one of the map's sources begins loading or changing asyncronously.
All sourcedataloading
events are followed by a sourcedata
,
sourcedataabort
or error
event.
See MapDataEvent for more information.
(MapDataEvent)
Fired when the map's style loads or changes. See MapDataEvent for more information.
(MapDataEvent)
Fired when the map's style begins loading or changing asyncronously.
All styledataloading
events are followed by a styledata
or error
event. See MapDataEvent
for more information.
(MapDataEvent)
Fired when an icon or pattern needed by the style is missing. The missing image can be added with Map#addImage within this event listener callback to prevent the image from being skipped. This event can be used to dynamically generate icons and patterns.
Fired repeatedly during an animated transition from one zoom level to another, as the result of either user interaction or methods such as Map#flyTo.
((MapMouseEvent | MapTouchEvent))
Fired just after the map completes a transition from one zoom level to another, as the result of either user interaction or methods such as Map#flyTo.
((MapMouseEvent | MapTouchEvent))
Fired just before the map begins a transition from one zoom level to another, as the result of either user interaction or methods such as Map#flyTo.
((MapMouseEvent | MapTouchEvent))