Java Code Examples for com.mapbox.core.constants.Constants

The following examples show how to use com.mapbox.core.constants.Constants. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: graphhopper-navigation-android   Author: graphhopper   File: TestRouteBuilder.java    License: MIT License 6 votes vote down vote up
private DirectionsRoute buildRouteWithOptions(DirectionsRoute route) throws IOException {
  List<Point> coordinates = new ArrayList<>();
  RouteOptions routeOptionsWithoutVoiceInstructions = RouteOptions.builder()
    .baseUrl(Constants.BASE_API_URL)
    .user("user")
    .profile("profile")
    .accessToken(ACCESS_TOKEN)
    .requestUuid("uuid")
    .geometries("mocked_geometries")
    .voiceInstructions(true)
    .bannerInstructions(true)
    .coordinates(coordinates).build();

  return route.toBuilder()
    .routeOptions(routeOptionsWithoutVoiceInstructions)
    .build();
}
 
Example #2
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RerouteActivity.java    License: MIT License 6 votes vote down vote up
private void drawRoute(DirectionsRoute route) {
  List<LatLng> points = new ArrayList<>();
  List<Point> coords = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6).coordinates();

  for (Point point : coords) {
    points.add(new LatLng(point.latitude(), point.longitude()));
  }

  if (!points.isEmpty()) {

    if (polyline != null) {
      mapboxMap.removePolyline(polyline);
    }

    // Draw polyline on map
    polyline = mapboxMap.addPolyline(new PolylineOptions()
      .addAll(points)
      .color(Color.parseColor("#4264fb"))
      .width(5));
  }
}
 
Example #3
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationLauncherActivity.java    License: MIT License 6 votes vote down vote up
public void boundCameraToRoute() {
  if (route != null) {
    List<Point> routeCoords = LineString.fromPolyline(route.geometry(),
      Constants.PRECISION_6).coordinates();
    List<LatLng> bboxPoints = new ArrayList<>();
    for (Point point : routeCoords) {
      bboxPoints.add(new LatLng(point.latitude(), point.longitude()));
    }
    if (bboxPoints.size() > 1) {
      try {
        LatLngBounds bounds = new LatLngBounds.Builder().includes(bboxPoints).build();
        // left, top, right, bottom
        int topPadding = launchBtnFrame.getHeight() * 2;
        animateCameraBbox(bounds, CAMERA_ANIMATION_DURATION, new int[] {50, topPadding, 50, 100});
      } catch (InvalidLatLngBoundsException exception) {
        Toast.makeText(this, R.string.error_valid_route_not_found, Toast.LENGTH_SHORT).show();
      }
    }
  }
}
 
Example #4
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationHelper.java    License: MIT License 6 votes vote down vote up
/**
 * Calculates the distance remaining in the step from the current users snapped position, to the
 * next maneuver position.
 */
static double stepDistanceRemaining(Point snappedPosition, int legIndex, int stepIndex,
                                    DirectionsRoute directionsRoute, List<Point> coordinates) {
  List<LegStep> steps = directionsRoute.legs().get(legIndex).steps();
  Point nextManeuverPosition = nextManeuverPosition(stepIndex, steps, coordinates);

  LineString lineString = LineString.fromPolyline(steps.get(stepIndex).geometry(),
    Constants.PRECISION_6);
  // If the users snapped position equals the next maneuver
  // position or the linestring coordinate size is less than 2,the distance remaining is zero.
  if (snappedPosition.equals(nextManeuverPosition) || lineString.coordinates().size() < 2) {
    return 0;
  }
  LineString slicedLine = TurfMisc.lineSlice(snappedPosition, nextManeuverPosition, lineString);
  return TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
}
 
Example #5
Source Project: graphhopper-navigation-android   Author: graphhopper   File: ValidationUtilsTest.java    License: MIT License 6 votes vote down vote up
private DirectionsRoute buildRouteWithNullInstructions() throws IOException {
  DirectionsRoute route = buildTestDirectionsRoute();
  List<Point> coordinates = new ArrayList<>();
  RouteOptions routeOptionsWithoutVoiceInstructions = RouteOptions.builder()
    .baseUrl(Constants.BASE_API_URL)
    .user("user")
    .profile("profile")
    .accessToken(ACCESS_TOKEN)
    .requestUuid("uuid")
    .geometries("mocked_geometries")
    .coordinates(coordinates).build();

  return route.toBuilder()
    .routeOptions(routeOptionsWithoutVoiceInstructions)
    .build();
}
 
