improve multi touch zoom
git-svn-id: https://osmand.googlecode.com/svn/trunk@334 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
68c5662526
commit
fcfff39bf4
5 changed files with 33 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue