@_spi(Experimental) public protocol ViewportState : AnyObject
ViewportState is a protocol that
Viewport depends on as it orchestrates transitions to and
from different states.
ViewportState is a reference type and must not be shared among multiple
observeDataSource(with:) method allows
ViewportTransitions to consume a stream of camera updates from a target state while
executing a transition.
stopUpdatingCamera() are invoked to tell the state that it should assume or
relinquish control of the map’s camera. These are typically used by
Viewport itself after a
successful transition into a state and when exiting a state, respectively.
MapboxMaps provides implementations of
ViewportState that can be created and configured
via methods on
Viewport. Applications may also define their own implementations to handle
advanced use cases not covered by the provided implementations.
States should generally pre-warm their data sources as soon as they are created to minimize delays when they become current. For this reason, only states that are currently (or soon-to-be) needed should be kept alive so that unneeded resources (e.g. location services) can be released.
handlerto receive the cameras being generated by this
This method is commonly used by
ViewportTransitionimplementations to obtain the target camera for transition animations. Transitions typically cannot start their animations until after
handleris invoked for the first time, so it’s a good idea for states to invoke
handlerwith the current camera if it’s not too stale rather than waiting for the next camera change to occur. To increase the likelihood that a valid camera exists when a handler is registered, design
ViewportStateimplementations so that they start updating their internal state prior to when they are passed to
The caller may either cancel the returned
handlerto indicate that it wishes to stop receiving updates. Following either of these events, implemenations must no longer invoke
handlerand must release all strong references to it.
A closure that is invoked by the state whenever its camera changes. Returns
trueto stay subscribed and
handlermust be invoked on the main queue.
ViewportState‘s most recent camera.
Cancelablethat the caller can use to unsubscribe.
Tells this state that it is now responsible for updating the camera.
Viewportcalls this method at the end of a successful transition into this state.
Implementations typically have a dependency on either
MapboxMapso that they can use its
setCamera(to:)method to change the camea or on
CameraAnimationsManagerso that they can run camera animations.
Tells this state that it is no longer responsible for updating the camera.
Viewportcalls this method at the beginning of the transition out of this state.
Implementations must stop updating the camera immediately and should typically cancel any ongoing animations that they started when this method is invoked.