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 the MapDelegate, 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 property mapView.map, but in some cases where the map should be ready first, such as when calling showVehicleRestrictions(vehicle:) the preferred way would be mapView.getMapAsync or mapView.onMapReadyCallback.

Public

  • 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. 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 }
  • An Array of the map Layers 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 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 }
  • 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 }
  • 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 }
  • 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

    gesture

    The 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.

    blockedGestures

    The list of blocked gestures that are blocked when the specified gesture is activated.

  • Adds a new Marker based on the given MarkerOptions.

    Throws

    An error of type AnnotationServiceError 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 MarkerOptions describing the desired properties of the Marker.

    Return Value

    An instance of Marker representing the marker that was added.

  • Adds a new Line based on the given LineOptions.

    Throws

    An error of type AnnotationServiceError 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 LineOptions describing the desired properties of the Line.

    Return Value

    An instance of Line representing the line that was added.

  • Adds a new Polygon based on the given PolygonOptions.

    Throws

    An error of type AnnotationServiceError 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 PolygonOptions describing the desired properties of the Polygon.

    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 type AnnotationServiceError 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 PolygonOverlayOptions describing the desired properties of the PolygonOverlay.

    Return Value

    An instance of PolygonOverlay representing 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

    annotation

    An instance of Annotation defining the annotation to be removed.

  • Adds a new Route based on the given RouteOptions.

    Throws

    An error of type RouteError if the route could not be added.

    Declaration

    Swift

    public func addRoute(_ options: RouteOptions) throws -> Route

    Parameters

    options

    An instance of RouteOptions describing the desired properties of the Route.

    Return Value

    An instance of Route representing 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

    tag

    Describes 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

    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.

  • Removes all previously added Routes.

    Declaration

    Swift

    public func removeRoutes()
  • Adds a new Circle based on the given CircleOptions.

    Throws

    An error of type AnnotationServiceError 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 CircleOptions describing the desired properties of the Circle.

    Return Value

    An instance of Circle representing the circle that was added.

  • Remove a route from the map with the given Route.

    Declaration

    Swift

    public func removeRoute(_ route: Route)

    Parameters

    route

    An instance of Route representing the route to remove.

  • Remove all annotations from the map that are tagless (tag is nil).

    Note

    An annotation tag is nil unless 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 is nil 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 is nil 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.

  • 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.

  • 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 CGPoint representing the point on the map.

    Return Value

    An instance of CLLocationCoordinate2D representing the location on the map.

  • 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 CLLocationCoordinate2D representing the location on the map.

    Return Value

    An instance of CGPoint representing the point on the map.

  • Brings the given Route to the uppermost layer.

    Declaration

    Swift

    public func bringToFront(route: Route)

    Parameters

    route

    An instance of Route representing the route to move to the uppermost layer.

  • Zooms to all current Routes with the given padding.

    Declaration

    Swift

    public func zoomToRoutes(padding: UInt)

    Parameters

    padding

    Padding between the coordinates and the camera borders.

  • 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 Annotation defining 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

    annotation

    An instance of Annotation defining 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() -> UIImage

    Return Value

    An instance of UIImage representing the snapshot of the map.

  • Takes a snapshot of the map without the given UIViews 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 UIView to be excluded from the snapshot.

    Return Value

    An instance of UIImage representing the snapshot of the map.

  • Fetches an Array of Layers 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.

  • 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 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 TrafficIncidentObserver to 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()

CameraActions

  • 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 }
  • 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.
    • follow: Camera follows the current position.
    • followRoute: 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 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 CameraUpdate instance to be applied.

    animationDuration

    The TimeInterval durtaion it would take for the animation to be completed.

    completion

    The completion handler that is triggered when the animation is finished.

  • 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 CameraUpdate instance to be applied.

  • Stops the current ongoing CameraUpdate animation.

    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()

RenderedFeatureActions

LocationActions

  • 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 }
  • 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 which 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. To correctly provide the file.glb file to your project path, the model should look like asset://file.glb. Markers size will be changed depending on current zoom level and scale parameter.
    • 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 }
  • 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()
  • Stops the location engine.

    The location engine stops updating the current location. Might be called from a private queue.

    Declaration

    Swift

    public func deactivateLocationProvider()

VehicleActions

  • Show vehicle restrictions layers on the map respective to the given Vehicle.

    Throws

    An error of type VehicleRestrictionsError if the vehicle restrictions could not be shown.

    Declaration

    Swift

    public func showVehicleRestrictions(vehicle: Vehicle) throws

    Parameters

    vehicle

    An instance of Vehicle for which to show vehicle restrictions.

  • 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 type VehicleRestrictionsError if 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()
  • Updates the current Vehicle information.

    Declaration

    Swift

    public func updateVehicle(_ vehicle: Vehicle)

    Parameters

    vehicle

    An instance of Vehicle with which to replace the current vehicle.