Viewport
The Viewport component provides a structured approach to organizing camera management logic into states and transitions between them. At any given time, the viewport is either idle, in a state (camera is being managed by a ViewportState), or transitioning between states.Import
Basic Usage
Props
transitionsToIdleUponUserInteraction
Indicates whether the Viewport should idle when the MapView receives touch input.Set this property to
false to enable building custom ViewportStates that can work simultaneously with certain types of gestures.onStatusChanged
Subscribes to status changes. Called when the viewport status changes.Observers are notified of status changes asynchronously on the main queue. This means that by the time the notification is delivered, the status may have already changed again. This behavior is necessary to allow observers to trigger further transitions while avoiding out-of-order delivery of status changed notifications.ViewportStatusChangedEvent:
from: ViewportStatus - The previous statusto: ViewportStatus - The new statusreason: ViewportStatusChangeReason - Why the status changed
TransitionStarted- A transition has begunTransitionSucceeded- A transition completed successfullyIdleRequested- Idle state was requestedUserInteraction- User interacted with the map
Methods
getState()
idle()
transitionTo()
The target viewport state. Can be either:FollowPuck State:Overview State:
Optional transition animation. Can be:Immediate Transition:Default Transition:
true if the transition was successful.
Examples:
Viewport States
FollowPuck State
Follows the user’s location (“puck”) with configurable camera settings.The zoom level to use. If
'keep', zoom will not be modified.Default: DEFAULT_FOLLOW_PUCK_VIEWPORT_STATE_ZOOMThe pitch (tilt) to use in degrees. If
'keep', pitch will not be modified.Default: DEFAULT_FOLLOW_PUCK_VIEWPORT_STATE_PITCH degreesIndicates how to obtain the bearing value:
'heading'- Sets bearing to the heading of the device'course'- Sets bearing based on the direction of travelnumber- Sets the camera bearing to a constant value'keep'- Bearing will not be modified
'heading' and 'course' both sync with the location puck’s bearing.The viewport padding. If
'keep', padding will not be modified.Object shape: { top?: number, left?: number, bottom?: number, right?: number }Overview State
Positions the camera to view a specific geometry.The geometry that the viewport should frame in the camera view.
The padding to use when calculating the camera.Object shape:
{ top?: number, left?: number, bottom?: number, right?: number }The bearing to use when calculating the camera.
The pitch to use when calculating the camera.
The length of the animation in seconds when the viewport starts updating the camera.
Examples
- Follow User
- Overview Route
- Status Monitoring
- Custom Interactions
Platform Documentation
Related Components
- Camera - Alternative camera control component
- MapView - The map container
- UserLocation - Display user location