Search in sources :

Example 1 with RouteLeg

use of com.mapbox.api.directions.v5.models.RouteLeg in project mapbox-navigation-android by mapbox.

the class NavigationEventDispatcherTest method setNavigationMetricListener_didNotGetTriggeredUntilArrival.

@Test
public void setNavigationMetricListener_didNotGetTriggeredUntilArrival() throws Exception {
    RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
    int lastStepIndex = lastLeg.steps().indexOf(lastLeg.steps().get(lastLeg.steps().size() - 1));
    navigationEventDispatcher.addMetricEventListeners(eventListeners);
    navigationEventDispatcher.addMetricArrivalListener(arrivalListener);
    // Progress that hasn't arrived
    RouteProgress routeProgressDidNotArrive = RouteProgress.builder().stepDistanceRemaining(100).legDistanceRemaining(100).distanceRemaining(100).directionsRoute(route).stepIndex(lastStepIndex).legIndex(0).build();
    navigationEventDispatcher.onProgressChange(location, routeProgressDidNotArrive);
    verify(eventListeners, times(1)).onRouteProgressUpdate(routeProgressDidNotArrive);
    verify(arrivalListener, times(0)).onArrival(location, routeProgressDidNotArrive);
    // Progress that has arrived
    RouteProgress routeProgressDidArrive = RouteProgress.builder().stepDistanceRemaining(30).legDistanceRemaining(30).distanceRemaining(30).directionsRoute(route).stepIndex(lastStepIndex).legIndex(0).build();
    navigationEventDispatcher.onProgressChange(location, routeProgressDidArrive);
    verify(eventListeners, times(1)).onRouteProgressUpdate(routeProgressDidArrive);
    verify(arrivalListener, times(1)).onArrival(location, routeProgressDidArrive);
}
Also used : RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Example 2 with RouteLeg

use of com.mapbox.api.directions.v5.models.RouteLeg in project mapbox-navigation-android by mapbox.

the class RouteProgressTest method setup.

@Before
public void setup() throws IOException {
    Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
    String body = loadJsonFixture(DIRECTIONS_PRECISION_6);
    DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
    route = response.routes().get(0);
    RouteLeg firstLeg = route.legs().get(0);
    // Multiple leg route
    body = loadJsonFixture(MULTI_LEG_ROUTE);
    response = gson.fromJson(body, DirectionsResponse.class);
    multiLegRoute = response.routes().get(0);
    beginningRouteProgress = RouteProgress.builder().stepDistanceRemaining(route.legs().get(0).steps().get(0).distance()).legDistanceRemaining(route.legs().get(0).distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
    lastRouteProgress = RouteProgress.builder().stepDistanceRemaining(route.legs().get(0).steps().get(firstLeg.steps().size() - 1).distance()).legDistanceRemaining(route.legs().get(0).distance()).distanceRemaining(0).directionsRoute(route).stepIndex(firstLeg.steps().size() - 1).legIndex(route.legs().size() - 1).build();
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse) Before(org.junit.Before)

Example 3 with RouteLeg

use of com.mapbox.api.directions.v5.models.RouteLeg 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);
        }
    }
}
Also used : LineString(com.mapbox.services.commons.geojson.LineString) RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg) Feature(com.mapbox.services.commons.geojson.Feature) Point(com.mapbox.services.commons.geojson.Point)

Example 4 with RouteLeg

use of com.mapbox.api.directions.v5.models.RouteLeg 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();
}
Also used : RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg)

Example 5 with RouteLeg

use of com.mapbox.api.directions.v5.models.RouteLeg in project mapbox-navigation-android by mapbox.

the class RouteUtilsTest method obtainLastStepIndex.

private int obtainLastStepIndex(DirectionsRoute route) throws IOException {
    RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
    int lastStepIndex = lastLeg.steps().indexOf(lastLeg.steps().get(lastLeg.steps().size() - 1));
    return lastStepIndex;
}
Also used : RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg)

Aggregations

RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)10 LegStep (com.mapbox.api.directions.v5.models.LegStep)3 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)2 Feature (com.mapbox.services.commons.geojson.Feature)2 Test (org.junit.Test)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)1 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)1 StepManeuver (com.mapbox.api.directions.v5.models.StepManeuver)1 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)1 LineString (com.mapbox.services.commons.geojson.LineString)1 Point (com.mapbox.services.commons.geojson.Point)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1