NavigationMapView
open class NavigationMapView : UIView
extension NavigationMapView: CLLocationManagerDelegate
extension NavigationMapView: UIGestureRecognizerDelegate
NavigationMapView
is a subclass of UIView
, which draws MapView
on its surface and provides
convenience functions for adding Route
lines to a map.
-
A collection of street road classes for which a congestion level substitution should occur.
For any street road class included in the
roadClassesWithOverriddenCongestionLevels
, all route segments with anCongestionLevel.unknown
traffic congestion level and a matchingMapboxDirections.MapboxStreetsRoadClass
. will be replaced with theCongestionLevel.low
congestion level.Declaration
Swift
public var roadClassesWithOverriddenCongestionLevels: Set<MapboxStreetsRoadClass>?
-
Controls whether to show congestion levels on alternative route lines. Defaults to
false
.If
true
and there’re multiple routes to choose, the alternative route lines would display the congestion levels at different colors, similar to the main route. To customize the congestion colors that represent different congestion levels, override thealternativeTrafficUnknownColor
,alternativeTrafficLowColor
,alternativeTrafficModerateColor
,alternativeTrafficHeavyColor
,alternativeTrafficSevereColor
property for theNavigationMapView.appearance()
.Declaration
Swift
public var showsCongestionForAlternativeRoutes: Bool
-
Controls wheter to show restricted portions of a route line.
Restricted areas are drawn using
routeRestrictedAreaColor
which is customizable.Declaration
Swift
public var showsRestrictedAreasOnRoute: Bool { get set }
-
The tolerance value used for configuring the underlying map source of route line, maneuver arrow and restricted areas.
Controls the level of simplification by specifying the maximum allowed distance between the original line point and the simplified point. A higher tolerance value results in higher simplification and faster performance. Changing the property will affect only newly added sources.
Declaration
Swift
public var overlaySimplificationTolerance: Double
-
Controls whether to show fading gradient color on route lines between two different congestion level segments. Defaults to
false
.If
true
, the congestion level change between two segments in the route line will be shown as fading gradient color instead of abrupt and steep change.Declaration
Swift
public var crossfadesCongestionSegments: Bool { get set }
-
Controls whether the main route style layer and its casing disappears as the user location puck travels over it. Defaults to
false
.Used in standalone
NavigationMapView
during active navigation. If usingNavigationViewController
andCarPlayNavigationViewController
for active navigation, updateNavigationViewController.routeLineTracksTraversal
andCarPlayNavigationViewController.routeLineTracksTraversal
instead.If
true
, the part of the route that has been traversed will be rendered with full transparency, to give the illusion of a disappearing route. To customize the color that appears on the traversed section of a route, override thetraversedRouteColor
property for theNavigationMapView.appearance()
. Iffalse
, the whole route will be shown without traversed part disappearing effect.To update the route line during active navigation when
RouteProgress
changes, add observer forNotification.Name.routeControllerProgressDidChange
and callNavigationMapView.updateRouteLine(routeProgress:coordinate:shouldRedraw:)
withshouldRedraw
asfalse
.To update the route line during active navigation when route refresh or rerouting happens, add observers for
Notification.Name.routeControllerDidRefreshRoute
andNotification.Name.routeControllerDidReroute
. And callNavigationMapView.updateRouteLine(routeProgress:coordinate:shouldRedraw:)
withshouldRedraw
astrue
.Declaration
Swift
public var routeLineTracksTraversal: Bool { get set }
-
Maximum distance (in screen points) the user can tap for a selection to be valid when selecting an alternate route.
Declaration
Swift
public var tapGestureDistanceThreshold: CGFloat
-
Gesture recognizer, that is used to detect taps on waypoints and routes that are currently present on the map. Enabled by default.
Declaration
Swift
public private(set) var mapViewTapGestureRecognizer: UITapGestureRecognizer! { get }
-
Visualizes the given routes and their waypoints and zooms the map to fit, removing any existing routes and waypoints from the map.
Each route is visualized as a line. Each line is color-coded by traffic congestion, if congestion levels are present and
NavigationMapView.crossfadesCongestionSegments
is set totrue
.Waypoints along the route are visualized as markers. Implement
NavigationMapViewDelegate
methods to customize the appearance of the lines and markers representing the routes and waypoints.To only visualize the routes and not the waypoints, or to have more control over the camera, use the
show(_:legIndex:)
method.Declaration
Swift
public func showcase(_ routes: [Route], routesPresentationStyle: RoutesPresentationStyle = .all(), legIndex: Int? = nil, animated: Bool = false, duration: TimeInterval = 1.0, completion: AnimationCompletionHandler? = nil)
Parameters
routes
The routes to visualize in order of priority. The first route is displayed as if it is currently selected or active, while the remaining routes are displayed as if they are currently deselected or inactive. The order of routes in this array may differ from the order in the original
RouteResponse
, for example in response to a user selecting a preferred route.routesPresentationStyle
Route lines presentation style. By default the map will be updated to fit all routes.
legIndex
The zero-based index of the currently active leg along the active route. The active leg is highlighted more prominently than inactive legs.
animated
true
to asynchronously animate the camera, orfalse
to instantaneously zoom and pan the map.duration
Duration of the animation (in seconds). In case if
animated
parameter is set tofalse
this value is ignored.completion
A completion handler that will be called once routes presentation completes.
-
Visualizes the given routes and it’s alternatives, removing any existing from the map.
Each route is visualized as a line. Each line is color-coded by traffic congestion, if congestion levels are present and
NavigationMapView.crossfadesCongestionSegments
is set totrue
.Waypoints along the route are visualized as markers. Implement
NavigationMapViewDelegate
methods to customize the appearance of the lines and markers representing the routes and waypoints.To only visualize the routes and not the waypoints, or to have more control over the camera, use the
show(_:legIndex:)
method.Declaration
Swift
public func showcase(_ routeResponse: IndexedRouteResponse, routesPresentationStyle: RoutesPresentationStyle = .all(), legIndex: Int? = nil, animated: Bool = false, duration: TimeInterval = 1.0, completion: AnimationCompletionHandler? = nil)
Parameters
routeResponse
IndexedRouteResponse
containing routes to visualize. The selected route byrouteIndex
is considered primary, while the remaining routes are displayed as if they are currently deselected or inactive.routesPresentationStyle
Route lines presentation style. By default the map will be updated to fit all routes.
legIndex
The zero-based index of the currently active leg along the active route. The active leg is highlighted more prominently than inactive legs.
animated
true
to asynchronously animate the camera, orfalse
to instantaneously zoom and pan the map.duration
Duration of the animation (in seconds). In case if
animated
parameter is set tofalse
this value is ignored.completion
A completion handler that will be called once routes presentation completes.
-
Visualizes the given routes, removing any existing routes from the map.
Each route is visualized as a line. Each line is color-coded by traffic congestion, if congestion levels are present. Implement
NavigationMapViewDelegate
methods to customize the appearance of the lines representing the routes. To also visualize waypoints and zoom the map to fit, use theshowcase(_:animated:)
method.To undo the effects of this method, use the
removeRoutes()
method.Declaration
Swift
public func show(_ routes: [Route], layerPosition: MapboxMaps.LayerPosition? = nil, legIndex: Int? = nil)
Parameters
routes
The routes to visualize in order of priority. The first route is displayed as if it is currently selected or active, while the remaining routes are displayed as if they are currently deselected or inactive. The order of routes in this array may differ from the order in the original
RouteResponse
, for example in response to a user selecting a preferred route.layerPosition
Position of the first route layer. Remaining routes and their casings are always displayed below the first and all other subsequent route layers. Defaults to
nil
. If layer position is set tonil
, the route layer appears below the bottommost symbol layer.legIndex
The zero-based index of the currently active leg along the active route. The active leg is highlighted more prominently than inactive legs.
-
Visualizes the given routes and it’s alternatives, removing any existing from the map.
Each route is visualized as a line. Each line is color-coded by traffic congestion, if congestion levels are present. Implement
NavigationMapViewDelegate
methods to customize the appearance of the lines representing the routes. To also visualize waypoints and zoom the map to fit, use theshowcase(_:animated:)
method.To undo the effects of this method, use
removeRoutes()
andremoveContinuousAlternativesRoutes()
methods.Declaration
Swift
public func show(_ routeResponse: IndexedRouteResponse, layerPosition: MapboxMaps.LayerPosition? = nil, legIndex: Int? = nil)
Parameters
routeResponse
IndexedRouteResponse
containing routes to visualize. The selected route byrouteIndex
is considered primary, while the remaining routes are displayed as if they are currently deselected or inactive.layerPosition
Position of the first route layer. Remaining routes and their casings are always displayed below the first and all other subsequent route layers. Defaults to
nil
. If layer position is set tonil
, the route layer appears below the bottommost symbol layer.legIndex
The zero-based index of the currently active leg along the primary route. The active leg is highlighted more prominently than inactive legs.
-
Remove any lines visualizing routes from the map.
This method undoes the effects of the
show(_:legIndex:)
method.Declaration
Swift
public func removeRoutes()
-
Removes all alternative routes that are currently shown on a map.
Declaration
Swift
public func removeAlternativeRoutes()
-
Shows the step arrow given the current
RouteProgress
.Declaration
Swift
public func addArrow(route: Route, legIndex: Int, stepIndex: Int)
Parameters
route
Route
object, for which maneuver arrows will be shown.legIndex
Zero-based index of the
RouteLeg
which contains the maneuver.stepIndex
Zero-based index of the
RouteStep
which contains the maneuver. -
Removes the
RouteStep
arrow from theMapView
.Declaration
Swift
public func removeArrow()
-
Color of the buildings, which were found at specific coordinates by calling
NavigationMapView.highlightBuildings(at:in3D:extrudeAll:completion:)
and whenextrudeAll
parameter is set tofalse
.Declaration
Swift
@objc dynamic public var buildingHighlightColor: UIColor
-
Color of all other buildings, which will be highlighted after calling
NavigationMapView.highlightBuildings(at:in3D:extrudeAll:completion:)
and whenextrudeAll
parameter is set totrue
.Declaration
Swift
@objc dynamic public var buildingDefaultColor: UIColor
-
Specifies how the map displays the user’s current location, including the appearance and underlying implementation.
By default, this property is set to
UserLocationStyle.puck2D(configuration:)
, the bearing source is location course.Declaration
Swift
public var userLocationStyle: UserLocationStyle? { get set }
-
Allows to control current user location styling based on accuracy authorization permission on iOS 14 and above. Defaults to
false
.When user disable the
Precise Location
property in the settings of current application: Iffalse
, user location will be drawn based on style, which was set inNavigationMapView.userLocationStyle
. Iftrue
,UserHaloCourseView
will be shown.Declaration
Swift
@objc dynamic public var reducedAccuracyActivatedMode: Bool { get set }
-
Updates
UserLocationStyle
to provided location.Declaration
Swift
public func moveUserLocation(to location: CLLocation, animated: Bool = false)
Parameters
location
Location, where
UserLocationStyle
should be shown.animated
Property, which determines whether
UserLocationStyle
transition to new location will be animated.
-
List of Mapbox Maps font names to be used for any symbol layers added by the Navigation SDK. These are used for features such as Route Duration Annotations that are optionally added during route preview. See https://docs.mapbox.com/ios/maps/api/6.3.0/customizing-fonts.html for more information about server-side fonts.
Declaration
Swift
@objc dynamic public var routeDurationAnnotationFontNames: [String]
-
Shows a callout containing the duration of each route. Useful as a way to give the user more information when picking between multiple route alternatives. If the route contains any tolled segments then the callout will specify that as well.
Declaration
Swift
public func showRouteDurations(along routes: [Route]?)
-
Controls if displayed
continuousAlternative
s will also be annotated with estimated travel time delta relative to the main route.Callouts text font also respects
NavigationMapView.routeDurationAnnotationFontNames
property. Default value istrue
.Declaration
Swift
public var showsRelativeDurationOnContinuousAlternativeRoutes: Bool { get set }
-
Removes all visible route duration callouts.
Declaration
Swift
public func removeRouteDurations()
-
Removes all visible continuous alternative routes duration callouts.
Declaration
Swift
public func removeContinuousAlternativeRoutesDurations()
-
Adds the route waypoints to the map given the current leg index. Previous waypoints for completed legs will be omitted.
Declaration
Swift
public func showWaypoints(on route: Route, legIndex: Int = 0)
Parameters
route
Route
, on which a certainWaypoint
will be shown.legIndex
Index, which determines for which
RouteLeg
Waypoint
will be shown. -
Removes all existing
Waypoint
objects fromMapView
, which were added byNavigationMapView
.Declaration
Swift
public func removeWaypoints()
-
PointAnnotationManager
, which is used to manage addition and removal of final destination annotation.PointAnnotationManager
will become valid only after fully loadingMapView
style.Declaration
Swift
public var pointAnnotationManager: PointAnnotationManager?
-
MapView
, which is added on top ofNavigationMapView
and allows to render navigation related components.Declaration
Swift
public private(set) var mapView: MapView! { get }
-
The object that acts as the navigation delegate of the map view.
Declaration
Swift
public weak var delegate: NavigationMapViewDelegate?
-
Attempts to localize labels into the system’s preferred language.
This method automatically modifies the
SymbolLayer.textField
property of any symbol style layer whose source is the Mapbox Streets source. The user can set the system’s preferred language in Settings, General Settings, Language & Region.This method avoids localizing road labels into the system’s preferred language, in an effort to match road signage and the turn banner, which always display road names and exit destinations in the local language. If this
NavigationMapView
stands alone outside aNavigationViewController
, you should call theMapboxMap.onEvery(_:handler:)
onmapView
, passing inMapEvents.EventKind.styleLoaded
, and call this method inside the closure. The map view embedded inNavigationViewController
is localized automatically, so you do not need to call this method on the value ofNavigationViewController.navigationMapView
.Declaration
Swift
public func localizeLabels()
-
Shows voice instructions for specific
Route
object.Declaration
Swift
public func showVoiceInstructionsOnMap(route: Route)
Parameters
route
Route
object, along which voice instructions will be shown. -
Initializes a newly allocated
NavigationMapView
object with the specified frame rectangle.Declaration
Swift
public override init(frame: CGRect)
Parameters
frame
The frame rectangle for the
NavigationMapView
. -
Initializes a newly allocated
NavigationMapView
object with the specified frame rectangle and type ofNavigationCamera
.Declaration
Swift
public init(frame: CGRect, navigationCameraType: NavigationCameraType = .mobile, tileStoreLocation: TileStoreConfiguration.Location? = NavigationSettings.shared.tileStoreConfiguration.mapLocation )
Parameters
frame
The frame rectangle for the
NavigationMapView
.navigationCameraType
Type of
NavigationCamera
, which is used for the current instance ofNavigationMapView
.tileStoreLocation
Configuration of
TileStore
location, where Map tiles are stored. Usenil
to disable onboard tile storage. -
Returns a
NavigationMapView
object initialized from data in a given unarchiver.Declaration
Swift
public required init?(coder: NSCoder)
Parameters
coder
An unarchiver object.
-
Returns a list of waypoints, that are located on the routes with more than one leg and are close to a certain point and are within threshold distance defined in
NavigationMapView.tapGestureDistanceThreshold
.Declaration
Swift
public func legSeparatingWaypoints(on routes: [Route], closeTo point: CGPoint) -> [Waypoint]?
Parameters
routes
List of the routes.
point
Point on the screen.
Return Value
List of the waypoints, which were found. If no routes have more than one leg,
nil
will be returned. -
Returns a list of the routes, that are close to a certain point and are within threshold distance defined in
NavigationMapView.tapGestureDistanceThreshold
.Declaration
Swift
public func routes(closeTo point: CGPoint) -> [Route]?
Parameters
point
Point on the screen.
Return Value
List of the routes, which were found. If there are no routes on the map view
nil
will be returned.
-
A
TileStore
instance used by map view.Declaration
Swift
open var mapTileStore: TileStore? { get }
-
Setups the Predictive Caching mechanism using provided Options.
This will handle all the required manipulations to enable the feature and maintain it during the navigations. Once enabled, it will be present as long as
NavigationMapView
is retained.Declaration
Swift
public func enablePredictiveCaching(options predictiveCacheOptions: PredictiveCacheOptions)
Parameters
options
options, controlling caching parameters like area radius and concurrent downloading threads.
-
The minimum preferred frames per second at which to render map animations.
This property takes effect when the application has limited resources for animation, such as when the device is running on battery power. By default, this property is set to
PreferredFPS.normal
.Declaration
Swift
public var minimumFramesPerSecond: Int
-
NavigationCamera
, which allows to control camera states.Declaration
Swift
public private(set) var navigationCamera: NavigationCamera! { get }
-
Updates the map view’s preferred frames per second to the appropriate value for the current route progress.
This method accounts for the proximity to a maneuver and the current power source. It has no effect if
NavigationCamera
is inNavigationCameraState.following
state.Declaration
Swift
public func updatePreferredFrameRate(for routeProgress: RouteProgress)
Parameters
routeProgress
Object, which stores current progress along specific route.
-
Shows a callout containing the relative duration to the primary route of each continuous alternative route. Useful as a way to give the user more information when picking between multiple route alternatives. If the route contains any tolled segments then the callout will specify that as well.
Declaration
Swift
public func showContinuousAlternativeRoutesDurations()
-
Receives coordinates for searching the map for buildings. If buildings are found, they will be highlighted in 2D or 3D depending on the
in3D
value.Declaration
Swift
public func highlightBuildings(at coordinates: [CLLocationCoordinate2D], in3D extrudesBuildings: Bool = true, extrudeAll: Bool = false, completion: ((_ foundAllBuildings: Bool) -> Void)? = nil)
Parameters
coordinates
Coordinates which represent building locations.
extrudesBuildings
Switch which allows to highlight buildings in either 2D or 3D. Defaults to
true
.extrudeAll
Switch which allows to extrude either all or only buildings at a specific coordinates. Defaults to
false
.completion
An escaping closure to be executed when the
MapView
feature querying for allcoordinates
ends. A singleBoolean
argument in closure indicates whether or not buildings were found for all coordinates. -
Removes the highlight from all buildings highlighted by
highlightBuildings(at:in3D:completion:)
.Declaration
Swift
public func unhighlightBuildings()
-
Visualizes the given alternative routes, removing any existing from the map.
Each route is visualized as a line. Each route is displayed as a separate line as an inactive route, drawn from it’s deviation point and below the main route line.
To undo the effects of this method, use the
removeContinuousAlternativesRoutes()
method.Declaration
Swift
public func show(continuousAlternatives: [AlternativeRoute])
Parameters
continuousAlternatives
The routes to visualize.
-
Remove any lines visualizing continuous alternatives routes from the map.
This method undoes the effects of the
show(continuousAlternatives:)
method.Declaration
Swift
public func removeContinuousAlternativesRoutes()
-
Returns a list of the
AlternativeRoute
s, that are close to a certain point and are within threshold distance defined inNavigationMapView.tapGestureDistanceThreshold
.Declaration
Swift
public func continuousAlternativeRoutes(closeTo point: CGPoint) -> [AlternativeRoute]?
Parameters
point
Point on the screen.
Return Value
List of the alternative routes, which were found. If there are no continuous alternatives routes on the map view
nil
will be returned.
-
Update the existing primary route line during active navigation.
Declaration
Swift
public func updateRouteLine(routeProgress: RouteProgress, coordinate: CLLocationCoordinate2D?, shouldRedraw: Bool = false)
Parameters
routeProgress
The current
RouteProgress
.coordinate
The current user location coordinate.
redraw
A
Bool
value to decide whether the route is new. When style changes,RouteController
did refresh route or reroute, the value should be set totrue
. WhenRouteController
did update theRouteProgress
, the value should be set tofalse
. -
Find and cache the index of the upcoming [RouteLineDistancesIndex].
Declaration
Swift
public func updateUpcomingRoutePointIndex(routeProgress: RouteProgress)
-
Updates the route style layer and its casing style layer to gradually disappear as the user location puck travels along the displayed route.
Declaration
Swift
public func travelAlongRouteLine(to coordinate: CLLocationCoordinate2D?)
Parameters
coordinate
Current position of the user location.