Customizing route appearance
It’s possible to change how main and alternate route polylines are displayed on the map by passing RouteDisplayParameters
object to RouteVisualizerRequest.requestDisplayingPolylineOfRoute
and RouteVisualizerRequest.requestDisplayingPolylinesOfAlternativeRoutes
methods.
The following settings can be changed:
Minimum route polyline width;
maximum route polyline width;
route color;
if a halo should be displayed around the route polyline (its color can also be specified);
if direction arrows should be shown on the main route;
if waypoint flags should be shown;
if traffic overlay should be shown on route polylines;
markers used to represent waypoints (start, finish and intermediate stops).
If RouteDisplayParameters
object is null
, the default settings will be used.
Here is an example of route customization:
RouteDisplayParameters routeDisplayParams = new RouteDisplayParametersBuilder()
.setMinRouteWidth(10)
.setMaxRouteWidth(40)
.setRouteColor(new Color("#FF0000"))
.setShowRouteHalo(true)
.setRouteHaloColor(new Color(0, 1, 0))
.build();
RouteDisplayParameters altRouteDisplayParams = new RouteDisplayParametersBuilder()
.setRouteColor(new Color(0.9f, 0.9f, 1.0f))
.setMaxRouteWidth(10)
.build();
RouteVisualizerRequest request = RouteVisualizerRequest.createRequestRemovingAll()
.requestDisplayingPolylineOfRoute(
selectedRoute, routeDisplayParams)
.requestDisplayingPolylinesOfAlternativeRoutes(
alternativeRoutes, altRouteDisplayParams);
Sdk.getInstance().getRouteVisualizer().performRequest(request);
The screenshot below shows the routes displayed with these options:
Using custom route markers
It’s also possible to specify custom drawables to be used as route markers using RouteDisplayParametersBuilder.setStartMarker(RouteMarker)
, RouteDisplayParametersBuilder.setFinishMarker(RouteMarker)
and RouteDisplayParametersBuilder.setIntermediateStopMarker(RouteMarker)
methods for start, finish and intermediate stops respectively.
If null
is passed to any of these methods, the corresponding markers will not be displayed. If these methods are not called, the default markers will be used, as shown in the picture above.
Example:
PointF flagAnchorPoint = new PointF(0.2f, 0.8f);
RouteMarker startMarker = new RouteMarker(
ResourcesCompat.getDrawable(getResources(), R.drawable.ic_start, null),
flagAnchorPoint);
routeDisplayParametersBuilder.setStartMarker(startMarker);
RouteMarker finishMarker = new RouteMarker(
ResourcesCompat.getDrawable(getResources(), R.drawable.ic_finish, null),
flagAnchorPoint);
routeDisplayParametersBuilder.setFinishMarker(finishMarker);
RouteMarker intermediateStopMarker = new RouteMarker(
ResourcesCompat.getDrawable(getResources(), R.drawable.ic_intermediate_stop, null),
flagAnchorPoint);
routeDisplayParametersBuilder.setIntermediateStopMarker(intermediateStopMarker);
RouteVisualizerRequest request = RouteVisualizerRequest.createRequestRemovingAll()
.requestDisplayingPolylineOfRoute(
selectedRoute, routeDisplayParametersBuilder.build());
Sdk.getInstance().getRouteVisualizer().performRequest(request);
ic_start
, ic_finish
and ic_intermediate_stop
icons only exist in the sample application.
This code will result in the following route being displayed: