Issue 519. Not rotate on low zoom levels

This commit is contained in:
Victor Shcherb 2011-09-18 13:31:25 +02:00
parent b5852e72db
commit fb37149847
2 changed files with 41 additions and 15 deletions

View file

@ -60,7 +60,7 @@ public class AnimateDraggingMapThread {
tileView.rotateToAnimate(rotationDiff / 5 + tileView.getRotate()); tileView.rotateToAnimate(rotationDiff / 5 + tileView.getRotate());
} }
} }
} while (conditionToCountinue); } while (conditionToCountinue && tileView.isMapRotateEnabled());
} }

View file

@ -43,6 +43,7 @@ import android.view.SurfaceHolder.Callback;
public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCallback, Callback { public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCallback, Callback {
protected final static int LOWEST_ZOOM_TO_ROTATE = 10;
protected final int emptyTileDivisor = 16; protected final int emptyTileDivisor = 16;
@ -263,11 +264,16 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
} }
public boolean isMapRotateEnabled(){
return zoom > LOWEST_ZOOM_TO_ROTATE;
}
public void setRotate(float rotate) { public void setRotate(float rotate) {
float diff = MapUtils.unifyRotationDiff(rotate, this.rotate); if (isMapRotateEnabled()) {
if (Math.abs(diff) > 5) { // check smallest rotation float diff = MapUtils.unifyRotationDiff(rotate, getRotate());
animatedDraggingThread.startRotate(rotate); if (Math.abs(diff) > 5) { // check smallest rotation
animatedDraggingThread.startRotate(rotate);
}
} }
} }
@ -280,7 +286,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
} }
public float getRotate() { public float getRotate() {
return rotate; return isMapRotateEnabled() ? rotate : 0;
} }
@ -488,7 +494,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
canvas.save(); canvas.save();
// rotate if needed // rotate if needed
if (!layer.drawInScreenPixels()) { if (!layer.drawInScreenPixels()) {
canvas.rotate(rotate, w, h); canvas.rotate(getRotate(), w, h);
} }
layer.onDraw(canvas, latlonRect, tilesRect, nightMode); layer.onDraw(canvas, latlonRect, tilesRect, nightMode);
canvas.restore(); canvas.restore();
@ -537,19 +543,37 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
// ///////////////////////////////// DRAGGING PART /////////////////////////////////////// // ///////////////////////////////// DRAGGING PART ///////////////////////////////////////
public float calcDiffTileY(float dx, float dy) { public float calcDiffTileY(float dx, float dy) {
return (-rotateSin * dx + rotateCos * dy) / getTileSize(); if(isMapRotateEnabled()){
return (-rotateSin * dx + rotateCos * dy) / getTileSize();
} else {
return dy / getTileSize();
}
} }
public float calcDiffTileX(float dx, float dy) { public float calcDiffTileX(float dx, float dy) {
return (rotateCos * dx + rotateSin * dy) / getTileSize(); if(isMapRotateEnabled()){
return (rotateCos * dx + rotateSin * dy) / getTileSize();
} else {
return dx / getTileSize();
}
} }
public float calcDiffPixelY(float dTileX, float dTileY) { public float calcDiffPixelY(float dTileX, float dTileY) {
return (rotateSin * dTileX + rotateCos * dTileY) * getTileSize(); if(isMapRotateEnabled()){
return (rotateSin * dTileX + rotateCos * dTileY) * getTileSize();
} else {
return dTileY * getTileSize();
}
} }
public float calcDiffPixelX(float dTileX, float dTileY) { public float calcDiffPixelX(float dTileX, float dTileY) {
return (rotateCos * dTileX - rotateSin * dTileY) * getTileSize(); if(isMapRotateEnabled()){
return (rotateCos * dTileX - rotateSin * dTileY) * getTileSize();
} else {
return dTileX * getTileSize();
}
} }
/** /**
@ -602,11 +626,13 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
} }
protected void rotateToAnimate(float rotate) { protected void rotateToAnimate(float rotate) {
this.rotate = MapUtils.unifyRotationTo360(rotate); if (isMapRotateEnabled()) {
float rotateRad = (float) Math.toRadians(rotate); this.rotate = MapUtils.unifyRotationTo360(rotate);
this.rotateCos = FloatMath.cos(rotateRad); float rotateRad = (float) Math.toRadians(rotate);
this.rotateSin = FloatMath.sin(rotateRad); this.rotateCos = FloatMath.cos(rotateRad);
refreshMap(); this.rotateSin = FloatMath.sin(rotateRad);
refreshMap();
}
} }
protected void setLatLonAnimate(double latitude, double longitude, boolean notify) { protected void setLatLonAnimate(double latitude, double longitude, boolean notify) {