show zoom level on map

git-svn-id: https://osmand.googlecode.com/svn/trunk@125 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-06-03 08:15:14 +00:00
parent f791e361ff
commit 97cf6850ff

View file

@ -24,6 +24,7 @@ public class MapInfoLayer implements OsmandMapLayer {
private Paint fillBlack; private Paint fillBlack;
private Paint fillRed; private Paint fillRed;
private RectF boundsForCompass; private RectF boundsForCompass;
private RectF boundsForZoom;
private RectF boundsForDist; private RectF boundsForDist;
private RectF boundsForSpeed; private RectF boundsForSpeed;
private Paint paintAlphaGray; private Paint paintAlphaGray;
@ -35,6 +36,8 @@ public class MapInfoLayer implements OsmandMapLayer {
private int cachedMeters = 0; private int cachedMeters = 0;
private String cachedSpeedString = null; private String cachedSpeedString = null;
private int cachedSpeed = 0; private int cachedSpeed = 0;
private int cachedZoom = 0;
private String cachedZoomString = "";
public MapInfoLayer(MapActivity map){ public MapInfoLayer(MapActivity map){
@ -67,7 +70,8 @@ public class MapInfoLayer implements OsmandMapLayer {
boundsForCompass = new RectF(0, 0, 32, 32); boundsForCompass = new RectF(0, 0, 32, 32);
boundsForDist = new RectF(32, 0, 110, 32); boundsForDist = new RectF(32, 0, 110, 32);
boundsForSpeed = new RectF(0, 32, 110, 64); boundsForZoom = new RectF(0, 32, 32, 64);
boundsForSpeed = new RectF(32, 32, 110, 64);
pathForCompass = new Path(); pathForCompass = new Path();
pathForCompass.moveTo(9, 15.5f); pathForCompass.moveTo(9, 15.5f);
@ -101,28 +105,44 @@ public class MapInfoLayer implements OsmandMapLayer {
cachedDistString = null; cachedDistString = null;
} else { } else {
cachedDistString = MapUtils.getFormattedDistance(cachedMeters); cachedDistString = MapUtils.getFormattedDistance(cachedMeters);
boundsForDist.right = paintBlack.measureText(cachedDistString) + 25 + boundsForDist.left; float right = paintBlack.measureText(cachedDistString) + 25 + boundsForDist.left;
boundsForSpeed.right = boundsForDist.right; if(cachedSpeedString != null){
boundsForSpeed.right = boundsForDist.right = Math.max(right, boundsForDist.right);
} else {
boundsForDist.right = right;
} }
} }
} }
}
if(view.getZoom() != cachedZoom){
cachedZoom = view.getZoom();
cachedZoomString = view.getZoom()+"";
}
// draw zoom
canvas.drawRoundRect(boundsForZoom, 3, 3, paintAlphaGray);
canvas.drawText(cachedZoomString, boundsForZoom.left + 5, boundsForZoom.bottom - 9, paintBlack);
// draw speed
if(map.getLastKnownLocation() != null && map.getLastKnownLocation().hasSpeed()){ if(map.getLastKnownLocation() != null && map.getLastKnownLocation().hasSpeed()){
if(cachedSpeed != (int) map.getLastKnownLocation().getSpeed()){ if(cachedSpeed != (int) map.getLastKnownLocation().getSpeed()){
cachedSpeed = (int) map.getLastKnownLocation().getSpeed(); cachedSpeed = (int) map.getLastKnownLocation().getSpeed();
cachedSpeedString = ((int) (cachedSpeed * 3.6d)) + " km/h"; cachedSpeedString = ((int) (cachedSpeed * 3.6d)) + " km/h";
float right = paintBlack.measureText(cachedSpeedString) + 8 + boundsForSpeed.left;
boundsForSpeed.right = boundsForDist.right = Math.max(right, boundsForDist.right);
} }
if(cachedSpeed > 0){ if(cachedSpeed > 0){
canvas.drawRoundRect(boundsForSpeed, 3, 3, paintAlphaGray); canvas.drawRoundRect(boundsForSpeed, 3, 3, paintAlphaGray);
canvas.drawText(cachedSpeedString, boundsForSpeed.left + 15, boundsForSpeed.bottom - 9, paintBlack); canvas.drawText(cachedSpeedString, boundsForSpeed.left + 8, boundsForSpeed.bottom - 9, paintBlack);
} }
} }
// draw distance to point
if(cachedDistString != null){ if(cachedDistString != null){
canvas.drawRoundRect(boundsForDist, 3, 3, paintAlphaGray); canvas.drawRoundRect(boundsForDist, 3, 3, paintAlphaGray);
canvas.drawCircle(boundsForDist.left + 8, boundsForDist.bottom - 15, 4, fillRed); canvas.drawCircle(boundsForDist.left + 8, boundsForDist.bottom - 15, 4, fillRed);
canvas.drawText(cachedDistString, boundsForDist.left + 15, boundsForDist.bottom - 9, paintBlack); canvas.drawText(cachedDistString, boundsForDist.left + 15, boundsForDist.bottom - 9, paintBlack);
} }
// draw the last because it use rotating // draw compass the last because it use rotating
canvas.drawRoundRect(boundsForCompass, 3, 3, paintAlphaGray); canvas.drawRoundRect(boundsForCompass, 3, 3, paintAlphaGray);
canvas.rotate(view.getRotate(), 15, 15); canvas.rotate(view.getRotate(), 15, 15);
canvas.drawPath(pathForCompass2, fillRed); canvas.drawPath(pathForCompass2, fillRed);