Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ final class LocationLayer implements LocationLayerAnimator.OnAnimationsValuesCha
private final Map<String, GeoJsonSource> sourceMap = new HashMap<>();

LocationLayer(MapView mapView, MapboxMap mapboxMap, LocationLayerOptions options) {
this.mapboxMap = mapboxMap;
this.context = mapView.getContext();
this.mapboxMap = mapboxMap;
this.options = options;
initializeComponents();
setRenderMode(RenderMode.NORMAL);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.mapbox.mapboxsdk.plugins.locationlayer;

import android.animation.ValueAnimator;
import android.location.Location;
import android.support.annotation.NonNull;

import com.mapbox.mapboxsdk.geometry.LatLng;
Expand All @@ -26,31 +25,22 @@ void removeListener(OnAnimationsValuesChangeListener listener) {
listeners.remove(listener);
}

void feedNewLocation(@NonNull Location previousLocation, @NonNull Location newLocation) {
LatLng previousLatLng;
if (latLngAnimator != null) {
previousLatLng = (LatLng) latLngAnimator.getAnimatedValue();
} else {
previousLatLng = new LatLng(previousLocation);
}
LatLng newLatLng = new LatLng(newLocation);
void feedNewLatLng(@NonNull LatLng previousTargetLatLng, @NonNull LatLng targetLatLng) {
cancelLatLngAnimation();
latLngAnimator = new LatLngAnimator(previousTargetLatLng, targetLatLng, 1000);
// FIXME: 22/02/2018 evaluate duration of animation better

float previousBearing;
if (gpsBearingAnimator != null) {
previousBearing = (float) gpsBearingAnimator.getAnimatedValue();
} else {
previousBearing = previousLocation.getBearing();
}
latLngAnimator.addUpdateListener(latLngUpdateListener);
latLngAnimator.start();
}

cancelLocationAnimations();
latLngAnimator = new LatLngAnimator(previousLatLng, newLatLng, 1000);
gpsBearingAnimator = new BearingAnimator(previousBearing, newLocation.getBearing(), 1000);
void feedNewGpsBearing(float previousGpsBearing, float targetGpsBearing) {
cancelBearingAnimation();
float normalizedTargetGpsBearing = Utils.shortestRotation(previousGpsBearing, targetGpsBearing);
gpsBearingAnimator = new BearingAnimator(previousGpsBearing, normalizedTargetGpsBearing, 1000);
// FIXME: 22/02/2018 evaluate duration of animation better

latLngAnimator.addUpdateListener(latLngUpdateListener);
gpsBearingAnimator.addUpdateListener(gpsBearingUpdateListener);

latLngAnimator.start();
gpsBearingAnimator.start();
}

Expand Down Expand Up @@ -102,16 +92,18 @@ interface OnAnimationsValuesChangeListener {
}

void cancelAllAnimations() {
cancelLocationAnimations();
cancelLatLngAnimation();
cancelCompassAnimations();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cancelBearingAnimation() not called.

}

private void cancelLocationAnimations() {
private void cancelLatLngAnimation() {
if (latLngAnimator != null) {
latLngAnimator.cancel();
latLngAnimator.removeAllUpdateListeners();
}
}

private void cancelBearingAnimation() {
if (gpsBearingAnimator != null) {
gpsBearingAnimator.cancel();
gpsBearingAnimator.removeAllUpdateListeners();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@ public void onNewLatLngValue(LatLng latLng) {
@Override
public void onNewGpsBearingValue(float gpsBearing) {
if (cameraMode == CameraMode.TRACKING_GPS
|| cameraMode == CameraMode.NONE_GPS) {
|| cameraMode == CameraMode.NONE_GPS
|| cameraMode == CameraMode.TRACKING_GPS_NORTH) {
setBearing(gpsBearing);
}

if (cameraMode == CameraMode.TRACKING_GPS_NORTH) {
setBearing(0);
}
}

@Override
Expand All @@ -62,8 +59,3 @@ public void onNewCompassBearingValue(float compassBearing) {
}
}
}


/*

float targetBearing = Utils.shortestRotation(0, (float) bearing);*/
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,19 @@ private void updateLocation(final Location location) {
}

staleStateManager.updateLatestLocationTime();

if (lastLocation != null) {
locationLayerAnimator.feedNewLocation(lastLocation, location);
LatLng previousLatLngTarget = new LatLng(lastLocation);
LatLng latLngTarget = new LatLng(location);
locationLayerAnimator.feedNewLatLng(previousLatLngTarget, latLngTarget);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't previousLatLngTarget be taken from the current camera position, not from the last location?


float previousGpsBearing = lastLocation.getBearing();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for previousLatLngTarget.

if (getCameraMode() == CameraMode.TRACKING_GPS_NORTH && mapboxMap.getCameraPosition().bearing != 0) {
locationLayerAnimator.feedNewGpsBearing(previousGpsBearing, 0);
} else {
locationLayerAnimator.feedNewGpsBearing(previousGpsBearing, location.getBearing());
}
}

lastLocation = location;
}

Expand Down