Example #6
Source Project: graphhopper-navigation-android   Author: graphhopper   File: ValidationUtilsTest.java    License: MIT License 6 votes vote down vote up
private DirectionsRoute buildRouteWithFalseVoiceInstructions() throws IOException {
  DirectionsRoute route = buildTestDirectionsRoute();
  List<Point> coordinates = new ArrayList<>();
  RouteOptions routeOptionsWithoutVoiceInstructions = RouteOptions.builder()
    .baseUrl(Constants.BASE_API_URL)
    .user("user")
    .profile("profile")
    .accessToken(ACCESS_TOKEN)
    .requestUuid("uuid")
    .geometries("mocked_geometries")
    .voiceInstructions(false)
    .coordinates(coordinates).build();

  return route.toBuilder()
    .routeOptions(routeOptionsWithoutVoiceInstructions)
    .build();
}
 
Example #7
Source Project: graphhopper-navigation-android   Author: graphhopper   File: ValidationUtilsTest.java    License: MIT License 6 votes vote down vote up
private DirectionsRoute buildRouteWithFalseBannerInstructions() throws IOException {
  DirectionsRoute route = buildTestDirectionsRoute();
  List<Point> coordinates = new ArrayList<>();
  RouteOptions routeOptionsWithoutVoiceInstructions = RouteOptions.builder()
    .baseUrl(Constants.BASE_API_URL)
    .user("user")
    .profile("profile")
    .accessToken(ACCESS_TOKEN)
    .requestUuid("uuid")
    .geometries("mocked_geometries")
    .voiceInstructions(true)
    .bannerInstructions(false)
    .coordinates(coordinates).build();

  return route.toBuilder()
    .routeOptions(routeOptionsWithoutVoiceInstructions)
    .build();
}
 
Example #8
Source Project: graphhopper-navigation-android   Author: graphhopper   File: TestRouteBuilder.java    License: MIT License 6 votes vote down vote up
private DirectionsRoute buildRouteWithOptions(DirectionsRoute route) throws IOException {
  List<Point> coordinates = new ArrayList<>();
  RouteOptions routeOptionsWithoutVoiceInstructions = RouteOptions.builder()
    .baseUrl(Constants.BASE_API_URL)
    .user("user")
    .profile("profile")
    .accessToken(ACCESS_TOKEN)
    .requestUuid("uuid")
    .geometries("mocked_geometries")
    .voiceInstructions(true)
    .bannerInstructions(true)
    .coordinates(coordinates).build();

  return route.toBuilder()
    .routeOptions(routeOptionsWithoutVoiceInstructions)
    .build();
}
 
Example #9
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteStepProgressTest.java    License: MIT License 6 votes vote down vote up
@Test
public void distanceRemaining_equalsStepDistanceAtBeginning() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteLeg firstLeg = route.legs().get(0);
  LineString lineString = LineString.fromPolyline(firstLeg.steps().get(5).geometry(), Constants.PRECISION_6);
  double stepDistance = TurfMeasurement.length(lineString, TurfConstants.UNIT_METERS);

  double stepDistanceRemaining = firstLeg.steps().get(5).distance();
  double legDistanceRemaining = firstLeg.distance();
  double distanceRemaining = route.distance();
  int stepIndex = 4;
  RouteProgress routeProgress = buildTestRouteProgress(route, stepDistanceRemaining,
    legDistanceRemaining, distanceRemaining, stepIndex, 0);
  RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();

  assertEquals(stepDistance, routeStepProgress.distanceRemaining(), BaseTest.LARGE_DELTA);
}
 
