Search in sources :

Example 1 with Point

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);
}
Also used : Point(com.mapbox.services.commons.geojson.Point)

Example 2 with Point

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);
        }
    }
}
Also used : FeatureCollection(com.mapbox.services.commons.geojson.FeatureCollection) Point(com.mapbox.services.commons.geojson.Point) Point(com.mapbox.services.commons.geojson.Point)

Example 3 with Point

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;
}
Also used : GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource) JsonObject(com.google.gson.JsonObject) Point(com.mapbox.services.commons.geojson.Point)

Example 4 with Point

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();
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Point(com.mapbox.services.commons.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) ValueAnimator(android.animation.ValueAnimator)

Example 5 with Point

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());
}
Also used : Position(com.mapbox.services.commons.models.Position) CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Point(com.mapbox.services.commons.geojson.Point) ILatLng(com.mapbox.mapboxsdk.geometry.ILatLng) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Aggregations

Point (com.mapbox.services.commons.geojson.Point)5 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)2 ValueAnimator (android.animation.ValueAnimator)1 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 JsonObject (com.google.gson.JsonObject)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 ILatLng (com.mapbox.mapboxsdk.geometry.ILatLng)1 GeoJsonSource (com.mapbox.mapboxsdk.style.sources.GeoJsonSource)1 FeatureCollection (com.mapbox.services.commons.geojson.FeatureCollection)1 Position (com.mapbox.services.commons.models.Position)1