Viewport
@available(iOS 13.0, *)
@_documentation(visibility: public)
@_spi(Experimental)
public struct Viewport : Equatable
The viewport represents the ways to position camera.
The viewport may be set to the map as initial viewport:
Map(initialViewport: .styleDefault)
or as binding:
struct UserLocationMap: View {
@State var viewport: Viewport = .followPuck(zoom: 16, bearing: .heading)
var body: some View {
Map(viewport: $viewport)
}
}
Viewport change can be animated via the withViewportAnimation(_:body:completion:).
struct AnimatedMap: View {
@State var viewport: Viewport = .styleDefault
var body: some View {
Map(viewport: $viewport)
.overlay {
Button("Locate the user") {
withViewportAnimation {
viewport = .followPuck(zoom: 16, bearing: .heading, pitch: 60)
}
}
}
}
}
-
Options for the overview viewport.
See moreDeclaration
Swift
@_documentation(visibility: public) public struct OverviewOptions : Equatable -
Options for the follow puck viewport.
See moreDeclaration
Swift
@_documentation(visibility: public) public struct FollowPuckOptions : Equatable -
Represent insets configuration.
Inset configuration is applicable to every kind of viewport configuration except
idle.Declaration
Swift
@_documentation(visibility: public) public struct InsetOptions : Equatable -
Configures insets of viewport.
Declaration
Swift
@_documentation(visibility: public) public var insetOptions: Viewport.InsetOptions -
Idle viewport represents the state when user freely drags the map.
The viewport is automatically switches to
idlestate when the user starts dragging the map. Setting theidleviewport results in cancelling any ongoing camera animation.Declaration
Swift
@_documentation(visibility: public) public static var idle: Viewport { get } -
Sets camera to the default camera options defined in the current style.
See more in the Mapbox Style Specification.
Declaration
Swift
@_documentation(visibility: public) public static var styleDefault: Viewport { get } -
Manually sets camera to specified properties.
Declaration
Swift
@_documentation(visibility: public) public static func camera(center: CLLocationCoordinate2D? = nil, anchor: CGPoint? = nil, zoom: CGFloat? = nil, bearing: CLLocationDirection? = nil, pitch: CGFloat? = nil) -> ViewportParameters
centerThe geographic coordinate that will be rendered at the midpoint of the map.
anchorPoint in the map’s coordinate system about which
zoomandbearingshould be applied. Mutually exclusive withcenter.zoomThe zoom level of the map.
bearingThe bearing of the map, measured in degrees clockwise from true north.
pitchPitch toward the horizon measured in degrees, with 0 degrees resulting in a top-down view for a two-dimensional map.
Return Value
A viewport configured with given camera settings.
-
Configures camera to show overview of the specified geometry.
Declaration
Swift
@_documentation(visibility: public) public static func overview( geometry: GeometryConvertible, bearing: CGFloat = 0, pitch: CGFloat = 0 ) -> ViewportParameters
geometryGeometry to show.
bearingThe bearing of the map, measured in degrees clockwise from true north.
pitchPitch toward the horizon measured in degrees, with 0 degrees resulting in a top-down view for a two-dimensional map.
Return Value
A viewport configured with given overview settings.
-
Configures camera to follow the user location indicator.
Note
It’s recommended to use only the
defaultanimation option for transition to thefollowPuckviewport, because it handles the moving user location puck. Other animation options such aseaseIn,easeOut,easeInOut,linear, orflydon’t support this.Declaration
Swift
@_documentation(visibility: public) public static func followPuck(zoom: CGFloat, bearing: FollowPuckViewportStateBearing = .constant(0), pitch: CGFloat = 0) -> ViewportParameters
zoomZoom level of the map.
bearingBearing of the map.
pitchPitch toward the horizon measured in degrees, with 0 degrees resulting in a top-down view for a two-dimensional map.
Return Value
A viewport configured to follow the user location puck.
-
Creates a new MapViewport with modified inset options.
Insets are ignored for
idleviewport.By default, insets are equal to the safe area. This method allows you to set additional insets, or ignore safe area part on the specified edges.
Declaration
Swift
@_documentation(visibility: public) public func inset(by insets: SwiftUI.EdgeInsets, ignoringSafeArea: Edge.Set = []) -> ViewportParameters
insetsAdditional insets, that will be summarized with existing safe area insets.
ignoringSafeAreaA set of edges where safe area’s contribution to the resulting inset should be ignored.
Return Value
A viewport with modified inset options.
-
Creates a new MapViewport with modified inset options.
Insets are ignored for
idleviewport.By default, insets are equal to the safe area. This method allows you to set additional inset for the specified edges. This method can be called multiple times to configure different edges.
Declaration
Swift
@_documentation(visibility: public) public func inset(edges: Edge.Set, length: CGFloat, ignoringSafeArea: Bool = false) -> ViewportParameters
edgesEdges for which to set the additional inset.
lengthThe length of inset.
ignoringSafeAreaIf safe area’s contribution should be ignored for the specified edges.
Return Value
A viewport with modified inset options.
-
Is
truewhen viewport is idle.Declaration
Swift
@_documentation(visibility: public) public var isIdle: Bool { get } -
Is
truewhen camera is configured from the default style camera properties.Declaration
Swift
@_documentation(visibility: public) public var isStyleDefault: Bool { get } -
Returns the camera options if viewport is configured with camera options.
Note
TheCameraOptionsis ignored, it is replaced withinsetOptions, seeinset(by:ignoringSafeArea:).Declaration
Swift
@_documentation(visibility: public) public var camera: CameraOptions? { get } -
Returns the overview options if viewport is configured to overview the specified geometry.
Declaration
Swift
@_documentation(visibility: public) public var overview: OverviewOptions? { get } -
Returns the follow puck options if viewport is configured to follow the user location puck.
Declaration
Swift
@_documentation(visibility: public) public var followPuck: FollowPuckOptions? { get }
Viewport Structure Reference