Example #10
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteStepProgressTest.java    License: MIT License 6 votes vote down vote up
@Test
public void stepIntersections_handlesNullNextManeuverCorrectly() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteLeg firstLeg = route.legs().get(0);
  int stepIndex = (route.legs().get(0).steps().size() - 1);
  int legIndex = 0;
  double stepDistanceRemaining = 0;
  double legDistanceRemaining = firstLeg.distance();
  double distanceRemaining = route.distance();
  RouteProgress routeProgress = buildTestRouteProgress(route, stepDistanceRemaining,
    legDistanceRemaining, distanceRemaining, stepIndex, legIndex);
  RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
  int currentStepTotal = route.legs().get(0).steps().get(stepIndex).intersections().size();
  List<Point> lastStepLocation = PolylineUtils.decode(
    route.legs().get(0).steps().get(stepIndex).geometry(), Constants.PRECISION_6);

  assertEquals(currentStepTotal, routeStepProgress.intersections().size());
  assertEquals(routeStepProgress.intersections().get(0).location().latitude(), lastStepLocation.get(0).latitude());
  assertEquals(routeStepProgress.intersections().get(0).location().longitude(), lastStepLocation.get(0).longitude());
}
 
Example #11
Source Project: graphhopper-navigation-example   Author: graphhopper   File: NavigationLauncherActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void boundCameraToRoute() {
    if (route != null) {
        List<Point> routeCoords = LineString.fromPolyline(route.geometry(),
                Constants.PRECISION_6).coordinates();
        List<LatLng> bboxPoints = new ArrayList<>();
        for (Point point : routeCoords) {
            bboxPoints.add(new LatLng(point.latitude(), point.longitude()));
        }
        if (bboxPoints.size() > 1) {
            try {
                LatLngBounds bounds = new LatLngBounds.Builder().includes(bboxPoints).build();
                // left, top, right, bottom
                animateCameraBbox(bounds, CAMERA_ANIMATION_DURATION, padding);
            } catch (InvalidLatLngBoundsException exception) {
                Toast.makeText(this, R.string.error_valid_route_not_found, Toast.LENGTH_SHORT).show();
            }
        }
    }
}
 
Example #12
Source Project: mapbox-java   Author: mapbox   File: MapMatchingRouteOptionsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void mapMatchingRequestResult_doesContainTheOriginalRequestData() throws Exception {
  Response<MapMatchingResponse> response = MapboxMapMatching.builder()
    .coordinates(coordinates)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
    .baseUrl(mockUrl.toString())
    .accessToken(ACCESS_TOKEN)
    .profile(DirectionsCriteria.PROFILE_WALKING)
    .language(Locale.CANADA).build().executeCall();
  MapMatchingMatching matching = response.body().matchings().get(0);

  assertEquals(Locale.CANADA.getLanguage(), matching.routeOptions().language());
  assertEquals(DirectionsCriteria.PROFILE_WALKING, matching.routeOptions().profile());
  assertEquals(Constants.MAPBOX_USER, matching.routeOptions().user());

  // Never set values
  assertNull(matching.routeOptions().annotations());
  assertNull(matching.routeOptions().bearingsList());
}
 
Example #13
Source Project: mapbox-java   Author: mapbox   File: MapboxStaticMap.java    License: MIT License 6 votes vote down vote up
/**
 * Build a new {@link MapboxStaticMap} object with the initial values set for
 * {@link #baseUrl()}, {@link #user()}, {@link #attribution()}, {@link #styleId()},
 * and {@link #retina()}.
 *
 * @return a {@link Builder} object for creating this object
 * @since 3.0.0
 */
public static Builder builder() {
  return new AutoValue_MapboxStaticMap.Builder()
    .styleId(StaticMapCriteria.STREET_STYLE)
    .baseUrl(Constants.BASE_API_URL)
    .user(Constants.MAPBOX_USER)
    .cameraPoint(Point.fromLngLat(0d, 0d))
    .cameraAuto(false)
    .attribution(true)
    .width(250)
    .logo(true)
    .attribution(true)
    .retina(true)
    .height(250)
    .cameraZoom(0)
    .cameraPitch(0)
    .cameraBearing(0)
    .precision(0)
    .retina(false);
}
 
