From ebe7501c8b1b68e90e2a7d280086f3e2fd07c785 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 13 Jul 2010 19:55:56 +0000 Subject: [PATCH] fix multitouch zooming git-svn-id: https://osmand.googlecode.com/svn/trunk@336 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../com/osmand/views/OsmandMapTileView.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java index 44ac7e4f74..3a7e771a2b 100644 --- a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java @@ -703,7 +703,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall @Override public void onZoomEnded(float distance, float relativeToStart) { - onZooming(distance, relativeToStart); + float dz = (float) (Math.log(relativeToStart) / Math.log(2) * 1.5); + float calcZoom = initialMultiTouchZoom + dz; + setZoom(Math.round(calcZoom)); + zoomPositionChanged(getFloatZoom()); } @@ -713,21 +716,24 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall initialMultiTouchLocation = getLatLonFromScreenPoint(centerPoint.x, centerPoint.y); initialMultiTouchZoom = zoom; } + private void zoomPositionChanged(float calcZoom){ + float dtx = calcDiffTileX(getCenterPointX() - initialMultiTouchCenterPoint.x, getCenterPointY() - initialMultiTouchCenterPoint.y); + float dty = calcDiffTileY(getCenterPointX() - initialMultiTouchCenterPoint.x, getCenterPointY() - initialMultiTouchCenterPoint.y); + double tx = MapUtils.getTileNumberX(calcZoom, initialMultiTouchLocation.getLongitude()); + double ty = MapUtils.getTileNumberY(calcZoom, initialMultiTouchLocation.getLatitude()); + double lat = MapUtils.getLatitudeFromTile(calcZoom, ty + dty); + double lon = MapUtils.getLongitudeFromTile(calcZoom, tx + dtx); + setLatLon(lat, lon); + } + @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); + float calcZoom = initialMultiTouchZoom + dz; + if(Math.abs(calcZoom - zoom) > 0.05){ + setZoom(calcZoom); + zoomPositionChanged(calcZoom); } }