Fix floating my position

This commit is contained in:
Alexey Kulish 2017-04-03 15:40:21 +03:00
parent 36f4e57f6a
commit adad814929
3 changed files with 33 additions and 7 deletions

View file

@ -52,6 +52,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
private Location myLocation;
private Float heading;
private boolean drivingRegionUpdated = false;
private boolean movingToMyLocation = false;
public MapViewTrackingUtilities(OsmandApplication app){
this.app = app;
@ -145,6 +146,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
this.contextMenu = contextMenu;
}
public boolean isMovingToMyLocation() {
return movingToMyLocation;
}
@Override
public void updateLocation(Location location) {
myLocation = location;
@ -194,7 +199,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
showViewAngle = routePlanningMode; // disable compass rotation in that mode
}
registerUnregisterSensor(location);
if (settings.ANIMATE_MY_LOCATION.get() && !smallSpeedForAnimation) {
if (settings.ANIMATE_MY_LOCATION.get() && !smallSpeedForAnimation && !movingToMyLocation) {
mapView.getAnimatedDraggingThread().startMoving(
location.getLatitude(), location.getLongitude(), zoom, rotation, false);
} else {
@ -333,7 +338,14 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
net.osmand.Location lastKnownLocation = locationProvider.getLastKnownLocation();
AnimateDraggingMapThread thread = mapView.getAnimatedDraggingThread();
int fZoom = mapView.getZoom() < 15 ? 15 : mapView.getZoom();
thread.startMoving(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), fZoom, false);
movingToMyLocation = true;
thread.startMoving(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(),
fZoom, false, new Runnable() {
@Override
public void run() {
movingToMyLocation = false;
}
});
}
mapView.refreshMap();
}

View file

@ -170,13 +170,18 @@ public class AnimateDraggingMapThread {
}
if (!stopped){
animatingMoveInThread(mMoveX, mMoveY, NAV_ANIMATION_TIME, notifyListener);
animatingMoveInThread(mMoveX, mMoveY, NAV_ANIMATION_TIME, notifyListener, null);
}
}
});
}
public void startMoving(final double finalLat, final double finalLon, final int endZoom, final boolean notifyListener) {
startMoving(finalLat, finalLon, endZoom, notifyListener, null);
}
public void startMoving(final double finalLat, final double finalLon, final int endZoom,
final boolean notifyListener, final Runnable finishAminationCallback) {
stopAnimatingSync();
final RotatedTileBox rb = tileView.getCurrentRotatedTileBox().copy();
double startLat = rb.getLatitude();
@ -219,7 +224,7 @@ public class AnimateDraggingMapThread {
}
if(!stopped){
animatingMoveInThread(mMoveX, mMoveY, animationTime, notifyListener);
animatingMoveInThread(mMoveX, mMoveY, animationTime, notifyListener, finishAminationCallback);
}
if(!stopped){
tileView.setLatLonAnimate(finalLat, finalLon, notifyListener);
@ -262,7 +267,7 @@ public class AnimateDraggingMapThread {
}
private void animatingMoveInThread(float moveX, float moveY, float animationTime,
boolean notify){
boolean notify, final Runnable finishAnimationCallback){
AccelerateDecelerateInterpolator interpolator = new AccelerateDecelerateInterpolator();
float cX = 0;
@ -286,6 +291,14 @@ public class AnimateDraggingMapThread {
stopped = true;
}
}
if (finishAnimationCallback != null) {
tileView.getApplication().runInUIThread(new Runnable() {
@Override
public void run() {
finishAnimationCallback.run();
}
});
}
}
private void animatingZoomInThread(int zoomStart, double zoomFloatStart,

View file

@ -92,7 +92,8 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
int locationX;
int locationY;
if (mapViewTrackingUtilities.isMapLinkedToLocation()
&& !MapViewTrackingUtilities.isSmallSpeedForAnimation(lastKnownLocation)) {
&& !MapViewTrackingUtilities.isSmallSpeedForAnimation(lastKnownLocation)
&& !mapViewTrackingUtilities.isMovingToMyLocation()) {
locationX = box.getPixXFromLonNoRot(box.getLongitude());
locationY = box.getPixYFromLatNoRot(box.getLatitude());
} else {