use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class RerouteActivity method onResponse.
@Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
Timber.d(call.request().url().toString());
if (response.body() != null) {
if (!response.body().routes().isEmpty()) {
// Extract the route
DirectionsRoute route = response.body().routes().get(0);
// Draw it on the map
drawRoute(route);
// Start mocking the new route
resetLocationEngine(route);
navigation.startNavigation(route);
mapboxMap.setOnMapClickListener(this);
tracking = true;
}
}
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class DynamicCameraTest method buildDirectionsRoute.
private DirectionsRoute buildDirectionsRoute() throws IOException {
Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(DIRECTIONS_PRECISION_6);
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
return response.routes().get(0);
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class NavigationMapRoute method checkNewRouteFound.
private void checkNewRouteFound(int currentRouteIndex) {
if (currentRouteIndex != primaryRouteIndex) {
updateRoute();
boolean isValidPrimaryIndex = primaryRouteIndex >= 0 && primaryRouteIndex < directionsRoutes.size();
if (isValidPrimaryIndex && onRouteSelectionChangeListener != null) {
DirectionsRoute selectedRoute = directionsRoutes.get(primaryRouteIndex);
onRouteSelectionChangeListener.onNewPrimaryRouteSelected(selectedRoute);
}
}
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class NavigationMapRoute method buildTrafficFeaturesFromRoute.
private void buildTrafficFeaturesFromRoute(DirectionsRoute route, int index, List<Feature> features, LineString lineString) {
for (RouteLeg leg : route.legs()) {
if (leg.annotation() != null && leg.annotation().congestion() != null) {
for (int i = 0; i < leg.annotation().congestion().size(); i++) {
// See https://github.com/mapbox/mapbox-navigation-android/issues/353
if (leg.annotation().congestion().size() + 1 <= lineString.getCoordinates().size()) {
double[] startCoord = lineString.getCoordinates().get(i).getCoordinates();
double[] endCoord = lineString.getCoordinates().get(i + 1).getCoordinates();
LineString congestionLineString = LineString.fromCoordinates(new double[][] { startCoord, endCoord });
Feature feature = Feature.fromGeometry(congestionLineString);
feature.addStringProperty(CONGESTION_KEY, leg.annotation().congestion().get(i));
feature.addStringProperty(SOURCE_KEY, String.format(Locale.US, ID_FORMAT, GENERIC_ROUTE_SOURCE_ID, index));
feature.addNumberProperty(INDEX_KEY, index);
features.add(feature);
}
}
} else {
Feature feature = Feature.fromGeometry(lineString);
features.add(feature);
}
}
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class RouteViewModel method obtainRouteLegDescriptionFrom.
private String obtainRouteLegDescriptionFrom(DirectionsRoute route) {
List<RouteLeg> routeLegs = route.legs();
StringBuilder routeLegDescription = new StringBuilder();
for (RouteLeg leg : routeLegs) {
routeLegDescription.append(leg.summary());
}
return routeLegDescription.toString();
}
Aggregations