Example #14
Source Project: mapbox-java   Author: mapbox   File: ApiCallHelperTest.java    License: MIT License 6 votes vote down vote up
@Test
public void getHeaderUserAgent_nonAsciiCharsRemoved() {

  String osName = "os.name";
  String osVersion = "os.version";
  String osArch = "os.arch";

  String userAgent = String.format(
    Locale.US, "%s %s/%s (%s)", Constants.HEADER_USER_AGENT, osName, osVersion, osArch);

  String userAgentWithExtraChars = ApiCallHelper.getHeaderUserAgent(null,
    osName + '\u00A9', // copyright
    osVersion + '\u00AE', // Registered Sign
    osArch + '\u2122'); // TM

  Assert.assertEquals(userAgent, userAgentWithExtraChars);
}
 
Example #15
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
/**
 * If the {@link DirectionsRoute} request contains congestion information via annotations, breakup
 * the source into pieces so data-driven styling can be used to change the route colors
 * accordingly.
 */
private FeatureCollection addTrafficToSource(DirectionsRoute route, int index) {
  final List<Feature> features = new ArrayList<>();
  LineString originalGeometry = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
  buildRouteFeatureFromGeometry(index, features, originalGeometry);
  routeLineStrings.put(originalGeometry, route);

  LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
  buildTrafficFeaturesFromRoute(route, index, features, lineString);
  return FeatureCollection.fromFeatures(features);
}
 
Example #16
Source Project: graphhopper-navigation-android   Author: graphhopper   File: DynamicCameraTest.java    License: MIT License 5 votes vote down vote up
private List<Point> generateRouteCoordinates(DirectionsRoute route) {
  if (route == null) {
    return Collections.emptyList();
  }
  LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
  return lineString.coordinates();
}
 
Example #17
Source Project: graphhopper-navigation-android   Author: graphhopper   File: ViewRouteFetcherTest.java    License: MIT License 5 votes vote down vote up
private RouteOptions buildRouteOptionsWithCoordinates(DirectionsResponse response) {
  List<Point> coordinates = new ArrayList<>();
  for (DirectionsWaypoint waypoint : response.waypoints()) {
    coordinates.add(waypoint.location());
  }
  return RouteOptions.builder()
    .baseUrl(Constants.BASE_API_URL)
    .user("user")
    .profile("profile")
    .accessToken(ACCESS_TOKEN)
    .requestUuid("uuid")
    .geometries("mocked_geometries")
    .coordinates(coordinates).build();
}
 
Example #18
Source Project: graphhopper-navigation-android   Author: graphhopper   File: SimpleCamera.java    License: MIT License 5 votes vote down vote up
private List<Point> generateRouteCoordinates(DirectionsRoute route) {
  if (route == null) {
    return Collections.emptyList();
  }
  LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
  return lineString.coordinates();
}
 
Example #19
Source Project: graphhopper-navigation-android   Author: graphhopper   File: SessionState.java    License: MIT License 5 votes vote down vote up
public String originalGeometry() {
  if (originalDirectionRoute() == null || TextUtils.isEmpty(originalDirectionRoute().geometry())) {
    return "";
  }

  List<Point> geometryPositions
    = PolylineUtils.decode(originalDirectionRoute().geometry(), Constants.PRECISION_6);
  return PolylineUtils.encode(geometryPositions, Constants.PRECISION_5);
}
 
Example #20
Source Project: graphhopper-navigation-android   Author: graphhopper   File: SessionState.java    License: MIT License 5 votes vote down vote up
public String currentGeometry() {
  if (currentDirectionRoute() == null || TextUtils.isEmpty(currentDirectionRoute().geometry())) {
    return "";
  }

  List<Point> geometryPositions
    = PolylineUtils.decode(currentDirectionRoute().geometry(), Constants.PRECISION_6);
  return PolylineUtils.encode(geometryPositions, Constants.PRECISION_5);
}
 
