Search in sources :

Example 1 with Point

use of com.mapbox.geojson.Point in project mapbox-plugins-android by mapbox.

the class GeoJsonPlugin method parseGeoJsonString.

/**
 * @param geoJson String of the GeoJSON file
 * @return DataModel list of polylines, polygons, and point with bounded
 */
private DataModel parseGeoJsonString(String geoJson) {
    int pointCount = 0;
    DataModel dataModel = new DataModel();
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    FeatureCollection featureCollection = FeatureCollection.fromJson(geoJson);
    List<Feature> listFeature = featureCollection.features();
    for (Feature feature : listFeature) {
        String featureType = feature.geometry().type();
        if (!TextUtils.isEmpty(featureType)) {
            if (featureType.equalsIgnoreCase("LineString")) {
                List<LatLng> latLngs = new ArrayList<>();
                LineString lineString = (LineString) feature.geometry();
                List<Point> coordinates = lineString.coordinates();
                for (Point position : coordinates) {
                    LatLng latLng = new LatLng(position.latitude(), position.longitude());
                    latLngs.add(latLng);
                    pointCount++;
                    builder.include(latLng);
                }
                PolyData polylinePolyData = new PolyData();
                polylinePolyData.setPoints(latLngs);
                polylinePolyData.setType(featureType);
                dataModel.addPolyline(polylinePolyData);
            } else if (featureType.equalsIgnoreCase("Point")) {
                Point point = (Point) feature.geometry();
                if (point != null) {
                    LatLng latLng = new LatLng(point.latitude(), point.longitude());
                    MarkerData markerData = new MarkerData();
                    markerData.setPoint(latLng);
                    markerData.setProperties(feature.properties());
                    dataModel.addMarker(markerData);
                    pointCount++;
                    builder.include(latLng);
                }
            } else if (featureType.equalsIgnoreCase("Polygon")) {
                List<LatLng> latLngs = new ArrayList<>();
                Polygon polygon = (Polygon) feature.geometry();
                List<Point> listPosition = polygon.coordinates().get(0);
                for (Point position : listPosition) {
                    LatLng latLng = new LatLng(position.latitude(), position.longitude());
                    latLngs.add(latLng);
                    pointCount++;
                    builder.include(latLng);
                }
                PolyData polygonPolyData = new PolyData();
                polygonPolyData.setPoints(latLngs);
                polygonPolyData.setType(featureType);
                dataModel.addPolygon(polygonPolyData);
            } else {
            // TODO
            }
        }
    }
    if (pointCount > 1) {
        dataModel.setBounds(builder.build());
    }
    return dataModel;
}
Also used : MarkerData(com.mapbox.mapboxsdk.plugins.geojson.model.MarkerData) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) ArrayList(java.util.ArrayList) LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) Feature(com.mapbox.geojson.Feature) Point(com.mapbox.geojson.Point) PolyData(com.mapbox.mapboxsdk.plugins.geojson.model.PolyData) FeatureCollection(com.mapbox.geojson.FeatureCollection) LineString(com.mapbox.geojson.LineString) DataModel(com.mapbox.mapboxsdk.plugins.geojson.model.DataModel) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Polygon(com.mapbox.geojson.Polygon)

Example 2 with Point

use of com.mapbox.geojson.Point in project mapbox-plugins-android by mapbox.

the class PlaceAutocompleteViewModel method buildGeocodingRequest.

public void buildGeocodingRequest(String accessToken) {
    geocoderBuilder = MapboxGeocoding.builder().autocomplete(true);
    geocoderBuilder.accessToken(accessToken);
    geocoderBuilder.limit(placeOptions.limit());
    // Proximity
    Point proximityPoint = placeOptions.proximity();
    if (proximityPoint != null) {
        geocoderBuilder.proximity(proximityPoint);
    }
    // Language
    String languageJson = placeOptions.language();
    if (languageJson != null) {
        geocoderBuilder.languages(languageJson);
    }
    // Type
    String typeJson = placeOptions.geocodingTypes();
    if (typeJson != null) {
        geocoderBuilder.geocodingTypes(typeJson);
    }
    // Countries
    String countriesJson = placeOptions.country();
    if (countriesJson != null) {
        geocoderBuilder.geocodingTypes(countriesJson);
    }
    // Bounding box
    String bbox = placeOptions.bbox();
    if (bbox != null) {
        geocoderBuilder.bbox(bbox);
    }
}
Also used : Point(com.mapbox.geojson.Point)

Example 3 with Point

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

the class NavigationHelperTest method nextManeuverPosition_correctlyReturnsNextManeuverPosition.

@Test
public void nextManeuverPosition_correctlyReturnsNextManeuverPosition() throws Exception {
    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()));
}
Also used : Point(com.mapbox.geojson.Point) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Example 4 with Point

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

the class NavigationHelperTest method setUp.

@Before
public void setUp() throws Exception {
    Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
    String body = loadJsonFixture(MULTI_LEG_ROUTE);
    DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
    route = response.routes().get(0);
    Location location = new Location("test");
    List<Point> coords = PolylineUtils.decode(route.legs().get(0).steps().get(1).geometry(), Constants.PRECISION_6);
    location.setLatitude(coords.get(0).latitude());
    location.setLongitude(coords.get(0).longitude());
    routeProgressBuilder = RouteProgress.builder().directionsRoute(route).distanceRemaining(1000).stepDistanceRemaining(1000).legDistanceRemaining(1000).stepIndex(0).legIndex(0);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Point(com.mapbox.geojson.Point) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse) Location(android.location.Location) Before(org.junit.Before)

Example 5 with Point

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

the class NavigationRouteProcessorTest method withinManeuverRadiusAndBearingMatches_stepIndexIsIncreased.

@Test
public void withinManeuverRadiusAndBearingMatches_stepIndexIsIncreased() throws Exception {
    RouteProgress firstProgress = routeProcessor.buildNewRouteProgress(navigation, mock(Location.class));
    int firstProgressIndex = firstProgress.currentLegProgress().stepIndex();
    List<Point> coordinates = createCoordinatesFromCurrentStep(firstProgress);
    Point lastPointInCurrentStep = coordinates.remove(coordinates.size() - 2);
    Location rawLocation = buildDefaultLocationUpdate(lastPointInCurrentStep.longitude(), lastPointInCurrentStep.latitude());
    when(rawLocation.getBearing()).thenReturn(145f);
    RouteProgress secondProgress = routeProcessor.buildNewRouteProgress(navigation, rawLocation);
    int secondProgressIndex = secondProgress.currentLegProgress().stepIndex();
    assertTrue(firstProgressIndex != secondProgressIndex);
}
Also used : Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Point(com.mapbox.geojson.Point) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Aggregations

Point (com.mapbox.geojson.Point)72 Test (org.junit.Test)31 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)29 Location (android.location.Location)18 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)17 LineString (com.mapbox.geojson.LineString)15 ArrayList (java.util.ArrayList)10 LegStep (com.mapbox.api.directions.v5.models.LegStep)9 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)7 Feature (com.mapbox.geojson.Feature)4 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)4 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)3 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)3 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)3 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 RouteOptions (com.mapbox.api.directions.v5.models.RouteOptions)2 MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)2 BaseTest (com.mapbox.services.android.navigation.ui.v5.BaseTest)2