TomTomMap
public class TomTomMap : AnnotationsActions, RouteActions, MapActions
extension TomTomMap: CameraActions
extension TomTomMap: RenderedFeatureActions
extension TomTomMap: VehicleActions, LocationActions
The TomTomMap
class serves as the foundational class, 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.
TomTomMap
can be accessed in several ways through the MapView
class:
- Through the property
mapView.map
. - By calling
mapView.getMapAsync
, i.e.,mapView.getMapAsync { map in // do something with map }
- By assigning
mapView.onMapReadyCallback
, i.e.,mapView.onMapReadyCallback = { map in // do something with map }
- By defining
mapView(_:, onMapReady:)
through theMapDelegate
, i.e.,func mapView(_: MapView, onMapReady map: TomTomMap) { // do something with the map }
In most cases, the preferred way to access the map would be through the propertymapView.map
, but in some cases where the map should be ready first, such as when callingshowVehicleRestrictions(vehicle:)
the preferred way would bemapView.getMapAsync
ormapView.onMapReadyCallback
.
Starts the location engine.
The location engine will start updating the current location.
After starting the location engine, it is possible to receive the last known location by calling:
mapView.map.locationProvider.location
Might be called from a private queue.
Declaration
Swift
public func activateLocationProvider()
Adds a new Circle
based on the given CircleOptions
.
Throws
An error of typeAnnotationServiceError
if the circle could not be added.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func addCircle(options: CircleOptions) throws -> Circle
Parameters
options
|
An instance of |
Return Value
An instance of Circle
representing the circle that was added.
Adds a new Line
based on the given LineOptions
.
Throws
An error of typeAnnotationServiceError
if the line could not be added.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func addLine(options: LineOptions) throws -> Line
Parameters
options
|
An instance of |
Return Value
An instance of Line
representing the line that was added.
Adds a new Marker
based on the given MarkerOptions
.
Throws
An error of typeAnnotationServiceError
if the marker could not be added.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func addMarker(options: MarkerOptions) throws -> Marker
Parameters
options
|
An instance of |
Return Value
An instance of Marker
representing the marker that was added.
Adds a new Polygon
based on the given PolygonOptions
.
Throws
An error of typeAnnotationServiceError
if the polygon could not be added.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func addPolygon(options: PolygonOptions) throws -> Polygon
Parameters
options
|
An instance of |
Return Value
An instance of Polygon
representing the polygon that was added.
Adds a new PolygonOverlay
based on the given PolygonOverlayOptions
.
Throws
An error of typeAnnotationServiceError
if the polygon overlay could not be added.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func addPolygonOverlay(options: PolygonOverlayOptions) throws -> PolygonOverlay
Parameters
options
|
An instance of |
Return Value
An instance of PolygonOverlay
representing the polygon overlay that was added.
Adds a new Route
based on the given RouteOptions
.
Throws
An error of typeRouteError
if the route could not be added.
Declaration
Swift
public func addRoute(_ options: RouteOptions) throws -> Route
Parameters
options
|
An instance of |
Return Value
An instance of Route
representing the route that was added.
All Route
objects that are currently rendered on the map.
This can be useful when doing collective actions on all routes, such as changing color, setting delegates, etc.
For example, changing the color of all routes to UIColor.gray
:
map.allRoutes.forEach { $0.color = .gray }
Declaration
Swift
public var allRoutes: [Route] { get }
Applies a CameraUpdate
with with a given duration for the animation.
In the Map Display SDK, every change to the camera’s position must be done using the CameraUpdate
class.
The CameraUpdate
class specifies the camera’s location, zoom, tilt, and rotation to set.
Declaration
Swift
public func applyCamera(
_ update: CameraUpdate,
animationDuration: TimeInterval,
completion: ((Bool) -> ())?
)
Parameters
update
|
The |
animationDuration
|
The |
completion
|
The completion handler that is triggered when the animation is finished. |
Returns the current camera properties.
Camera properties can be: zoom, tilt, rotation, field of view, etc.
These properties are updated when applyCamera(_:animationDuration:completion:)
or moveCamera(_:)
is called
with conjunction to a CameraUpdate
instance, or when the map camera has changed as the result of gesturing.
The camera properties reflects the current state of the camera, therefore it can be as the last CameraUpdate
that was applied or the altered state
of the camera after gesturing.
Declaration
Swift
public var cameraProperties: CameraProperties { get }
Represents how the camera follows the current position.
There are five available tracking modes:
- none: No camera tracking.
- followNorthUp: Camera follows the current position.
- followRouteDirection: Camera follows the current position and heading, while adjusting tilt and scale to best present the route and its guidance instructions.
- followDirection: Camera follows the current position and heading.
- routeOverview: The operator tries to fit the routes in the current view, by changing the camera zoom and look-at parameters. It constantly adjusts these parameters to keep the remaining part of the route(s) in view. Tilt and heading parameters are set to 0 in this camera mode.
Declaration
Swift
public var cameraTrackingMode: CameraTrackingMode { get set }
Returns an instance of CLLocationCoordinate2D
from the given CGPoint
.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func coordinateForPoint(point: CGPoint) -> CLLocationCoordinate2D?
Parameters
point
|
An instance of |
Return Value
An instance of CLLocationCoordinate2D
representing the location on the map.
Data source of the TomTomMap
.
Declaration
Swift
public weak var dataSource: MapDataSource?
Stops the location engine.
The location engine stops updating the current location. Might be called from a private queue.
Declaration
Swift
public func deactivateLocationProvider()
Delegate of the TomTomMap
.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public weak var delegate: MapDelegate?
Deselects an annotation identified by the given Annotation
.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func deselect(annotation: Annotation)
Parameters
annotation
|
An instance of |
An array of MapGestureDisableOption
defines the map gestures to be disabled.
You can disable certain gestures, for example, double tapping and tapping by assigning these gestures to this field:
map.disabledGestures = [.doubleTap, .tap]
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public var disabledGestures: [MapGestureDisableOption] { get set }
Hide hillshading layers from the map.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func hideHillshading()
Hide traffic flow layers from the map.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func hideTraffic()
Hide traffic incidents layers from the map.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func hideTrafficIncidents()
Hide vehicle restrictions layers from the map.
Declaration
Swift
public func hideVehicleRestrictions()
A Boolean value indicating whether marker fading is allowed or not.
Marker fading means that as you move farther from a marker on the map, it progressively fades out to reflect increasing distance.
By default this value is false
.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public var isMarkersFadingEnabled: Bool { get set }
A Boolean value indicating whether marker shrinking is allowed or not.
Marker shrinking means that as you move farther from a marker on the map, it gradually shrinks in size to reflect increasing distance.
By default this value is false
.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public var isMarkersShrinkingEnabled: Bool { get set }
The language to be used for labels returned in the response. It should be one of the supported IETF language code tags described here or one of the custom language tags. When data in a specified language is not available for a specific label, the default language is used. Default value: NGT (Neutral Ground Truth)
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public var language: Locale { get set }
An Array
of the map Layer
s included in a given style.
Map layers are map elements, for example: Borders, Background, Traffic Incidents, Markers, Labels, etc.
Each element of the array contains all the information needed to render a layer.
Note that a single element of a map, such as a road, may consist of several layers.
You can hide specific map layers to get the level of detail you need and highlight the layers that are important for your use case.
For example, you can toggle the visibility of the background layer using layersForRegexp(pattern:)
:
let layers = try? map.layersForRegexp(pattern: NSRegularExpression(pattern: "background", options: []))
layers?.forEach { $0.isVisible = false } // The background layer won't show on the map.
layers?.forEach { $0.isVisible = true } // The background layer shows on the map.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public var layers: [Layer] { get }
Fetches an Array
of Layer
s based on the given regex pattern.
The regex is applied to the Layer.id
property.
Example:
let roads = NSRegularExpression(pattern: ".*[rR]oad.*", options: [])) mapView.map.layersForRegexp(pattern: roads)
Important
This is a Public Preview API. It may be changed or removed at any time.
Declaration
Swift
public func layersForRegexp(pattern: NSRegularExpression) -> [Layer]
Parameters
pattern
|
Regex pattern. |
Return Value
Instances of fetched Layer
.
Type of the location marker’s visualization.
Can be used to change the location marker’s scale and or image, the options are:
- navigationChevron: The location marker is rendered in a chevron pattern that can be added to the marker’s scale.
- userLocation: The location marker is rendered as a position marker, with the heading to be added to the marker’s scale.
- custom: Gives the ability to add a custom .glb model as a location indicator.
The project path that the custom model should be provided to is as follows:
asset://file.glb
. Markers size will be changed depending on current zoom level and scale parameter. For more information about the model core requirements and supported features, refer toLocationIndicator.custom
. - none: No location marker will be rendered on the map.
The default marker is LocationIndicator.navigationChevron
with a scale of 1.
Declaration
Swift
public var locationIndicatorType: LocationIndicator { get set }
Provides different location services.
The location services are:
start()
: Starts the location engine. It might be called from a private queue.
stop()
: Stops the location engine. It might be called from a private queue.
location
: The last location received. It will be nil until a location has been received.
addObserver
: Add an observer to the location engine.
removeObserver
: Remove an observer from the location engine.
Declaration
Swift
public var locationProvider: LocationProvider { get set }
Validates if the location is valid or not.
Validation is checked by if the location is fixed or not.
The GPS fix status indicates the quality of the signal, or the accuracy and reliability of the location being reported.
The LocationProvider
module provides the DefaultLocationValidator
as a default validator,
but it is also possible to create a custom one.
Declaration
Swift
public var locationValidator: LocationValidator { get set }
Fetches all map features, such as annotations and map layers at the given CLLocationCoordinate2D
.
Declaration
Swift
public func mapFeatures(coordinate: CLLocationCoordinate2D) -> [RenderedFeature]
Parameters
coordinate
|
The given |
Return Value
An Array
of RenderedFeature
s that were found at the given coordinate.
Fetches all map features, such as annotations and map layers at the given CLLocationCoordinate2D
filtered by the given
RenderedFeatureQueryOptions
.
Declaration
Swift
public func mapFeatures(coordinate: CLLocationCoordinate2D, options: RenderedFeatureQueryOptions) -> [RenderedFeature]
Parameters
coordinate
|
The given |
options
|
The |
Return Value
An Array
of RenderedFeature
s that were found at the given coordinate filtered by the given RenderedFeatureQueryOptions
.
Fetches all map features, such as annotations and map layers within the given CoordinateBounds
.
Declaration
Swift
public func mapFeatures(coordinateBounds: CoordinateBounds) -> [RenderedFeature]
Parameters
coordinateBounds
|
The given |
Return Value
An Array
of RenderedFeature
s that were found at the given coordinate bounds.
Fetches all map features, such as annotations and map layers within the given CoordinateBounds
filtered by the given
RenderedFeatureQueryOptions
.
Declaration
Swift
public func mapFeatures(coordinateBounds: CoordinateBounds, options: RenderedFeatureQueryOptions) -> [RenderedFeature]
Parameters
coordinateBounds
|
The given |
options
|
The |
Return Value
An Array
of RenderedFeature
s that were found within the given coordinate bounds filtered by the given RenderedFeatureQueryOptions
.
Applies a CameraUpdate
with no animation.
In the Map Display SDK, every change to the camera’s position must be done using the CameraUpdate
class.
The CameraUpdate
class specifies the camera’s location, zoom, tilt, and rotation to set.
Declaration
Swift
public func moveCamera(_ update: CameraUpdate)
Parameters
update
|
The |
Returns an instance of CGPoint
from the given CLLocationCoordinate2D
.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func pointForCoordinate(coordinate: CLLocationCoordinate2D) -> CGPoint?
Parameters
coordinate
|
An instance of |
Return Value
An instance of CGPoint
representing the point on the map.
Register a TrafficIncidentObserver
to be notified about traffic incidents clicks.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func registerTrafficIncidentObserver(_ observer: TrafficIncidentObserver)
Parameters
observer
|
An instances of |
Removes an annotation from the map with the given Annotation
.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func remove(annotation: Annotation)
Parameters
annotation
|
An instance of |
Remove all annotations from the map that are tagless (tag is nil
).
Note
An annotation tag isnil
unless explicitly set.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func removeAnnotations()
Removes annotations having a particular tag from the map.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func removeAnnotations(tag: String)
Parameters
tag
|
Describes the annotation group to be removed. |
Removes all previously added Route
s.
Declaration
Swift
public func removeRoutes()
Selects an annotation identified by the given Annotation
.
Selecting an annotation delegates a call to MapDelegate
and MapDataSource
.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func select(annotation: Annotation)
Parameters
annotation
|
An instance of |
Sets the exclusive map gestures, prioritizing the specified gesture while blocking others gestures that happen simultaneously.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func setExclusiveGestures(gesture: GestureType, blockedGestures: [GestureType])
Parameters
gesture
|
The specified gesture to prioritize over the |
blockedGestures
|
The list of blocked gestures that are blocked when the specified |
Sets the marker distance fading range.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func setMarkerDistanceFadingRange(range: ClosedRange<Measurement<UnitLength>>)
Parameters
range
|
The marker distance fading range, the default range is 990.0m for the lower bound and 1000.0m for the upper bound, which means it progressively fades in a distance span of 10m when it reaches the distance of the lower bound. |
Sets the marker distance shrinking range.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func setMarkerDistanceShrinkingRange(range: ClosedRange<Measurement<UnitLength>>)
Parameters
range
|
The marker distance shrinking range, the default range is 500.0m for the lower bound and 1000.0m for the upper bound, meaning it gradually shrinks in a distance span of 500m when it reaches a distance of the lower bound. |
Show hillshading layers on the map.
Hillshading is an image pyramid that contains elevation data with terrain representation. It can be used for rendering hillshade that shows the topographical shape of hills and mountains.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func showHillshading()
Traffic flow shows the difference between current and free-flow speed.
These differences are represented by the following colors: Green indicates that the speeds are the same, meaning there are no traffic jams. Red indicates that traffic is slower than free-flow, meaning that there are traffic jams. You can show real-time traffic flow layers on the map by calling this method.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func showTraffic()
Traffic incidents shows specific traffic problems such as closed roads, rain, ice on the road, or accidents.
You can show real-time traffic incidents layers on the map by calling this method.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func showTrafficIncidents()
Show vehicle restrictions layers on the map respective to the current Vehicle
.
If a Vehicle
wasn’t set, it is imperative to set the Vehicle
before calling this function, and reload the style
after calling function to see the vehicle restrictions layers on the map.
Throws
An error of typeVehicleRestrictionsError
if the vehicle restrictions could not be shown.
Declaration
Swift
public func showVehicleRestrictions() throws
Show vehicle restrictions layers on the map respective to the given Vehicle
.
Throws
An error of typeVehicleRestrictionsError
if the vehicle restrictions could not be shown.
Declaration
Swift
public func showVehicleRestrictions(vehicle: any Vehicle) throws
Parameters
vehicle
|
An instance of |
Takes a snapshot of the map and return a UIImage
.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func snapshot() -> UIImage
Return Value
An instance of UIImage
representing the snapshot of the map.
Takes a snapshot of the map without the given UIView
s and return a UIImage
.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func snapshotWithoutViews(views: [UIView]) -> UIImage
Parameters
views
|
Instances of |
Return Value
An instance of UIImage
representing the snapshot of the map.
Stops the current ongoing CameraUpdate
animation.
This can be useful in cases where multiple CameraUpdate
s are being dispatched and it is imperative to call this method in-between
to prevent multiple animations colliding.
Declaration
Swift
public func stopAnimation()
A container for the main and the dark versions of the StyleDefinition
.
If darkStyle
is not provided, setting TomTomMap.styleMode
to dark
has no effect.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public var styleContainer: StyleContainer { get set }
Defines the map styles available to the user.
main
: By default this is the TomTom light style.
dark
: By default this is the TomTom dark style.
When MapOptions.mapStyle.darkStyle
is not set,
setting map.styleMode = .dark
will have no effect.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public var styleMode: StyleMode { get set }
Returns visible region of the map.
The visible region of the map is represented as CLLocationCoordinate2D
coordinates, where:
farLeft: The far-left coordinate.
nearLeft: The near-left coordinate.
farRight: The far-right coordinate.
nearRight: The near-right coordinate.
Declaration
Swift
public var visibleRegion: VisibleRegion { get }
Zooms to the all markers on the map that are tagless (tag is nil
) to fit them all on the screen with a 0px margin.
Note
An annotation tag isnil
unless explicitly set.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func zoomToMarkers()
Zooms to all markers on the map that are tagless (tag is nil
) so they all fit the screen with the given margin.
Note
An annotation tag isnil
unless explicitly set.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func zoomToMarkers(marginPx: UInt)
Parameters
marginPx
|
Padding between the coordinates and the camera borders, measured in pixels. |
Zooms to the current markers on the map with the given tag to fit them all on the screen with the given margin.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func zoomToMarkers(marginPx: UInt, tag: String)
Parameters
marginPx
|
Padding between the coordinates and the camera borders, measured in pixels. |
tag
|
Describes the annotation group that has the given tag. |
Zooms to the current markers on the map with the given tag to fit them all on the screen with a 0px margin.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func zoomToMarkers(tag: String)
Parameters
tag
|
Describes the annotation group that has the given tag. |
Zooms to all current Route
s with the given padding.
Declaration
Swift
public func zoomToRoutes(padding: UInt)
Parameters
padding
|
Padding between the coordinates and the camera borders. |