Example #21
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationTelemetry.java    License: MIT License 5 votes vote down vote up
private void updateLastRerouteEvent(DirectionsRoute newDirectionsRoute) {
  if (!queuedRerouteEvents.isEmpty()) {
    RerouteEvent rerouteEvent = queuedRerouteEvents.get(queuedRerouteEvents.size() - 1);
    List<Point> geometryPositions = PolylineUtils.decode(newDirectionsRoute.geometry(), Constants.PRECISION_6);
    PolylineUtils.encode(geometryPositions, Constants.PRECISION_5);
    rerouteEvent.setNewRouteGeometry(PolylineUtils.encode(geometryPositions, Constants.PRECISION_5));
    int newDistanceRemaining = newDirectionsRoute.distance() == null ? 0 : newDirectionsRoute.distance().intValue();
    rerouteEvent.setNewDistanceRemaining(newDistanceRemaining);
    int newDurationRemaining = newDirectionsRoute.duration() == null ? 0 : newDirectionsRoute.duration().intValue();
    rerouteEvent.setNewDurationRemaining(newDurationRemaining);
  }
}
 
Example #22
Source Project: graphhopper-navigation-android   Author: graphhopper   File: ReplayRouteLocationConverter.java    License: MIT License 5 votes vote down vote up
private List<Point> calculateStepPoints() {
  List<Point> stepPoints = new ArrayList<>();

  LineString line = LineString.fromPolyline(
    route.legs().get(currentLeg).steps().get(currentStep).geometry(), Constants.PRECISION_6);
  stepPoints.addAll(sliceRoute(line));
  increaseIndex();

  return stepPoints;
}
 
Example #23
Source Project: graphhopper-navigation-android   Author: graphhopper   File: OffRouteDetectorTest.java    License: MIT License 5 votes vote down vote up
@Test
public void isUserOffRoute_AssertFalseTwoUpdatesAwayFromManeuverThenOneTowards() throws Exception {
  RouteProgress routeProgress = buildDefaultTestRouteProgress();
  LegStep currentStep = routeProgress.currentLegProgress().currentStep();

  LineString lineString = LineString.fromPolyline(currentStep.geometry(), Constants.PRECISION_6);
  List<Point> coordinates = lineString.coordinates();

  Location firstLocationUpdate = buildDefaultLocationUpdate(-77.0339782574523, 38.89993519985637);
  offRouteDetector.isUserOffRoute(firstLocationUpdate, routeProgress, options);

  Point lastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
  Location secondLocationUpdate = buildDefaultLocationUpdate(
    lastPointInCurrentStep.longitude(), lastPointInCurrentStep.latitude()
  );
  boolean isUserOffRouteFirstTry = offRouteDetector.isUserOffRoute(secondLocationUpdate, routeProgress, options);
  assertFalse(isUserOffRouteFirstTry);

  Point secondLastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
  Location thirdLocationUpdate = buildDefaultLocationUpdate(
    secondLastPointInCurrentStep.longitude(), secondLastPointInCurrentStep.latitude()
  );
  boolean isUserOffRouteSecondTry = offRouteDetector.isUserOffRoute(thirdLocationUpdate, routeProgress, options);
  assertFalse(isUserOffRouteSecondTry);

  Location fourthLocationUpdate = buildDefaultLocationUpdate(
    lastPointInCurrentStep.longitude(), lastPointInCurrentStep.latitude()
  );
  boolean isUserOffRouteThirdTry = offRouteDetector.isUserOffRoute(fourthLocationUpdate, routeProgress, options);
  assertFalse(isUserOffRouteThirdTry);
}
 
Example #24
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationHelperTest.java    License: MIT License 5 votes vote down vote up
@Test
public void stepDistanceRemaining_returnsZeroWhenPositionsEqualEachOther() throws Exception {
  DirectionsRoute route = buildMultiLegRoute();
  Point snappedPoint = Point.fromLngLat(-77.062996, 38.798405);
  List<Point> coordinates = PolylineUtils.decode(
    route.legs().get(0).steps().get(1).geometry(), Constants.PRECISION_6
  );

  double distance = NavigationHelper.stepDistanceRemaining(snappedPoint, 0, 1, route, coordinates);

  assertEquals(0.0, distance);
}
 
