use of com.mapbox.services.commons.geojson.Point in project mapbox-navigation-android by mapbox.
the class NavigationMapRoute method onMapClick.
@Override
public void onMapClick(@NonNull LatLng point) {
if (invalidMapClick()) {
return;
}
final int currentRouteIndex = primaryRouteIndex;
if (findClickedRoute(point)) {
return;
}
checkNewRouteFound(currentRouteIndex);
}
use of com.mapbox.services.commons.geojson.Point in project mapbox-navigation-android by mapbox.
the class NavigationMapRoute method updateRoute.
private void updateRoute() {
// alternative or primary.
for (FeatureCollection featureCollection : featureCollections) {
if (!(featureCollection.getFeatures().get(0).getGeometry() instanceof Point)) {
int index = featureCollection.getFeatures().get(0).getNumberProperty(INDEX_KEY).intValue();
updatePrimaryShieldRoute(String.format(Locale.US, ID_FORMAT, GENERIC_ROUTE_SHIELD_LAYER_ID, index), index);
updatePrimaryRoute(String.format(Locale.US, ID_FORMAT, GENERIC_ROUTE_LAYER_ID, index), index);
}
}
}
use of com.mapbox.services.commons.geojson.Point in project androidApp by InspectorIncognito.
the class UserPlugin method setLocation.
/**
* Updates the user location icon.
*
* @param location the latest user location
* @since 0.1.0
*/
protected boolean setLocation(final Location location) {
GeoJsonSource locationGeoJsonSource = mapboxMap.getSourceAs(LocationLayerConstants.LOCATION_SOURCE);
if (locationGeoJsonSource == null) {
Log.e("UserPlugin", "Location GeoJSON source missing from map style, this should never occur.");
return true;
}
// Convert the new location to a Point object.
Point newPoint = Point.fromCoordinates(new double[] { location.getLongitude(), location.getLatitude() });
// If the source doesn't have geometry, a Point gets added.
if (previousPoint == null) {
userLocationFeature = Feature.fromGeometry(newPoint, new JsonObject(), LocationLayerConstants.USER_LOCATION_ICON);
userLocationFeature.addBooleanProperty(LocationLayerConstants.PROPERTY_ON_BUS, false);
userLocationFeature.addStringProperty(LocationLayerConstants.PROPERTY_ORIENTATION, "NONE");
locationGeoJsonSource.setGeoJson(userLocationFeature);
previousPoint = newPoint;
return true;
}
// Do nothing if the location source's current Point is identical to the new location Point.
if (previousPoint.getCoordinates().equals(newPoint.getCoordinates())) {
return true;
}
// Or if the distance between the two points is less than 10 meters
if (MapboxUtil.distanceTo(previousPoint.getCoordinates(), newPoint.getCoordinates()) < 10) {
return true;
}
locationChangeAnimate(locationGeoJsonSource, previousPoint, newPoint);
return false;
}
use of com.mapbox.services.commons.geojson.Point in project androidApp by InspectorIncognito.
the class UserPlugin method locationChangeAnimate.
/*
* Animators
*/
/**
* Handles the animation from currentSourcePoint to the new user location point.
*/
private void locationChangeAnimate(@NonNull final GeoJsonSource locationGeoJsonSource, @NonNull Point currentSourcePoint, @NonNull Point newPoint) {
if (locationChangeAnimator != null) {
locationChangeAnimator.end();
}
locationChangeAnimator = ValueAnimator.ofObject(new PointEvaluator(), currentSourcePoint, newPoint);
locationChangeAnimator.setDuration(linearAnimation ? getLocationUpdateDuration() : LocationLayerConstants.LOCATION_UPDATE_DELAY_MS);
if (linearAnimation) {
locationChangeAnimator.setInterpolator(new LinearInterpolator());
} else {
locationChangeAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
}
locationChangeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
previousPoint = (Point) animation.getAnimatedValue();
userLocationFeature.setGeometry(previousPoint);
locationGeoJsonSource.setGeoJson(userLocationFeature);
if (tracking) {
mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(previousPoint.getCoordinates().getLatitude(), previousPoint.getCoordinates().getLongitude())));
}
}
});
locationChangeAnimator.start();
}
use of com.mapbox.services.commons.geojson.Point in project androidApp by InspectorIncognito.
the class MapboxUtil method convertToLatLng.
public static LatLng convertToLatLng(Feature feature) {
Point symbolPoint = (Point) feature.getGeometry();
Position position = symbolPoint.getCoordinates();
return new LatLng(position.getLatitude(), position.getLongitude());
}
Aggregations