use of com.mapbox.services.commons.geojson.LineString in project mapbox-navigation-android by mapbox.
the class NavigationMapRoute method buildTrafficFeaturesFromRoute.
private void buildTrafficFeaturesFromRoute(DirectionsRoute route, int index, List<Feature> features, LineString lineString) {
for (RouteLeg leg : route.legs()) {
if (leg.annotation() != null && leg.annotation().congestion() != null) {
for (int i = 0; i < leg.annotation().congestion().size(); i++) {
// See https://github.com/mapbox/mapbox-navigation-android/issues/353
if (leg.annotation().congestion().size() + 1 <= lineString.getCoordinates().size()) {
double[] startCoord = lineString.getCoordinates().get(i).getCoordinates();
double[] endCoord = lineString.getCoordinates().get(i + 1).getCoordinates();
LineString congestionLineString = LineString.fromCoordinates(new double[][] { startCoord, endCoord });
Feature feature = Feature.fromGeometry(congestionLineString);
feature.addStringProperty(CONGESTION_KEY, leg.annotation().congestion().get(i));
feature.addStringProperty(SOURCE_KEY, String.format(Locale.US, ID_FORMAT, GENERIC_ROUTE_SOURCE_ID, index));
feature.addNumberProperty(INDEX_KEY, index);
features.add(feature);
}
}
} else {
Feature feature = Feature.fromGeometry(lineString);
features.add(feature);
}
}
}
use of com.mapbox.services.commons.geojson.LineString in project mapbox-navigation-android by mapbox.
the class NavigationMapRoute method calculateClickDistancesFromRoutes.
private boolean calculateClickDistancesFromRoutes(HashMap<Double, DirectionsRoute> routeDistancesAwayFromClick, com.mapbox.geojson.Point clickPoint) {
for (LineString lineString : routeLineStrings.keySet()) {
com.mapbox.geojson.Point pointOnLine = findPointOnLine(clickPoint, lineString);
if (pointOnLine == null) {
return true;
}
double distance = TurfMeasurement.distance(clickPoint, pointOnLine, TurfConstants.UNIT_METERS);
routeDistancesAwayFromClick.put(distance, routeLineStrings.get(lineString));
}
return false;
}
use of com.mapbox.services.commons.geojson.LineString in project mapbox-navigation-android by mapbox.
the class NavigationMapRoute method addTrafficToSource.
/**
* 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);
}
Aggregations