ViewportController
The viewport controller allows you to control the viewport of the map.
You can get the current viewport, move the viewport, and be notified when the viewport changes.
Extended by
Methods
getViewport()
getViewport():
Promise
<ViewportState
>
Gets the current state of the viewport.
Returns
Promise
<ViewportState
>
Example
setViewport()
setViewport(
viewport
:SetViewportCenterZoomParams
):void
Moves the map to the specified location.
Parameters
viewport
Returns
void
Example
getViewportConstraints()
getViewportConstraints():
Promise
<null
|ViewportConstraints
>
Gets the current state of the viewport constraints.
Returns
Promise
<null
| ViewportConstraints
>
Example
setViewportConstraints()
setViewportConstraints(
constraints
:null
|Partial
<ViewportConstraints
>):void
Constrains the map viewport so it stays inside certain bounds and/or certain zoom levels.
Parameters
constraints
Returns
void
Examples
every constraint is optional
if a constraint is null, it will be removed but keeping the others
if method receives null, it will remove the constraints
fitViewportToBounds()
fitViewportToBounds(
bounds
:ViewportFitBoundsParams
):void
Fits the map to the specified bounds.
Parameters
bounds
Returns
void
Example
Events
onViewportMove()
onViewportMove(
args
: {handler
: (viewport
:ViewportState
) =>void
; }):VoidFunction
Adds a listener for when the viewport changes.
Parameters
args
-
args.handler
This callback is called with the current viewport state whenever the viewport changes.
Returns
VoidFunction
A function to unsubscribe from the listener
Example
onViewportMoveEnd()
onViewportMoveEnd(
args
: {handler
: (viewport
:ViewportState
) =>void
; }):VoidFunction
Adds a listener for when the viewport move ends, which is when the user stops dragging or zooming the map, animations have finished, or inertial dragging ends.
Parameters
args
args.handler
Returns
VoidFunction
A function to unsubscribe from the listener
Example
onMapIdle()
onMapIdle(
args
: {handler
: () =>void
; }):VoidFunction
Adds a listener for when the map is idle, which is defined as:
No transitions are in progress
The user is not interacting with the map, e.g. by panning or zooming
All tiles for the current viewport have been loaded
Any fade transitions (e.g. for labels) have completed
Parameters
args
{ handler
: () => void
; }
args.handler
() => void
Returns
VoidFunction
A function to unsubscribe from the listener
Example
Last updated
Was this helpful?