Search in sources :

Example 16 with LineString

use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.

the class MockLocationEngine method moveToLocation.

public void moveToLocation(Point point) {
    if (location == null) {
        return;
    }
    List<Point> pointList = new ArrayList<>();
    pointList.add(Point.fromLngLat(location.getLongitude(), location.getLatitude()));
    pointList.add(point);
    if (handler != null && runnable != null) {
        handler.removeCallbacks(runnable);
    }
    // Reset all variables
    handler = new Handler();
    points = new ArrayList<>();
    currentLeg = 0;
    currentStep = 0;
    // Calculate the distance which will always be consistent throughout the route.
    distance = calculateDistancePerSec();
    LineString route = LineString.fromLngLats(pointList);
    sliceRoute(route, distance);
    if (noisyGps) {
        addNoiseToRoute(distance);
    }
    runnable = new LocationUpdateRunnable();
    handler.postDelayed(runnable, delay);
}
Also used : LineString(com.mapbox.geojson.LineString) ArrayList(java.util.ArrayList) Handler(android.os.Handler) Point(com.mapbox.geojson.Point)

Example 17 with LineString

use of com.mapbox.geojson.LineString 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 18 with LineString

use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.

the class RouteStepProgressTest method distanceRemaining_equalsCorrectValueAtIntervals.

@Test
public void distanceRemaining_equalsCorrectValueAtIntervals() {
    LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6);
    double stepDistance = TurfMeasurement.length(lineString, TurfConstants.UNIT_METERS);
    // meters
    double stepSegments = 5;
    // Chop the line in small pieces
    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 distance = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
        RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(distance).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
        RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
        assertEquals(distance, routeStepProgress.distanceRemaining(), BaseTest.DELTA);
    }
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 19 with LineString

use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.

the class RouteStepProgressTest method getDurationRemaining_equalsCorrectValueAtIntervals.

@Test
public void getDurationRemaining_equalsCorrectValueAtIntervals() {
    LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6);
    // meters
    double stepSegments = 5;
    // Chop the line in small pieces
    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 distance = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
        RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(distance).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
        RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
        double fractionRemaining = (firstStep.distance() - distance) / firstStep.distance();
        assertEquals((1.0 - fractionRemaining) * firstStep.duration(), routeStepProgress.durationRemaining(), BaseTest.LARGE_DELTA);
    }
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Aggregations

LineString (com.mapbox.geojson.LineString)19 Point (com.mapbox.geojson.Point)15 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)9 Test (org.junit.Test)9 LegStep (com.mapbox.api.directions.v5.models.LegStep)5 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)5 Location (android.location.Location)2 Feature (com.mapbox.geojson.Feature)2 ArrayList (java.util.ArrayList)2 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 FeatureCollection (com.mapbox.geojson.FeatureCollection)1 Polygon (com.mapbox.geojson.Polygon)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1 DataModel (com.mapbox.mapboxsdk.plugins.geojson.model.DataModel)1 MarkerData (com.mapbox.mapboxsdk.plugins.geojson.model.MarkerData)1 PolyData (com.mapbox.mapboxsdk.plugins.geojson.model.PolyData)1 RouteLegProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteLegProgress)1