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;
}
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);
}
}
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()));
}
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);
}
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);
}
Aggregations