MapView
@objc
open class MapView : UIView
The MapView
object to wrap the underlying map renderer.
It contains the map created by the renderer in the view hierarchy and provides UI and view life-cycle functionalities. The view can be created programmatically, via xib or storyboards.
For example, displaying a simple MapView
programmatically using a constraints-based layout:
Initialization:
lazy var mapView: MapView = {
let mapOptions = MapOptions(mapStyle: .defaultStyle, apiKey: "your-key")
let mapView = MapView(mapOptions: mapOptions)
return mapView
}()
Layout:
mapView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(mapView)
NSLayoutConstraint.activate([
mapView.widthAnchor.constraint(equalTo: view.widthAnchor),
mapView.heightAnchor.constraint(equalTo: view.heightAnchor),
])
Setting up the receival of life-cycle events and updates, as well as setting the initial zoom and position of the map view:
mapView.delegate = self
mapView.cameraUpdate = .init(position: .AMSTERDAM, zoom: 13)
There will also be a need to conform your UIViewController
to MapViewDelegate
and implement the required methods.
-
MapView
init method.Ensure that
MapsDisplayService.apiKey
is set before calling this method, or use thepublic init(mapOptions: MapOptions)
initializer as follows:lazy var mapView: MapView = { let mapOptions = MapOptions(apiKey: "YOUR MAP KEY") let mapView = MapView(mapOptions: mapOptions) return mapView }()
Declaration
Swift
public convenience init()
-
MapView
init method, initializes the map with the givenMapOptions
.If
MapsDisplayService.apiKey
was set before calling this method, it will be overwritten with theMapOptions
apiKey.Declaration
Swift
@objc public init(mapOptions: MapOptions)
Parameters
mapOptions
The map options.
-
MapView
init method.Ensure that
MapsDisplayService.apiKey
is set before calling this method, or use thepublic init(mapOptions: MapOptions)
initializer as follows:lazy var mapView: MapView = { let mapOptions = MapOptions(apiKey: "YOUR MAP KEY") let mapView = MapView(mapOptions: mapOptions) return mapView }()
Declaration
Swift
override public convenience init(frame: CGRect)
Parameters
frame
The view frame.
-
MapView
init with coder method.If you are using xib or storyboards, ensure that make sure that
MapsDisplayService.apiKey
is set before loading theMapView
.Declaration
Swift
public required init?(coder: NSCoder)
Parameters
coder
The coder object used to decode the
UIView
-
Forces the rendering view to redraw when the constraints-based layout is applied.
This is used to synchronize the layout and the rendering view when constraints-based layout is applied.
Declaration
Swift
override open func layoutSubviews()
-
The
MapViewDelegate
protocol that informs you when theMapView
object is ready to be used.Declaration
Swift
public weak var delegate: MapViewDelegate?
-
The map management object acting as the primary gateway for integrating a multitude of map-related features.
It offers a rich set of functionalities enabling developer interaction with the map and customizing its behavior. For more information, refer to
TomTomMap
.Declaration
Swift
public private(set) lazy var map: TomTomMap { get set }
-
Tells the closure that the specified map view is ready to be used.
When the map view is fully initialized you can use the
TomTomMap
object to interact with it. The closure passes the ready-to-useTomTomMap
of the fully initializedMapView
.Declaration
Swift
public var onMapReadyCallback: ((TomTomMap) -> ())?
-
Notifies when a new frame is rendered as a texture.
When set, rendering performance may drop.
Important
Frame capture is supported only when using Metal renderer.Declaration
Swift
public weak var rendererFrameCaptureDelegate: MapRendererFrameCaptureDelegate? { get set }
-
Object for setting the map camera. Use it to set parameters such as:
- Position
- Zoom
- Tilt
- Rotation
Can be used with
UIView.animated
.
Example:
UIView.animate(withDuration: 5, delay: 2, options: [.beginFromCurrentState, .allowUserInteraction, .curveEaseIn], animations: { self.mapView.cameraUpdate = CameraUpdate(rotation: 180.0) }) { _ in }
}
Declaration
Swift
public var cameraUpdate: CameraUpdate { get set }
-
Preferred frames per second. Default value: 60 fps.
The application’s view will choose a frame rate as close as possible to the chosen preferred frames per second based on the capabilities of the screen’s refresh rate.
Declaration
Swift
public var preferredFramesPerSecond: Int { get set }
-
Sets the scale view’s unit system.
The scale view is located in the lower-right corner of the map. It appears when zooming in or out, then disappears after 5 seconds without any map interaction. It also disappears when the map is tilted or when the scale is out of range.
By default the units are set to metric or imperial based on the system settings. You can change them by modifying this property. For example:
mapView.scaleViewUnitSystem = .uk // UK units system. mapView.scaleViewUnitSystem = .us // US units system. mapView.scaleViewUnitSystem = .metric // Metric units system.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public var scaleViewUnitSystem: UnitsSystem { get set }
-
Sets the edge insets of the map view to determine space for the safe area.
The safe area is the part of the viewport that is considered completely visible by the user, not covered by UI components such as buttons or sliders.
By default, the edge insets are zero.
Declaration
Swift
public var contentInsets: NSDirectionalEdgeInsets { get set }
Parameters
contentInsets
The directional edge insets to set.
-
Replaces the list of data providers used as an alternative tile source.
Tiles from the old data providers are loaded through the new data providers. If no data provider loads, the default data provider is used internally.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func replaceDataProviders(_ dataProviders: [MapDisplayDataProvider])
Parameters
dataProviders
The data providers that are alternative tile sources.
-
The layout guide that represents the portion of the map view obscured by map scale.
A
UILayoutGuide
represent a rectangle in the layout engine. It will not be part of the view hierarchy, but may be applied withNSLayoutConstraint
.Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public var mapButtonsBottomSafeAreaLayoutGuide: UILayoutGuide { get }
-
A Boolean value that determines whether the map view is hidden.
Declaration
Swift
override public var isHidden: Bool { get set }
-
Sets a closure that will be triggered when the map instance is ready to use. The closure will be executed on the main thread.
When the map view is fully initialized you can use the
TomTomMap
object to interact with it. The closure passes the ready-to-useTomTomMap
of the fully initializedMapView
.Declaration
Swift
public func getMapAsync(closure: @escaping (TomTomMap) -> ())
Parameters
closure
The closure which handles the result.
-
Tells the view that its window object changed.
Additionally, this implementation validates the display link of the renderer, and adds the current location button to the map view if the view hierarchy is ready.
Declaration
Swift
override public func didMoveToWindow()
-
Tells the view that its superview changed.
Additionally, this implementation validates the display link of the renderer.
Declaration
Swift
override public func didMoveToSuperview()
-
Sets the scale view visibility on the map.
Declaration
Swift
public var isScaleViewVisible: Bool { get set }
-
Sets the logo view visibility on the map.
Declaration
Swift
public var isLogoVisible: Bool { get set }
-
Compass button visibility policy.
See moreDeclaration
Swift
public enum CompassButtonVisibilityPolicy
-
Sets the control compass button visibility on the map. Default value:
.visibleWhenNeeded
Declaration
Swift
public var compassButtonVisibilityPolicy: CompassButtonVisibilityPolicy { get set }
-
Current location button visibility policy.
See moreDeclaration
Swift
public enum CurrentLocationButtonVisibilityPolicy
-
Sets the control current location visibility on the map. Default value:
.hidden
Declaration
Swift
public var currentLocationButtonVisibilityPolicy: CurrentLocationButtonVisibilityPolicy { get set }
-
Whether the current location button is visible at the moment.
Declaration
Swift
public var isCurrentLocationButtonVisible: Bool { get }