RoutingVisualization
public protocol RoutingVisualization
The Entry point for all methods related to the routing visualization.
Instances of RoutingVisualization
are created using RoutingVisualizationFactory.create(map:styleConfiguration:)
.
You should call methods on these instances from the main thread only, otherwise an exception can occur.
A RoutingVisualization
instance is used by first providing a RoutePlan
with displayRoutePlan(_:)
.
After that, the TomTomSDKRoute.Route
s contained in the RoutePlan
are displayed on the map, and you can use setActiveRoute(_:)
to select a route to be navigated on.
You can access the list of route primitives displayed on the map using routes
.
The active route and the alternative routes are styled with the properties contained in the StyleConfiguration
provided to RoutingVisualizationFactory.create(map:styleConfiguration:)
.
You can then call clearRoutePlan()
to remove all the primitives that have been added to the map by the module.
Visualization of on-route traffic incidents can be enabled or disabled using areTrafficIncidentsEnabled
.
If a TomTomSDKRoute.Route
contained in the RoutePlan
has traffic data available and areTrafficIncidentsEnabled
is true, traffic incidents are displayed on the map on top of that TomTomSDKRoute.Route
.
You can access the list of traffic incidents that are on a route using trafficIncidents(on:)
.
-
The list of
TomTomSDKMapDisplay.Route
s that is being displayed on the map. During display of aRoutePlan
, this list contains the active route and the alternative This list will be empty after callingclear
.Declaration
Swift
var routes: [TomTomSDKMapDisplay.Route] { get }
-
The active
TomTomSDKMapDisplay.Route
. This is nil before aRoutePlan
has been displayed withdisplayRoutePlan(_:)
, or after callingclearRoutePlan()
.setActiveRoute(_:)
For setting a different route to be navigated.Declaration
Swift
var activeRoute: TomTomSDKMapDisplay.Route? { get }
-
Configures whether automatic zoom is enabled. The default is true.
Declaration
Swift
var isZoomToRoutePlanEnabled: Bool { get set }
-
Enables or disables visualization of on-route traffic incidents. This function can be called at any moment of the
RoutingVisualization
lifecycle. For example, if it is called when no traffic incidents are available (e.g., before displaying a route plan), the new visibility status (either enabled or disabled) is saved and applied later when traffic incidents are available. If it is called when traffic incidents are available (e.g., during the route planning phase), the new status takes effect immediately on the traffic incidents.Declaration
Swift
var areTrafficIncidentsEnabled: Bool { get set }
-
Displays a
RoutePlan
on the map. Adds aTomTomSDKRoute.Route
instance to the map for eachTomTomSDKRoute.Route
contained in the route plan. By default, the first route of the plan is active, but you can set a different route usingsetActiveRoute(_:)
. Consecutive calls of this method replace the previousRoutePlan
being displayed. If the providedRoutePlan
contains an empty list of routes, then this method does nothing.Declaration
Swift
func displayRoutePlan(_ routePlan: RoutePlan)
Parameters
routePlan
The
RoutePlan
to be displayed on the map. -
Gets the list of
TrafficIncident
s that are being displayed on a certainTomTomSDKRoute.Route
.Declaration
Swift
func trafficIncidents(on route: TomTomSDKMapDisplay.Route) -> [TrafficIncident]
Parameters
route
The
TomTomSDKMapDisplay.Route
to get traffic incidents from.Return Value
The list of
TrafficIncident
s on the route, ornil
if the route is not inroutes
. -
Set as active a
TomTomSDKMapDisplay.Route
from the routes displayed on the map. If the providedTomTomSDKMapDisplay.Route
is not a route from theRoutePlan
displayed withdisplayRoutePlan(_:)
, then this method does nothing.Declaration
Swift
func setActiveRoute(_ route: TomTomSDKMapDisplay.Route)
Parameters
route
The
TomTomSDKMapDisplay.Route
to be active. -
Removes all routes and markers added with
displayRoutePlan(_:)
from the map and setsactiveRoute
to nil.Warning
Do not remove manually the routes or markers which were added duringdisplayRoutePlan(_:)
usingTomTomSDKMapDisplay.TomTomMap
methods.Declaration
Swift
func clearRoutePlan()
-
Removes all alternative routes and corresponding traffic incidents added with
displayRoutePlan(_:)
from the map and keeps theactiveRoute
.Declaration
Swift
func clearAlternativeRoutes()