fix rendering

git-svn-id: https://osmand.googlecode.com/svn/trunk@486 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-09-02 20:58:06 +00:00
parent 2b3525ec2d
commit 7818380320
4 changed files with 197 additions and 59 deletions

View file

@ -5,11 +5,36 @@ import net.osmand.osm.OSMSettings.OSMTagKey;
/**
* SOURCE : http://wiki.openstreetmap.org/wiki/Map_Features
*
* Describing types of polygons :
* 1. Last 3 bits define type of element : polygon, polyline, point
*/
public class MapRenderingTypes {
// OSM keys :
// 1. highway (lines) +
// 2. highway (node) - [stop, roundabout, speed_camera]
// 3. traffic_calming -
// 4. service - [parking_aisle]
// 5. barrier -
// 6. cycleway - [? different kinds of cycleways]
// 7. waterway -
// 8. railway -
// 9. aeroway/aerialway -
// 10. power -
// 11. man_made -
// 12. building +
// ---------------------------------
// 13. leisure, amenity, shop, tourism, historic, sport -
// 14. emergency -
// 15. landuse -
// 16. natural -
// 17. military -
// 18. route (?)
// 19. boundary (?)
// 20. RESTRICTIONS
public final static int TYPE_MASK = (1 << 3) - 1;
@ -17,6 +42,7 @@ public class MapRenderingTypes {
public final static int POLYLINE_TYPE = 2;
public final static int POINT_TYPE = 1;
// 1. polygon
public final static int PG_AREA_MASK = (1 << 6) - 1;
public final static int PG_BUILDING_TYPE = 1;
@ -26,6 +52,9 @@ public class MapRenderingTypes {
public final static int PL_TYPE_MASK = (1 << 4) - 1;
public final static int PL_HIGHWAY_TYPE = 1;
// highway : sss|aaa|f|ttttt|o|0001|011
// o - oneway, t - type of way, f - free or toll, a - acess, max speed - s = 20 bits
// 2._ - 1bit
public final static int PL_HW_ONEWAY = 1;
@ -33,16 +62,27 @@ public class MapRenderingTypes {
// TODO max speed class (?)
// TODO free (?)
// 2._.1 highway types
public final static int PL_HW_TYPE_MASK = (1 << 5) -1;
public final static int PL_HW_TRUNK = 1;
public final static int PL_HW_MOTORWAY = 2;
public final static int PL_HW_PRIMARY = 3;
public final static int PL_HW_SECONDARY = 4;
public final static int PL_HW_TERTIARY = 5;
public final static int PL_HW_RESIDENTIAL = 6;
public final static int PL_HW_TRACK = 7;
public final static int PL_HW_PATH = 8;
public final static int PL_HW_UNCLASSIFIED = 9;
public final static int PL_HW_SERVICE = 10;
public final static int PL_HW_SERVICE = 7;
public final static int PL_HW_UNCLASSIFIED = 8;
public final static int PL_HW_TRACK = 9;
public final static int PL_HW_PATH = 10;
public final static int PL_HW_LIVING_STREET = 11;
public final static int PL_HW_CYCLEWAY = 17;
public final static int PL_HW_FOOTWAY = 18;
public final static int PL_HW_STEPS = 19;
public final static int PL_HW_BRIDLEWAY = 20;
public final static int PL_HW_CONSTRUCTION = 31;
@ -87,7 +127,21 @@ public class MapRenderingTypes {
return PL_HW_TRACK;
} else if(hw.equals("PATH")){ //$NON-NLS-1$
return PL_HW_PATH;
} else if(hw.equals("UNCLASSIFIED")){ //$NON-NLS-1$
} else if(hw.equals("SERVICE") || hw.equals("SERVICES")){ //$NON-NLS-1$ //$NON-NLS-2$
return PL_HW_SERVICE;
} else if(hw.equals("LIVING_STREET")){ //$NON-NLS-1$
return PL_HW_LIVING_STREET;
} else if(hw.equals("CONSTRUCTION")){ //$NON-NLS-1$
return PL_HW_CONSTRUCTION;
} else if(hw.equals("STEPS")){ //$NON-NLS-1$
return PL_HW_STEPS;
} else if(hw.equals("BRIDLEWAY")){ //$NON-NLS-1$
return PL_HW_BRIDLEWAY;
} else if(hw.equals("CYCLEWAY")){ //$NON-NLS-1$
return PL_HW_CYCLEWAY;
} else if(hw.equals("PEDESTRIAN") | hw.equals("FOOTWAY")){ //$NON-NLS-1$ //$NON-NLS-2$
return PL_HW_FOOTWAY;
} else if(hw.equals("UNCLASSIFIED") || hw.equals("ROAD")){ //$NON-NLS-1$ //$NON-NLS-2$
return PL_HW_UNCLASSIFIED;
}
return 0;

View file

@ -63,7 +63,7 @@ public class ResourceManager {
// it is not good investigated but no more than 64 (satellite images)
// Only 8 MB (from 16 Mb whole mem) available for images : image 64K * 128 = 8 MB (8 bit), 64 - 16 bit, 32 - 32 bit
protected int maxImgCacheSize = 48;
protected int maxImgCacheSize = 32;
protected Map<String, Bitmap> cacheOfImages = new LinkedHashMap<String, Bitmap>();
protected Map<String, Boolean> imagesOnFS = new LinkedHashMap<String, Boolean>() ;
@ -567,9 +567,9 @@ public class ResourceManager {
}
}
if(source == null || source.getBitDensity() == 0){
maxImgCacheSize = 48;
maxImgCacheSize = 32;
} else {
maxImgCacheSize = 384 / source.getBitDensity();
maxImgCacheSize = Math.max(384 / source.getBitDensity() , 32);
}
}

View file

@ -2,12 +2,13 @@ package net.osmand.render;
import java.util.List;
import org.apache.commons.logging.Log;
import net.osmand.LogUtil;
import net.osmand.osm.MapRenderObject;
import net.osmand.osm.MapRenderingTypes;
import net.osmand.osm.MapUtils;
import org.apache.commons.logging.Log;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
@ -54,8 +55,20 @@ public class OsmandRenderer {
paintFillWhite.setColor(Color.rgb(241, 238, 232));
}
public Bitmap getBitmap(){
return bmp;
}
public synchronized void clearBitmap(){
if(bmp != null){
bmp.recycle();
}
bmp = null;
}
public void generateNewBitmap(RectF objectLoc, List<MapRenderObject> objects, int zoom, float rotate) {
long now = System.currentTimeMillis();
// TODO sort objects first of all
if(bmp != null){
bmp.recycle();
bmp = null;
@ -76,47 +89,31 @@ public class OsmandRenderer {
}
protected void draw(MapRenderObject obj, Canvas canvas, double leftTileX, double topTileY, float zoom, float rotate) {
float xText = -1;
float yText = -1;
Path path = null;
if (obj.isPoint()) {
float x = (float) ((MapUtils.getTileNumberX(zoom, obj.getPointLongitude(0)) - leftTileX) * 256f);
float y = (float) ((MapUtils.getTileNumberY(zoom, obj.getPointLatitude(0)) - topTileY) * 256f);
// xText = x;
// yText = y;
canvas.drawCircle(x, y, 6, paintFill);
protected void draw(MapRenderObject obj, Canvas canvas, double leftTileX, double topTileY, int zoom, float rotate) {
if(obj.isPoint()){
drawPoint(obj, canvas, leftTileX, topTileY, zoom, rotate);
} else if(obj.isPolyLine() && MapRenderingTypes.isHighway(obj.getType())){
drawHighway(obj, canvas, leftTileX, topTileY, zoom, rotate);
} else {
Paint paint;
float xText = 0;
float yText = 0;
Path path = null;
if(obj.isPolygon()){
paint = paintFill;
paint = paintFill;
// for buildings !
if(MapRenderingTypes.isPolygonBuilding(obj.getType())){
paint.setColor(Color.rgb(188, 169, 169));
} else {
paint.setColor(Color.GRAY);
paint.setColor(Color.rgb(188, 169, 169));
// paint.setColor(Color.GRAY);
}
} else {
paint = paintStroke;
if(MapRenderingTypes.isHighway(obj.getType())){
int hwType = MapRenderingTypes.getHighwayType(obj.getType());
if(hwType == MapRenderingTypes.PL_HW_MOTORWAY || hwType == MapRenderingTypes.PL_HW_TRUNK){
paint.setColor(Color.BLUE);
} else if(hwType == MapRenderingTypes.PL_HW_PRIMARY){
paint.setColor(Color.rgb(235, 152, 154));
} else if(hwType == MapRenderingTypes.PL_HW_SECONDARY){
paint.setColor(Color.rgb(253, 214, 164));
} else {
paint.setColor(Color.WHITE);
}
paint.setStrokeWidth(5);
} else {
paint.setStrokeWidth(2);
paint.setColor(Color.DKGRAY);
}
paint.setStrokeWidth(2);
paint.setColor(Color.DKGRAY);
}
for (int i = 0; i < obj.getPointsLength(); i++) {
float x = (float) ((MapUtils.getTileNumberX(zoom, obj.getPointLongitude(i)) - leftTileX) * 256f);
float y = (float) ((MapUtils.getTileNumberY(zoom, obj.getPointLatitude(i)) - topTileY) * 256f);
@ -129,29 +126,116 @@ public class OsmandRenderer {
path.lineTo(x, y);
}
}
if (path != null) {
xText /= obj.getPointsLength();
yText /= obj.getPointsLength();
canvas.drawPath(path, paint);
if(obj.getName() != null){
canvas.drawText(obj.getName(), xText, yText, paintText);
}
}
}
if(obj.getName() != null && xText > 0 && yText > 0){
if(obj.isPolyLine()){
canvas.drawTextOnPath(obj.getName(), path, 0, 0, paintText);
}
public void drawPoint(MapRenderObject obj, Canvas canvas, double leftTileX, double topTileY, int zoom, float rotate){
if (zoom > 15) {
// float x = (float) ((MapUtils.getTileNumberX(zoom, obj.getPointLongitude(0)) - leftTileX) * 256f);
// float y = (float) ((MapUtils.getTileNumberY(zoom, obj.getPointLatitude(0)) - topTileY) * 256f);
// canvas.drawCircle(x, y, 6, paintFill);
}
}
public void drawHighway(MapRenderObject obj, Canvas canvas, double leftTileX, double topTileY, int zoom, float rotate) {
if(obj.getPointsLength() == 0){
return;
}
float xText = 0;
float yText = 0;
Path path = null;
float pathRotate = 0;
float xLength = 0;
float yLength = 0;
Paint paint = paintStroke;
int hwType = MapRenderingTypes.getHighwayType(obj.getType());
if (hwType == MapRenderingTypes.PL_HW_MOTORWAY || hwType == MapRenderingTypes.PL_HW_TRUNK) {
paint.setColor(Color.BLUE);
} else if (hwType == MapRenderingTypes.PL_HW_PRIMARY) {
paint.setColor(Color.rgb(235, 152, 154));
} else if (hwType == MapRenderingTypes.PL_HW_SECONDARY) {
paint.setColor(Color.rgb(253, 214, 164));
} else if (hwType == MapRenderingTypes.PL_HW_SERVICE || hwType == MapRenderingTypes.PL_HW_UNCLASSIFIED
|| hwType == MapRenderingTypes.PL_HW_TERTIARY || hwType == MapRenderingTypes.PL_HW_RESIDENTIAL) {
paint.setColor(Color.WHITE);
} else {
// skip for now
return;
}
if (zoom < 16) {
paint.setStrokeWidth(6);
} else if (zoom == 16) {
paint.setStrokeWidth(7);
} else if (zoom == 17) {
paint.setStrokeWidth(11);
} else if (zoom >= 18) {
paint.setStrokeWidth(16);
}
float xPrev = 0;
float yPrev = 0;
int middle = obj.getPointsLength() / 2;
for (int i = 0; i < obj.getPointsLength(); i++) {
float x = (float) ((MapUtils.getTileNumberX(zoom, obj.getPointLongitude(i)) - leftTileX) * 256f);
float y = (float) ((MapUtils.getTileNumberY(zoom, obj.getPointLatitude(i)) - topTileY) * 256f);
// xText += x;
// yText += y;
if (path == null) {
path = new Path();
path.moveTo(x, y);
} else {
canvas.drawText(obj.getName(), xText, yText, paintText);
if (xPrev > 0) {
xLength += x - xPrev; // not abs
yLength += y - yPrev; // not abs
}
if(i == middle){
double rot = -Math.atan2(x - xPrev, y - yPrev) * 180 / Math.PI + 90;
if (rot < 0) {
rot += 360;
}
if (rot < 270 && rot > 90) {
rot += 180;
}
pathRotate = (float) rot;
xText = (x + xPrev) / 2;
yText = (y + yPrev) / 2;
}
if (pathRotate == 0) {
}
path.lineTo(x, y);
}
xPrev = x;
yPrev = y;
}
if (path != null) {
// xText /= obj.getPointsLength();
// yText /= obj.getPointsLength();
canvas.drawPath(path, paint);
if (obj.getName() != null) {
if (paintText.measureText(obj.getName()) < Math.max(Math.abs(xLength), Math.abs(yLength))) {
int sv = canvas.save();
canvas.rotate(pathRotate, xText, yText);
canvas.drawText(obj.getName(), xText, yText, paintText);
canvas.restoreToCount(sv);
}
}
}
}
public Bitmap getBitmap(){
return bmp;
}
public synchronized void clearBitmap(){
if(bmp != null){
bmp.recycle();
}
bmp = null;
}
}

View file

@ -363,10 +363,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
private void drawOverMap(Canvas canvas){
int w = getCenterPointX();
int h = getCenterPointY();
if (showMapPosition) {
canvas.drawCircle(w, h, 3 * dm.density, paintCenter);
canvas.drawCircle(w, h, 7 * dm.density, paintCenter);
}
canvas.restore();
// create local copy
ArrayList<OsmandMapLayer> local = new ArrayList<OsmandMapLayer>(layers);
@ -378,6 +374,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
layer.onDraw(canvas);
canvas.restore();
}
if (showMapPosition) {
canvas.drawCircle(w, h, 3 * dm.density, paintCenter);
canvas.drawCircle(w, h, 7 * dm.density, paintCenter);
}
}
public void calculateTileRectangle(Rect pixRect, float cx, float cy, float ctilex, float ctiley, RectF tileRect){