Example #25
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationHelperTest.java    License: MIT License 5 votes vote down vote up
@Test
public void nextManeuverPosition_correctlyReturnsNextManeuverPosition() throws Exception {
  DirectionsRoute route = buildMultiLegRoute();
  List<Point> coordinates = PolylineUtils.decode(
    route.legs().get(0).steps().get(0).geometry(), Constants.PRECISION_6
  );

  Point nextManeuver = NavigationHelper.nextManeuverPosition(0,
    route.legs().get(0).steps(), coordinates);

  assertTrue(nextManeuver.equals(route.legs().get(0).steps().get(1).maneuver().location()));
}
 
Example #26
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationHelperTest.java    License: MIT License 5 votes vote down vote up
@Test
public void nextManeuverPosition_correctlyReturnsNextManeuverPositionInNextLeg() throws Exception {
  DirectionsRoute route = buildMultiLegRoute();
  int stepIndex = route.legs().get(0).steps().size() - 1;
  List<Point> coordinates = PolylineUtils.decode(
    route.legs().get(0).steps().get(stepIndex).geometry(), Constants.PRECISION_6);

  Point nextManeuver = NavigationHelper.nextManeuverPosition(stepIndex,
    route.legs().get(0).steps(), coordinates);

  assertTrue(nextManeuver.equals(route.legs().get(1).steps().get(0).maneuver().location()));
}
 
Example #27
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationHelperTest.java    License: MIT License 5 votes vote down vote up
@Test
public void createIntersectionDistanceList_samePointsForDistanceCalculationsEqualZero() throws Exception {
  RouteProgress routeProgress = buildMultiLegRouteProgress();
  LegStep currentStep = routeProgress.currentLegProgress().currentStep();
  List<Point> currentStepPoints = PolylineUtils.decode(currentStep.geometry(), Constants.PRECISION_6);
  List<StepIntersection> currentStepIntersections = currentStep.intersections();

  List<Pair<StepIntersection, Double>> intersectionDistances = NavigationHelper.createDistancesToIntersections(
    currentStepPoints, currentStepIntersections
  );

  assertTrue(intersectionDistances.get(0).second == 0);
}
 
Example #28
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationHelperTest.java    License: MIT License 5 votes vote down vote up
@Test
public void createIntersectionDistanceList_intersectionListSizeEqualsDistanceListSize() throws Exception {
  RouteProgress routeProgress = buildMultiLegRouteProgress();
  LegStep currentStep = routeProgress.currentLegProgress().currentStep();
  List<Point> currentStepPoints = PolylineUtils.decode(currentStep.geometry(), Constants.PRECISION_6);
  List<StepIntersection> currentStepIntersections = currentStep.intersections();

  List<Pair<StepIntersection, Double>> intersectionDistances = NavigationHelper.createDistancesToIntersections(
    currentStepPoints, currentStepIntersections
  );

  assertTrue(currentStepIntersections.size() == intersectionDistances.size());
}
 
Example #29
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationHelperTest.java    License: MIT License 5 votes vote down vote up
@Test
public void createIntersectionDistanceList_emptyStepIntersectionsReturnsEmptyList() throws Exception {
  RouteProgress routeProgress = buildMultiLegRouteProgress();
  LegStep currentStep = routeProgress.currentLegProgress().currentStep();
  List<Point> currentStepPoints = PolylineUtils.decode(currentStep.geometry(), Constants.PRECISION_6);
  List<StepIntersection> currentStepIntersections = new ArrayList<>();

  List<Pair<StepIntersection, Double>> intersectionDistances = NavigationHelper.createDistancesToIntersections(
    currentStepPoints, currentStepIntersections
  );

  assertTrue(intersectionDistances.isEmpty());
}
 
Example #30
Source Project: graphhopper-navigation-android   Author: graphhopper   File: ToleranceUtilsTest.java    License: MIT License 5 votes vote down vote up
@Test
public void dynamicRerouteDistanceTolerance_userCloseToIntersection() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteProgress routeProgress = buildDefaultTestRouteProgress();
  double distanceToIntersection = route.distance() - 39;
  LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
  Point closePoint = TurfMeasurement.along(lineString, distanceToIntersection, TurfConstants.UNIT_METERS);

  double tolerance = ToleranceUtils.dynamicRerouteDistanceTolerance(closePoint, routeProgress);

  assertEquals(50.0, tolerance, DELTA);
}