Search in sources :

Example 16 with LegStep

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

the class OffRouteDetectorTest method setupStepPoints.

private void setupStepPoints(OffRouteDetector offRouteDetector) throws Exception {
    RouteProgress routeProgress = buildDefaultRouteProgress();
    LegStep currentStep = routeProgress.currentLegProgress().currentStep();
    LineString lineString = LineString.fromPolyline(currentStep.geometry(), Constants.PRECISION_6);
    List<Point> stepPoints = lineString.coordinates();
    offRouteDetector.updateStepPoints(stepPoints);
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 17 with LegStep

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

the class DynamicCamera method createCameraPosition.

/**
 * Creates a camera position with the current location and upcoming maneuver location.
 * <p>
 * Using {@link MapboxMap#getCameraForLatLngBounds(LatLngBounds, int[])} with a {@link LatLngBounds}
 * that includes the current location and upcoming maneuver location.
 *
 * @param location      for current location
 * @param routeProgress for upcoming maneuver location
 * @return camera position that encompasses both locations
 */
private CameraPosition createCameraPosition(Location location, RouteProgress routeProgress) {
    LegStep upComingStep = routeProgress.currentLegProgress().upComingStep();
    if (upComingStep != null) {
        Point stepManeuverPoint = upComingStep.maneuver().location();
        List<LatLng> latLngs = new ArrayList<>();
        LatLng currentLatLng = new LatLng(location);
        LatLng maneuverLatLng = new LatLng(stepManeuverPoint.latitude(), stepManeuverPoint.longitude());
        latLngs.add(currentLatLng);
        latLngs.add(maneuverLatLng);
        if (latLngs.size() < 1 || currentLatLng.equals(maneuverLatLng)) {
            return mapboxMap.getCameraPosition();
        }
        LatLngBounds cameraBounds = new LatLngBounds.Builder().includes(latLngs).build();
        int[] padding = { 0, 0, 0, 0 };
        CameraPosition positionForLatLngBounds = mapboxMap.getCameraForLatLngBounds(cameraBounds, padding);
        if (positionForLatLngBounds != null) {
            return positionForLatLngBounds;
        }
    }
    return mapboxMap.getCameraPosition();
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) ArrayList(java.util.ArrayList) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Point(com.mapbox.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 18 with LegStep

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

the class InstructionStepResources method intersectionTurnLanes.

private void intersectionTurnLanes(LegStep step) {
    StepIntersection intersection = step.intersections().get(0);
    List<IntersectionLanes> lanes = intersection.lanes();
    if (checkForNoneIndications(lanes)) {
        turnLanes = null;
        return;
    }
    turnLanes = lanes;
}
Also used : StepIntersection(com.mapbox.api.directions.v5.models.StepIntersection) IntersectionLanes(com.mapbox.api.directions.v5.models.IntersectionLanes)

Example 19 with LegStep

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

the class InstructionStepResources method extractStepResources.

private void extractStepResources(RouteProgress progress) {
    LegStep currentStep = progress.currentLegProgress().currentStep();
    LegStep upcomingStep = progress.currentLegProgress().upComingStep();
    LegStep followOnStep = progress.currentLegProgress().followOnStep();
    // Type / Modifier / Text
    if (upcomingStep != null) {
        maneuverViewType = upcomingStep.maneuver().type();
        maneuverViewModifier = upcomingStep.maneuver().modifier();
        // Then step (step after upcoming)
        if (followOnStep != null) {
            thenStep(upcomingStep, followOnStep, progress.currentLegProgress().currentStepProgress().durationRemaining());
        }
        // Turn lane data
        if (hasIntersections(upcomingStep)) {
            intersectionTurnLanes(upcomingStep);
        }
    } else {
        maneuverViewType = currentStep.maneuver().type();
        maneuverViewModifier = currentStep.maneuver().modifier();
    }
}
Also used : LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 20 with LegStep

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

the class InstructionListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(InstructionViewHolder holder, int position) {
    if (stepList.get(position) != null) {
        LegStep step = stepList.get(position);
        if (hasBannerInstructions(step)) {
            updatePrimaryText(holder, step.bannerInstructions().get(0).primary());
            updateSecondaryText(holder, step.bannerInstructions().get(0).secondary());
        } else {
            holder.stepPrimaryText.setText(step.maneuver().instruction());
            updateSecondaryText(holder, null);
        }
        updateManeuverView(holder, step);
        SpannableString distanceText = distanceUtils.formatDistance(step.distance());
        holder.stepDistanceText.setText(distanceText);
    }
}
Also used : SpannableString(android.text.SpannableString) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Aggregations

LegStep (com.mapbox.api.directions.v5.models.LegStep)18 Point (com.mapbox.geojson.Point)9 LineString (com.mapbox.geojson.LineString)5 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)3 Location (android.location.Location)2 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)2 NonNull (android.support.annotation.NonNull)1 SpannableString (android.text.SpannableString)1 BannerInstructions (com.mapbox.api.directions.v5.models.BannerInstructions)1 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)1 IntersectionLanes (com.mapbox.api.directions.v5.models.IntersectionLanes)1 StepIntersection (com.mapbox.api.directions.v5.models.StepIntersection)1 StepManeuver (com.mapbox.api.directions.v5.models.StepManeuver)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1