Viewport
public final class Viewport
Viewport provides a structured approach to organizing camera management logic into states and
transitions between them.
At any given time, the viewport is either:
- idle (not updating the camera)
- in a state (camera is being managed by a
ViewportState) - transitioning (camera is being managed by a
ViewportTransition)
-
Configuration options for adjusting the viewport’s behavior.
Declaration
Swift
public var options: ViewportOptions { get set } -
The current
ViewportStatus.statuscannot be set directly. Usetransition(to:transition:completion:)andidle()to transition to a state or to idle.Defaults to
idle.Declaration
Swift
public var status: ViewportStatus { get } -
Subscribes a
ViewportStatusObservertostatuschanges.Viewport keeps a strong reference to registered observers. Adding the same observer again while it is already subscribed has no effect.
Note
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.See also
removeStatusObserver(_:)Declaration
Swift
public func addStatusObserver(_ observer: ViewportStatusObserver)Parameters
observerAn object that will be notified when the
statuschanges. -
Unsubscribes a
ViewportStatusObserverfromstatuschanges. This causes viewport to release its strong reference to the observer. Removing an observer that is not subscribed has no effect.See also
addStatusObserver(_:)Declaration
Swift
public func removeStatusObserver(_ observer: ViewportStatusObserver)Parameters
observerAn object that should no longer be notified when the
statuschanges. -
Sets
statustoidlesynchronously.This cancels any active
ViewportStateorViewportTransition.Declaration
Swift
public func idle() -
Executes a transition to the requested state.
If the transition fails,
statusis set toidle.Transitioning to state
xwhen the status is.state(x)invokescompletionsynchronously withtrueand does not modifystatus.Transitioning to state
xwhen the status is.transition(_, x)invokescompletionsynchronously withfalseand does not modifystatus.Viewportkeeps a strong reference to active transitions and states. To reuse states and transitions, keep strong references to them in the consuming project.Declaration
Swift
public func transition(to toState: ViewportState, transition: ViewportTransition? = nil, completion: ((_ success: Bool) -> Void)? = nil)Parameters
toStateThe target
ViewportStateto transition to.transitionThe
ViewportTransitionthat is used to transition to the target state. Ifnil,defaultTransitionis used. Defaults tonil.completionA closure that is invoked when the transition ends. Defaults to
nil.successWhether the transition ran to completion. Transitions may end early if they fail or are interrupted (e.g. by another call to
transition(to:transition:completion:)oridle()) -
transition(to:transition:completion:)uses this transition unless some non-nil value is passed to itstransitionargument.Defaults to
DefaultViewportTransitionwith default options.Declaration
Swift
public var defaultTransition: ViewportTransition { get set } -
Creates a new instance of
FollowPuckViewportStatewith the specified options.Declaration
Swift
public func makeFollowPuckViewportState(options: FollowPuckViewportStateOptions = .init()) -> FollowPuckViewportStateParameters
optionsconfiguration options used when creating
FollowPuckViewportState. Defaults toFollowPuckViewportStateOptions/init(padding:zoom:bearing:pitch:animationDuration:)with the default value specified for all parameters.Return Value
The newly-created
FollowPuckViewportState. -
Creates a new instance of
OverviewViewportStatewith the specified options.Declaration
Swift
public func makeOverviewViewportState(options: OverviewViewportStateOptions) -> OverviewViewportStateParameters
optionsconfiguration options used when creating
OverviewViewportState.Return Value
The newly-created
OverviewViewportState. -
Creates a new instance of
DefaultViewportTransition.Declaration
Swift
public func makeDefaultViewportTransition(options: DefaultViewportTransitionOptions = .init()) -> DefaultViewportTransitionParameters
optionsconfiguration options used when creating
DefaultViewportTransition. Defaults toinit(maxDuration:)with the default value specified for all parametersReturn Value
The newly-created
DefaultViewportTransition. -
Creates a new instance of
ImmediateViewportTransition.Declaration
Swift
public func makeImmediateViewportTransition() -> ImmediateViewportTransitionReturn Value
The newly-created
ImmediateViewportTransition.
Viewport Class Reference