com.mapbox.core.constants.Constants Java Examples
The following examples show how to use
com.mapbox.core.constants.Constants.
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 File: ApiCallHelperTest.java From mapbox-java with MIT License | 6 votes |
@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 #2
Source File: TestRouteBuilder.java From graphhopper-navigation-android with MIT License | 6 votes |
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 #3
Source File: ValidationUtilsTest.java From graphhopper-navigation-android with MIT License | 6 votes |
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 #4
Source File: ValidationUtilsTest.java From graphhopper-navigation-android with MIT License | 6 votes |
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 #5
Source File: ValidationUtilsTest.java From graphhopper-navigation-android with MIT License | 6 votes |
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 File: RouteStepProgressTest.java From graphhopper-navigation-android with MIT License | 6 votes |
@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 #7
Source File: RouteStepProgressTest.java From graphhopper-navigation-android with MIT License | 6 votes |
@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 #8
Source File: NavigationLauncherActivity.java From graphhopper-navigation-example with Apache License 2.0 | 6 votes |
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 #9
Source File: MapMatchingRouteOptionsTest.java From mapbox-java with MIT License | 6 votes |
@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 #10
Source File: NavigationHelper.java From graphhopper-navigation-android with MIT License | 6 votes |
/** * 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 #11
Source File: MapboxStaticMap.java From mapbox-java with MIT License | 6 votes |
/** * 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 #12
Source File: NavigationLauncherActivity.java From graphhopper-navigation-android with MIT License | 6 votes |
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 #13
Source File: RerouteActivity.java From graphhopper-navigation-android with MIT License | 6 votes |
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 #14
Source File: TestRouteBuilder.java From graphhopper-navigation-android with MIT License | 6 votes |
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 #15
Source File: MapboxDirectionsRefresh.java From mapbox-java with MIT License | 5 votes |
/** * Build a new {@link MapboxDirectionsRefresh} builder with default initial values. * * @return a {@link Builder} for creating a default {@link MapboxDirectionsRefresh} * @since 4.4.0 */ public static Builder builder() { return new AutoValue_MapboxDirectionsRefresh.Builder() .baseUrl(Constants.BASE_API_URL) .routeIndex(ZERO) .legIndex(ZERO); }
Example #16
Source File: MapboxMapMatching.java From mapbox-java with MIT License | 5 votes |
/** * Build a new {@link MapboxMapMatching} object with the initial values set for * {@link #baseUrl()}, {@link #profile()}, {@link #geometries()}, and {@link #user()}. * * @return a {@link Builder} object for creating this object * @since 3.0.0 */ public static Builder builder() { return new AutoValue_MapboxMapMatching.Builder() .baseUrl(Constants.BASE_API_URL) .profile(DirectionsCriteria.PROFILE_DRIVING) .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6) .user(DirectionsCriteria.PROFILE_DEFAULT_USER); }
Example #17
Source File: MapboxOptimization.java From mapbox-java with MIT License | 5 votes |
/** * Build a new {@link MapboxOptimization} object with the initial values set for * {@link #baseUrl()}, {@link #profile()}, {@link #user()}, and {@link #geometries()}. * * @return a {@link Builder} object for creating this object * @since 3.0.0 */ public static Builder builder() { return new AutoValue_MapboxOptimization.Builder() .baseUrl(Constants.BASE_API_URL) .profile(DirectionsCriteria.PROFILE_DRIVING) .user(DirectionsCriteria.PROFILE_DEFAULT_USER) .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6); }
Example #18
Source File: MapboxDirections.java From mapbox-java with MIT License | 5 votes |
/** * Build a new {@link MapboxDirections} object with the initial values set for * {@link #baseUrl()}, {@link #profile()}, {@link #user()}, and {@link #geometries()}. * * @return a {@link Builder} object for creating this object * @since 3.0.0 */ public static Builder builder() { return new AutoValue_MapboxDirections.Builder() .baseUrl(Constants.BASE_API_URL) .profile(DirectionsCriteria.PROFILE_DRIVING) .user(DirectionsCriteria.PROFILE_DEFAULT_USER) .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6); }
Example #19
Source File: ApiCallHelper.java From mapbox-java with MIT License | 5 votes |
/** * Computes a full user agent header of the form: * {@code MapboxJava/1.2.0 Mac OS X/10.11.5 (x86_64)}. * * @param clientAppName Application Name * @return {@link String} representing the header user agent * @since 1.0.0 */ public static String getHeaderUserAgent(@Nullable String clientAppName) { String osName = System.getProperty("os.name"); String osVersion = System.getProperty("os.version"); String osArch = System.getProperty("os.arch"); if (TextUtils.isEmpty(osName) || TextUtils.isEmpty(osVersion) || TextUtils.isEmpty(osArch)) { return Constants.HEADER_USER_AGENT; } else { return getHeaderUserAgent(clientAppName, osName, osVersion, osArch); } }
Example #20
Source File: ApiCallHelper.java From mapbox-java with MIT License | 5 votes |
/** * Computes a full user agent header of the form: * {@code MapboxJava/1.2.0 Mac OS X/10.11.5 (x86_64)}. * * @param clientAppName Application Name * @param osName OS name * @param osVersion OS version * @param osArch OS Achitecture * @return {@link String} representing the header user agent * @since 1.0.0 */ public static String getHeaderUserAgent(@Nullable String clientAppName, @NonNull String osName, @NonNull String osVersion, @NonNull String osArch) { osName = osName.replaceAll(ONLY_PRINTABLE_CHARS, ""); osVersion = osVersion.replaceAll(ONLY_PRINTABLE_CHARS, ""); osArch = osArch.replaceAll(ONLY_PRINTABLE_CHARS, ""); String baseUa = String.format( Locale.US, "%s %s/%s (%s)", Constants.HEADER_USER_AGENT, osName, osVersion, osArch); return TextUtils.isEmpty(clientAppName) ? baseUa : String.format(Locale.US, "%s %s", clientAppName, baseUa); }
Example #21
Source File: RouteStepProgressTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void fractionTraveled_equalsCorrectValueAtIntervals() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); RouteLeg firstLeg = route.legs().get(0); LegStep firstStep = route.legs().get(0).steps().get(0); LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6); List<Float> fractionsRemaining = new ArrayList<>(); List<Float> routeProgressFractionsTraveled = new ArrayList<>(); double stepSegments = 5; for (double i = 0; i < firstStep.distance(); i += stepSegments) { Point point = TurfMeasurement.along(lineString, i, TurfConstants.UNIT_METERS); LineString slicedLine = TurfMisc.lineSlice(point, route.legs().get(0).steps().get(1).maneuver().location(), lineString); double stepDistanceRemaining = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS); int stepIndex = 0; int legIndex = 0; double legDistanceRemaining = firstLeg.distance(); double distanceRemaining = route.distance(); RouteProgress routeProgress = buildTestRouteProgress(route, stepDistanceRemaining, legDistanceRemaining, distanceRemaining, stepIndex, legIndex); RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress(); float fractionRemaining = (float) ((firstStep.distance() - stepDistanceRemaining) / firstStep.distance()); if (fractionRemaining < 0) { fractionRemaining = 0; } fractionsRemaining.add(fractionRemaining); routeProgressFractionsTraveled.add(routeStepProgress.fractionTraveled()); } assertTrue(fractionsRemaining.equals(routeProgressFractionsTraveled)); }
Example #22
Source File: RouteStepProgressTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void distanceRemaining_equalsCorrectValueAtIntervals() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); RouteLeg firstLeg = route.legs().get(0); LegStep firstStep = route.legs().get(0).steps().get(0); LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6); double stepDistance = TurfMeasurement.length(lineString, TurfConstants.UNIT_METERS); double stepSegments = 5; for (double i = 0; i < stepDistance; i += stepSegments) { Point point = TurfMeasurement.along(lineString, i, TurfConstants.UNIT_METERS); if (point.equals(route.legs().get(0).steps().get(1).maneuver().location())) { return; } LineString slicedLine = TurfMisc.lineSlice(point, route.legs().get(0).steps().get(1).maneuver().location(), lineString); double stepDistanceRemaining = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS); double legDistanceRemaining = firstLeg.distance(); double distanceRemaining = route.distance(); RouteProgress routeProgress = buildTestRouteProgress(route, stepDistanceRemaining, legDistanceRemaining, distanceRemaining, 0, 0); RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress(); assertEquals(stepDistanceRemaining, routeStepProgress.distanceRemaining(), BaseTest.DELTA); } }
Example #23
Source File: ApiCallHelperTest.java From mapbox-java with MIT License | 5 votes |
@Test public void getHeaderUserAgent_formatsStringCorrectly() throws Exception { assertTrue(ApiCallHelper.getHeaderUserAgent( null).startsWith(Constants.HEADER_USER_AGENT)); assertTrue(ApiCallHelper.getHeaderUserAgent( "AppName").startsWith("AppName")); }
Example #24
Source File: ToleranceUtilsTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void dynamicRerouteDistanceTolerance_userJustPastTheIntersection() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); RouteProgress routeProgress = buildDefaultTestRouteProgress(); double distanceToIntersection = route.distance(); 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); }
Example #25
Source File: ToleranceUtilsTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@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); }
Example #26
Source File: DynamicCameraTest.java From graphhopper-navigation-android with MIT License | 5 votes |
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 #27
Source File: ViewRouteFetcherTest.java From graphhopper-navigation-android with MIT License | 5 votes |
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 #28
Source File: SimpleCamera.java From graphhopper-navigation-android with MIT License | 5 votes |
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 #29
Source File: SessionState.java From graphhopper-navigation-android with MIT License | 5 votes |
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 #30
Source File: SessionState.java From graphhopper-navigation-android with MIT License | 5 votes |
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); }