[android] #3629 - smooth MyLocationView animation when tracking the user location, introducing a new easeTo method with a linear interpolator
This commit is contained in:
@@ -1182,7 +1182,7 @@ public class MapView extends FrameLayout {
|
||||
mNativeMapView.jumpTo(bearing, center, pitch, zoom);
|
||||
}
|
||||
|
||||
void easeTo(double bearing, LatLng center, long duration, double pitch, double zoom, @Nullable final MapboxMap.CancelableCallback cancelableCallback) {
|
||||
void easeTo(double bearing, LatLng center, long duration, double pitch, double zoom, boolean easingInterpolator, @Nullable final MapboxMap.CancelableCallback cancelableCallback) {
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
@@ -1203,7 +1203,7 @@ public class MapView extends FrameLayout {
|
||||
});
|
||||
}
|
||||
|
||||
mNativeMapView.easeTo(bearing, center, duration, pitch, zoom);
|
||||
mNativeMapView.easeTo(bearing, center, duration, pitch, zoom, easingInterpolator);
|
||||
}
|
||||
|
||||
void flyTo(double bearing, LatLng center, long duration, double pitch, double zoom, @Nullable final MapboxMap.CancelableCallback cancelableCallback) {
|
||||
|
||||
@@ -331,8 +331,18 @@ public class MapboxMap {
|
||||
*/
|
||||
@UiThread
|
||||
public final void easeCamera(CameraUpdate update, int durationMs, final MapboxMap.CancelableCallback callback) {
|
||||
easeCamera(update, durationMs, true, callback);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public final void easeCamera(CameraUpdate update, int durationMs, boolean easingInterpolator) {
|
||||
easeCamera(update, durationMs, easingInterpolator, null);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public final void easeCamera(CameraUpdate update, int durationMs, boolean easingInterpolator, final MapboxMap.CancelableCallback callback) {
|
||||
mCameraPosition = update.getCameraPosition(this);
|
||||
mMapView.easeTo(mCameraPosition.bearing, mCameraPosition.target, getDurationNano(durationMs), mCameraPosition.tilt, mCameraPosition.zoom, new CancelableCallback() {
|
||||
mMapView.easeTo(mCameraPosition.bearing, mCameraPosition.target, getDurationNano(durationMs), mCameraPosition.tilt, mCameraPosition.zoom, easingInterpolator, new CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
if (callback != null) {
|
||||
|
||||
@@ -446,8 +446,8 @@ final class NativeMapView {
|
||||
nativeJumpTo(mNativeMapViewPtr, angle, center, pitch, zoom);
|
||||
}
|
||||
|
||||
public void easeTo(double angle, LatLng center, long duration, double pitch, double zoom) {
|
||||
nativeEaseTo(mNativeMapViewPtr, angle, center, duration, pitch, zoom);
|
||||
public void easeTo(double angle, LatLng center, long duration, double pitch, double zoom, boolean easingInterpolator) {
|
||||
nativeEaseTo(mNativeMapViewPtr, angle, center, duration, pitch, zoom, easingInterpolator);
|
||||
}
|
||||
|
||||
public void flyTo(double angle, LatLng center, long duration, double pitch, double zoom) {
|
||||
@@ -641,7 +641,7 @@ final class NativeMapView {
|
||||
|
||||
private native void nativeJumpTo(long nativeMapViewPtr, double angle, LatLng center, double pitch, double zoom);
|
||||
|
||||
private native void nativeEaseTo(long nativeMapViewPtr, double angle, LatLng center, long duration, double pitch, double zoom);
|
||||
private native void nativeEaseTo(long nativeMapViewPtr, double angle, LatLng center, long duration, double pitch, double zoom, boolean easingInterpolator);
|
||||
|
||||
private native void nativeFlyTo(long nativeMapViewPtr, double angle, LatLng center, long duration, double pitch, double zoom);
|
||||
|
||||
|
||||
@@ -120,7 +120,6 @@ public class MyLocationView extends View {
|
||||
throw new RuntimeException("The dimensions from location and bearing drawables should be match");
|
||||
}
|
||||
|
||||
|
||||
foregroundDrawable = defaultDrawable;
|
||||
foregroundBearingDrawable = bearingDrawable;
|
||||
setForegroundDrawableTint(foregroundTintColor);
|
||||
@@ -594,8 +593,7 @@ public class MyLocationView extends View {
|
||||
if (previousUpdateTimeStamp == 0) {
|
||||
locationUpdateDuration = 0;
|
||||
} else {
|
||||
// TODO remove 10 * hack to multiply duration to workaround easing interpolation (easeCamera)
|
||||
locationUpdateDuration = 10 * (locationUpdateTimestamp - previousUpdateTimeStamp);
|
||||
locationUpdateDuration = locationUpdateTimestamp - previousUpdateTimeStamp;
|
||||
}
|
||||
|
||||
// calculate interpolated location
|
||||
@@ -613,7 +611,6 @@ public class MyLocationView extends View {
|
||||
}
|
||||
gpsDirection = 0;
|
||||
setCompass(gpsDirection);
|
||||
// }
|
||||
} else if (myBearingTrackingMode == MyBearingTracking.COMPASS) {
|
||||
if (!compassListener.isPaused()) {
|
||||
builder.bearing(compassListener.getCurrentDegree());
|
||||
@@ -622,10 +619,11 @@ public class MyLocationView extends View {
|
||||
}
|
||||
}
|
||||
|
||||
// accuracy
|
||||
updateAccuracy(location);
|
||||
|
||||
// animate to new camera
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), (int) locationUpdateDuration, null);
|
||||
// ease to new camera position with a linear interpolator
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), (int) locationUpdateDuration, false /*linear interpolator*/);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user