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
.status
cannot 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
ViewportStatusObserver
tostatus
changes.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
observer
An object that will be notified when the
status
changes. -
Unsubscribes a
ViewportStatusObserver
fromstatus
changes. 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
observer
An object that should no longer be notified when the
status
changes. -
Sets
status
toidle
synchronously.This cancels any active
ViewportState
orViewportTransition
.Declaration
Swift
public func idle()
-
Executes a transition to the requested state.
If the transition fails,
status
is set toidle
.Transitioning to state
x
when the status is.state(x)
invokescompletion
synchronously withtrue
and does not modifystatus
.Transitioning to state
x
when the status is.transition(_, x)
invokescompletion
synchronously withfalse
and does not modifystatus
.Viewport
keeps 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
toState
The target
ViewportState
to transition to.transition
The
ViewportTransition
that is used to transition to the target state. Ifnil
,defaultTransition
is used. Defaults tonil
.completion
A closure that is invoked when the transition ends. Defaults to
nil
.success
Whether 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 itstransition
argument.Defaults to
DefaultViewportTransition
with default options.Declaration
Swift
public var defaultTransition: ViewportTransition { get set }
-
Creates a new instance of
FollowPuckViewportState
with the specified options.Declaration
Swift
public func makeFollowPuckViewportState(options: FollowPuckViewportStateOptions = .init()) -> FollowPuckViewportState
Parameters
options
configuration 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
OverviewViewportState
with the specified options.Declaration
Swift
public func makeOverviewViewportState(options: OverviewViewportStateOptions) -> OverviewViewportState
Parameters
options
configuration 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()) -> DefaultViewportTransition
Parameters
options
configuration 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() -> ImmediateViewportTransition
Return Value
The newly-created
ImmediateViewportTransition
.