MapboxRouteArrowApi

Responsible for displaying a maneuver arrow representing the next maneuver. The maneuver arrow is calculated based on the route progress and the data returned should be rendered on the map using the MapboxRouteArrowView class. Generally this class should be called on each route progress update in order to ensure the arrow displayed is kept consistent with the state of navigation.

The two principal classes for the maneuver arrow are the MapboxRouteArrowApi and the MapboxRouteArrowView.

Like the route line components the MapboxRouteArrowApi consumes data from the Navigation SDK, specifically the RouteProgress, and produces data for rendering on the map by the MapboxRouteArrowView. Simple usage of the maneuver arrows would look like:

RouteArrowOptions routeArrowOptions = new RouteArrowOptions.Builder(context)
.withAboveLayerId(RouteLayerConstants.TOP_LEVEL_ROUTE_LINE_LAYER_ID)
.build()
MapboxRouteArrowApi routeArrow = new MapboxRouteArrowApi()
MapboxRouteArrowView routeArrowView = new MapboxRouteArrowView(routeArrowOptions)

or

val routeArrowOptions = RouteArrowOptions.Builder(context)
.withAboveLayerId(RouteLayerConstants.TOP_LEVEL_ROUTE_LINE_LAYER_ID)
.build()
val routeArrow = MapboxRouteArrowApi()
val routeArrowView = MapboxRouteArrowView(routeArrowOptions)

NOTE: the above example is setting the layer above which the arrow(s) should be located. This constant is a good starting point but you may have a use case that requires setting the layer elevation for the arrows differently. In addition, if using this constant it is important that the route line related layers be initialized before any rendering of the arrows is done. The route line related layers can be created either by calling MapboxRouteLineView.initializeLayers or by calling one of the render methods on MapboxRouteLineView. In most cases it is not necessary to explicitly call MapboxRouteLineView.initializeLayers as calling any of the render methods of MapboxRouteLineView will initialize the layers and typically a route line will be drawn before a maneuver arrow.

In order for the MapboxRouteArrowApi to function it needs route progress updates. An application should register a RouteProgressObserver with the MapboxNavigation class instance and pass the route progress updates to the MapboxRouteArrowApi class. Be sure to unregister this listener appropriately according to the lifecycle of your activity or Fragment in order to prevent resource leaks.

At a minimum an application should do the following with route progress updates:

override fun onRouteProgressChanged(routeProgress: RouteProgress) {
val updateState = routeArrow.updateUpcomingManeuverArrow(routeProgress)
routeArrowView.render(mapboxMap.getStyle(), updateState)
}

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard

Adds an arrow to the map. An arrow is made up of at least two points. The direction of the arrow head is determined by calculating the bearing between the last two points submitted. Each call will add a new arrow.

Link copied to clipboard

Calculates a maneuver arrow based on the route progress and returns a state that can be used to render the arrow on the map.

Link copied to clipboard

Clears all arrows from the map.

Link copied to clipboard
Link copied to clipboard

Returns a state containing visibility modifications for hiding the maneuver arrow.

Link copied to clipboard

Returns the data necessary to re-render or redraw the arrow(s).

Link copied to clipboard

Will remove the arrow and return updated data for rendering the arrows.

Link copied to clipboard

Returns a state containing visibility modifications for showing the maneuver arrow.