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.getMapAsyncormapView.onMapReadyCallback.
-
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? -
Data source of the
TomTomMap.Declaration
Swift
public weak var dataSource: MapDataSource? -
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 } -
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. WhenMapOptions.mapStyle.darkStyleis not set, settingmap.styleMode = .darkwill 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 } -
An
Arrayof the mapLayers 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 } -
An array of
MapGestureDisableOptiondefines 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 } -
A container for the main and the dark versions of the
StyleDefinition.If
darkStyleis not provided, settingTomTomMap.styleModetodarkhas 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 } -
All
Routeobjects 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 } -
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 } -
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
gestureThe specified gesture to prioritize over the
blockedGestures. When this gesture is activated, it prevents the blocked gestures from being recognized or processed at the same time.blockedGesturesThe list of blocked gestures that are blocked when the specified
gestureis activated. -
Adds a new
Markerbased on the givenMarkerOptions.Throws
An error of typeAnnotationServiceErrorif 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 -> MarkerParameters
optionsAn instance of
MarkerOptionsdescribing the desired properties of theMarker.Return Value
An instance of
Markerrepresenting the marker that was added. -
Adds a new
Linebased on the givenLineOptions.Throws
An error of typeAnnotationServiceErrorif 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 -> LineParameters
optionsAn instance of
LineOptionsdescribing the desired properties of theLine.Return Value
An instance of
Linerepresenting the line that was added. -
Adds a new
Polygonbased on the givenPolygonOptions.Throws
An error of typeAnnotationServiceErrorif 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 -> PolygonParameters
optionsAn instance of
PolygonOptionsdescribing the desired properties of thePolygon.Return Value
An instance of
Polygonrepresenting the polygon that was added. -
Adds a new
PolygonOverlaybased on the givenPolygonOverlayOptions.Throws
An error of typeAnnotationServiceErrorif 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 -> PolygonOverlayParameters
optionsAn instance of
PolygonOverlayOptionsdescribing the desired properties of thePolygonOverlay.Return Value
An instance of
PolygonOverlayrepresenting the polygon overlay that was added. -
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
annotationAn instance of
Annotationdefining the annotation to be removed. -
Adds a new
Routebased on the givenRouteOptions.Throws
An error of typeRouteErrorif the route could not be added.Declaration
Swift
public func addRoute(_ options: RouteOptions) throws -> RouteParameters
optionsAn instance of
RouteOptionsdescribing the desired properties of theRoute.Return Value
An instance of
Routerepresenting the route that was added. -
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
tagDescribes the annotation group to be removed.
-
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
marginPxPadding between the coordinates and the camera borders, measured in pixels.
tagDescribes 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
tagDescribes the annotation group that has the given tag.
-
Removes all previously added
Routes.Declaration
Swift
public func removeRoutes() -
Adds a new
Circlebased on the givenCircleOptions.Throws
An error of typeAnnotationServiceErrorif 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 -> CircleParameters
optionsAn instance of
CircleOptionsdescribing the desired properties of theCircle.Return Value
An instance of
Circlerepresenting the circle that was added. -
Remove all annotations from the map that are tagless (tag is
nil).Note
An annotation tag isnilunless explicitly set.Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func removeAnnotations() -
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 isnilunless 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 isnilunless 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
marginPxPadding between the coordinates and the camera borders, measured in pixels.
-
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
rangeThe 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
rangeThe 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.
-
Returns an instance of
CLLocationCoordinate2Dfrom the givenCGPoint.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
pointAn instance of
CGPointrepresenting the point on the map.Return Value
An instance of
CLLocationCoordinate2Drepresenting the location on the map. -
Returns an instance of
CGPointfrom the givenCLLocationCoordinate2D.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
coordinateAn instance of
CLLocationCoordinate2Drepresenting the location on the map.Return Value
An instance of
CGPointrepresenting the point on the map. -
Zooms to all current
Routes with the given padding.Declaration
Swift
public func zoomToRoutes(padding: UInt)Parameters
paddingPadding between the coordinates and the camera borders.
-
Selects an annotation identified by the given
Annotation.Selecting an annotation delegates a call to
MapDelegateandMapDataSource.Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func select(annotation: Annotation)Parameters
annotationAn instance of
Annotationdefining the annotation to be selected. -
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
annotationAn instance of
Annotationdefining the annotation to be deselected. -
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() -> UIImageReturn Value
An instance of
UIImagerepresenting the snapshot of the map. -
Takes a snapshot of the map without the given
UIViews and return aUIImage.Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func snapshotWithoutViews(views: [UIView]) -> UIImageParameters
viewsInstances of
UIViewto be excluded from the snapshot.Return Value
An instance of
UIImagerepresenting the snapshot of the map. -
Fetches an
ArrayofLayers based on the given regex pattern.The regex is applied to the
Layer.idproperty.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
patternRegex pattern.
Return Value
Instances of fetched
Layer. -
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() -
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() -
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() -
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() -
Register a
TrafficIncidentObserverto 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
observerAn instances of
TrafficIncidentObserverto be notified. -
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() -
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()
-
Returns visible region of the map.
The visible region of the map is represented as
CLLocationCoordinate2Dcoordinates, 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 } -
Returns the current camera properties.
Camera properties can be: zoom, tilt, rotation, field of view, etc. These properties are updated when
applyCamera(_:animationDuration:completion:)ormoveCamera(_:)is called with conjunction to aCameraUpdateinstance, 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 lastCameraUpdatethat 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 } -
Applies a
CameraUpdatewith with a given duration for the animation.In the Map Display SDK, every change to the camera’s position must be done using the
CameraUpdateclass. TheCameraUpdateclass specifies the camera’s location, zoom, tilt, and rotation to set.Declaration
Swift
public func applyCamera( _ update: CameraUpdate, animationDuration: TimeInterval, completion: ((Bool) -> ())? )Parameters
updateThe
CameraUpdateinstance to be applied.animationDurationThe
TimeIntervaldurtaion it would take for the animation to be completed.completionThe completion handler that is triggered when the animation is finished.
-
Applies a
CameraUpdatewith no animation.In the Map Display SDK, every change to the camera’s position must be done using the
CameraUpdateclass. TheCameraUpdateclass specifies the camera’s location, zoom, tilt, and rotation to set.Declaration
Swift
public func moveCamera(_ update: CameraUpdate)Parameters
updateThe
CameraUpdateinstance to be applied. -
Stops the current ongoing
CameraUpdateanimation.This can be useful in cases where multiple
CameraUpdates are being dispatched and it is imperative to call this method in-between to prevent multiple animations colliding.Declaration
Swift
public func stopAnimation()
-
Fetches all map features, such as annotations and map layers at the given
CLLocationCoordinate2D.Declaration
Swift
public func mapFeatures(coordinate: CLLocationCoordinate2D) -> [RenderedFeature]Parameters
coordinateThe given
CLLocationCoordinate2Dto fetch the map features from.Return Value
An
ArrayofRenderedFeatures that were found at the given coordinate. -
Fetches all map features, such as annotations and map layers at the given
CLLocationCoordinate2Dfiltered by the givenRenderedFeatureQueryOptions.Declaration
Swift
public func mapFeatures(coordinate: CLLocationCoordinate2D, options: RenderedFeatureQueryOptions) -> [RenderedFeature]Parameters
coordinateThe given
CLLocationCoordinate2Dto fetch the map features from.optionsThe
RenderedFeatureQueryOptionsfilter to return specific rendered features at the given coordinate.Return Value
An
ArrayofRenderedFeatures that were found at the given coordinate filtered by the givenRenderedFeatureQueryOptions. -
Fetches all map features, such as annotations and map layers within the given
CoordinateBounds.Declaration
Swift
public func mapFeatures(coordinateBounds: CoordinateBounds) -> [RenderedFeature]Parameters
coordinateBoundsThe given
CoordinateBoundsfrom which to fetch the map features.Return Value
An
ArrayofRenderedFeatures that were found at the given coordinate bounds. -
Fetches all map features, such as annotations and map layers within the given
CoordinateBoundsfiltered by the givenRenderedFeatureQueryOptions.Declaration
Swift
public func mapFeatures(coordinateBounds: CoordinateBounds, options: RenderedFeatureQueryOptions) -> [RenderedFeature]Parameters
coordinateBoundsThe given
CoordinateBoundsto fetch the map features from.optionsThe
RenderedFeatureQueryOptionsfilter to return specific rendered features within the given coordinate bounds.Return Value
An
ArrayofRenderedFeatures that were found within the given coordinate bounds filtered by the givenRenderedFeatureQueryOptions.
-
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
LocationProvidermodule provides theDefaultLocationValidatoras a default validator, but it is also possible to create a custom one.Declaration
Swift
public var locationValidator: LocationValidator { get set } -
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.navigationChevronwith a scale of 1.Declaration
Swift
public var locationIndicatorType: LocationIndicator { get set } -
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.locationMight be called from a private queue.Declaration
Swift
public func activateLocationProvider() -
Stops the location engine.
The location engine stops updating the current location. Might be called from a private queue.
Declaration
Swift
public func deactivateLocationProvider()
-
Show vehicle restrictions layers on the map respective to the given
Vehicle.Throws
An error of typeVehicleRestrictionsErrorif the vehicle restrictions could not be shown.Declaration
Swift
public func showVehicleRestrictions(vehicle: any Vehicle) throwsParameters
vehicleAn instance of
Vehiclefor which to show vehicle restrictions. -
Show vehicle restrictions layers on the map respective to the current
Vehicle.If a
Vehiclewasn’t set, it is imperative to set theVehiclebefore calling this function, and reload the style after calling function to see the vehicle restrictions layers on the map.Throws
An error of typeVehicleRestrictionsErrorif the vehicle restrictions could not be shown.Declaration
Swift
public func showVehicleRestrictions() throws -
Hide vehicle restrictions layers from the map.
Declaration
Swift
public func hideVehicleRestrictions()
TomTom SDK for iOS (0.53.1)
TomTomMap