From fcfff39bf43b441b1c47b05a61824c1223d199b8 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 13 Jul 2010 16:14:42 +0000 Subject: [PATCH] improve multi touch zoom git-svn-id: https://osmand.googlecode.com/svn/trunk@334 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/ToDoConstants.java | 2 ++ .../activities/NavigatePointActivity.java | 5 ++++- .../views/AnimateDraggingMapThread.java | 13 +++++++------ .../com/osmand/views/MultiTouchSupport.java | 7 +++++-- .../com/osmand/views/OsmandMapTileView.java | 19 +++++++++++++++---- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index 1ab9f8390d..83b82117bf 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -21,6 +21,8 @@ public class ToDoConstants { // (introduce special settings how often update location to monitoring & audio guidance) // Improvement : Show stops in the transport route on the map // Improvement : redesign poi selecting (show on map ) + /// Better : improve zooming (better zoom out) + // BUG with search area for poi/transport bounds region // 69. Add phone information to POI // Not clear if it is really needed diff --git a/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java b/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java index a819d8cdc6..fc7534c37f 100644 --- a/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java +++ b/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java @@ -21,6 +21,7 @@ import com.osmand.LogUtil; import com.osmand.OsmandSettings; import com.osmand.R; import com.osmand.osm.LatLon; +import com.osmand.views.OsmandMapTileView; public class NavigatePointActivity extends Activity { Dialog dlg; @@ -128,7 +129,9 @@ public class NavigatePointActivity extends Activity { } else { // in case when it is dialog if(activity != null) { - activity.setMapLocation(lat, lon); + OsmandMapTileView v = activity.getMapView(); + activity.getMapView().getAnimatedDraggingThread().startMoving(v.getLatitude(), v.getLongitude(), + lat, lon, v.getZoom(), v.getZoom(), v.getSourceTileSize(), v.getRotate(), true); } else { OsmandSettings.setMapLocationToShow(this, lat, lon, MessageFormat.format(getString(R.string.search_history_navigate_to), lat, lon)); } diff --git a/OsmAnd/src/com/osmand/views/AnimateDraggingMapThread.java b/OsmAnd/src/com/osmand/views/AnimateDraggingMapThread.java index 0b2002d5a2..5c09098bce 100644 --- a/OsmAnd/src/com/osmand/views/AnimateDraggingMapThread.java +++ b/OsmAnd/src/com/osmand/views/AnimateDraggingMapThread.java @@ -213,14 +213,15 @@ public class AnimateDraggingMapThread implements Runnable { endZ = endZoom; - timeZInt = Math.abs(curZoom - intZ) * 300; - if (timeZInt > 1200) { - timeZInt = 1200; - } +// timeZInt = Math.abs(curZoom - intZ) * 300; +// if (timeZInt > 900) { +// +// } + timeZInt = 600; timeZEnd = 500; timeMove = (int) (Math.abs(moveX) + Math.abs(moveY) * 4); - if(timeMove > 2000){ - timeMove = 2000; + if(timeMove > 2200){ + timeMove = 2200; } animateDrag = false; phaseOfMoving = (byte) (intZ == curZoom ? 1 : 0); diff --git a/OsmAnd/src/com/osmand/views/MultiTouchSupport.java b/OsmAnd/src/com/osmand/views/MultiTouchSupport.java index cde0a6ceb7..ec18662451 100644 --- a/OsmAnd/src/com/osmand/views/MultiTouchSupport.java +++ b/OsmAnd/src/com/osmand/views/MultiTouchSupport.java @@ -5,6 +5,7 @@ import java.lang.reflect.Method; import org.apache.commons.logging.Log; import android.content.Context; +import android.graphics.PointF; import android.util.FloatMath; import android.view.MotionEvent; @@ -21,7 +22,7 @@ public class MultiTouchSupport { public interface MultiTouchZoomListener { - public void onZoomStarted(float distance); + public void onZoomStarted(float distance, PointF centerPoint); public void onZooming(float distance, float relativeToStart); @@ -70,6 +71,7 @@ public class MultiTouchSupport { private boolean inZoomMode = false; private float zoomStartedDistance = 100; private float previousZoom = 1; + private PointF centerPoint = new PointF(); public boolean onTouchEvent(MotionEvent event){ if(!isMultiTouchSupported()){ @@ -91,7 +93,8 @@ public class MultiTouchSupport { float distance = FloatMath.sqrt((x2 - x1)*(x2 -x1) + (y2-y1)*(y2-y1)); previousZoom = distance / zoomStartedDistance; if (actionCode == ACTION_POINTER_DOWN) { - listener.onZoomStarted(distance); + centerPoint = new PointF((x1 + x2) / 2, (y1 + y2) / 2); + listener.onZoomStarted(distance, centerPoint); zoomStartedDistance = distance; inZoomMode = true; return true; diff --git a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java index 0ece57d6a0..44ac7e4f74 100644 --- a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java @@ -97,6 +97,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall private AnimateDraggingMapThread animatedDraggingThread; private float initialMultiTouchZoom; + private PointF initialMultiTouchCenterPoint; + private LatLon initialMultiTouchLocation; private GestureDetector gestureDetector; @@ -701,22 +703,31 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall @Override public void onZoomEnded(float distance, float relativeToStart) { - float dz = (float) (Math.log(relativeToStart) / Math.log(2) * 1.5); - initialMultiTouchZoom = (float) Math.round(initialMultiTouchZoom + dz); - setZoom(initialMultiTouchZoom); + onZooming(distance, relativeToStart); } @Override - public void onZoomStarted(float distance) { + public void onZoomStarted(float distance, PointF centerPoint) { + initialMultiTouchCenterPoint = centerPoint; + initialMultiTouchLocation = getLatLonFromScreenPoint(centerPoint.x, centerPoint.y); initialMultiTouchZoom = zoom; } @Override public void onZooming(float distance, float relativeToStart) { float dz = (float) (Math.log(relativeToStart) / Math.log(2) * 1.5); + float dtx = calcDiffTileX(getCenterPointX() - initialMultiTouchCenterPoint.x, getCenterPointY() - initialMultiTouchCenterPoint.y); + float dty = calcDiffTileY(getCenterPointX() - initialMultiTouchCenterPoint.x, getCenterPointY() - initialMultiTouchCenterPoint.y); + double tx = MapUtils.getTileNumberX(getFloatZoom(), initialMultiTouchLocation.getLongitude()); + double ty = MapUtils.getTileNumberY(getFloatZoom(), initialMultiTouchLocation.getLatitude()); + double lat = MapUtils.getLatitudeFromTile(getFloatZoom(), ty + dty); + double lon = MapUtils.getLongitudeFromTile(getFloatZoom(), tx + dtx); + + if(Math.abs(initialMultiTouchZoom + dz - zoom) > 0.05){ setZoom(initialMultiTouchZoom + dz); + setLatLon(lat, lon); } }