diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index da47505924..2b6e69c05e 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -171,8 +171,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc if (mapView != null) { RotatedTileBox tb = mapView.getCurrentRotatedTileBox(); if (isMapLinkedToLocation() && location != null) { + Integer zoom = null; + Float rotation = null; if (settings.AUTO_ZOOM_MAP.get()) { - autozoom(location); + zoom = autozoom(location); } int currentMapRotation = settings.ROTATE_MAP.get(); boolean smallSpeed = isSmallSpeedForCompass(location); @@ -183,14 +185,16 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc if (location.hasBearing() && !smallSpeed) { // special case when bearing equals to zero (we don't change anything) if (location.getBearing() != 0f) { - mapView.setRotate(-location.getBearing()); + rotation = -location.getBearing(); + //mapView.setRotate(-location.getBearing()); } } } else if(currentMapRotation == OsmandSettings.ROTATE_MAP_COMPASS) { showViewAngle = routePlanningMode; // disable compass rotation in that mode } registerUnregisterSensor(location); - mapView.setLatLon(location.getLatitude(), location.getLongitude()); + mapView.getAnimatedDraggingThread().startMovingNav(location.getLatitude(), location.getLongitude(), zoom, rotation); + //mapView.setLatLon(location.getLatitude(), location.getLongitude()); } else if(location != null) { showViewAngle = (!location.hasBearing() || isSmallSpeedForCompass(location)) && (tb != null && tb.containsLatLon(location.getLatitude(), location.getLongitude())); @@ -273,7 +277,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc return zoomDelta; } - public void autozoom(Location location) { + public Integer autozoom(Location location) { if (location.hasSpeed()) { long now = System.currentTimeMillis(); final RotatedTileBox tb = mapView.getCurrentRotatedTileBox(); @@ -298,11 +302,13 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc // round to 0.33 targetZoom = Math.round(targetZoom * 3) / 3f; int newIntegerZoom = (int)Math.round(targetZoom); - double zPart = targetZoom - newIntegerZoom; - mapView.getAnimatedDraggingThread().startZooming(newIntegerZoom, zPart, false); + //double zPart = targetZoom - newIntegerZoom; + //mapView.getAnimatedDraggingThread().startZooming(newIntegerZoom, zPart, false); + return newIntegerZoom; } } } + return mapView.getZoom(); } public void backToLocationImpl() { diff --git a/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java b/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java index 8f4a3dcac1..e64cfd4dbf 100644 --- a/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java +++ b/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java @@ -1,5 +1,10 @@ package net.osmand.plus.views; +import android.os.SystemClock; +import android.view.animation.AccelerateDecelerateInterpolator; +import android.view.animation.DecelerateInterpolator; +import android.view.animation.LinearInterpolator; + import net.osmand.PlatformUtil; import net.osmand.core.android.MapRendererView; import net.osmand.data.RotatedTileBox; @@ -7,11 +12,6 @@ import net.osmand.util.MapUtils; import org.apache.commons.logging.Log; -import android.os.SystemClock; -import android.view.animation.AccelerateDecelerateInterpolator; -import android.view.animation.DecelerateInterpolator; -import android.view.animation.LinearInterpolator; - /** * Thread for animated dragging. * Defines accelerator to stop dragging screen. @@ -116,8 +116,61 @@ public class AnimateDraggingMapThread { } - - public void startMoving(final double finalLat, final double finalLon, final int endZoom, final boolean notifyListener){ + public void startMovingNav(final double finalLat, final double finalLon, final Integer finalZoom, final Float finalRotation){ + stopAnimatingSync(); + final RotatedTileBox rb = tileView.getCurrentRotatedTileBox().copy(); + double startLat = rb.getLatitude(); + double startLon = rb.getLongitude(); + final int startZoom = rb.getZoom(); + final double startZoomFP = rb.getZoomFloatPart(); + final float startRotaton = rb.getRotate(); + + final float mMoveX = rb.getPixXFromLatLon(startLat, startLon) - rb.getPixXFromLatLon(finalLat, finalLon); + final float mMoveY = rb.getPixYFromLatLon(startLat, startLon) - rb.getPixYFromLatLon(finalLat, finalLon); + + final float animationTime = Math.max(450, (Math.abs(mMoveX) + Math.abs(mMoveY)) / 1200f * MOVE_MOVE_ANIMATION_TIME); + + final int zoom; + final float rotation; + if (finalZoom != null) { + zoom = finalZoom; + } else { + zoom = startZoom; + } + if (finalRotation != null) { + rotation = finalRotation; + } else { + rotation = startRotaton; + } + + startThreadAnimating(new Runnable() { + + @Override + public void run() { + setTargetValues(zoom, finalLat, finalLon); + if (zoom != startZoom || startZoomFP != 0) { + animatingZoomInThread(startZoom, startZoomFP, zoom, 0, ZOOM_MOVE_ANIMATION_TIME, false); + } + + if (!stopped){ + animatingMoveInThread(mMoveX, mMoveY, animationTime, false); + } + + if (!stopped){ + tileView.setLatLonAnimate(finalLat, finalLon, false); + } + + tileView.setFractionalZoom(zoom, 0, false); + + if (rotation != startRotaton) { + AnimateDraggingMapThread.this.targetRotate = rotation; + } + pendingRotateAnimation(); + } + }); + } + + public void startMoving(final double finalLat, final double finalLon, final int endZoom, final boolean notifyListener){ stopAnimatingSync(); final RotatedTileBox rb = tileView.getCurrentRotatedTileBox().copy(); double startLat = rb.getLatitude();