Mapbox Route Arrow Api
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)
}