diff --git a/DataExtractionOSM/src/net/osmand/osm/MapRenderingTypes.java b/DataExtractionOSM/src/net/osmand/osm/MapRenderingTypes.java index b036aeceae..869f2e4234 100644 --- a/DataExtractionOSM/src/net/osmand/osm/MapRenderingTypes.java +++ b/DataExtractionOSM/src/net/osmand/osm/MapRenderingTypes.java @@ -54,11 +54,10 @@ public class MapRenderingTypes { // TODO place text : (ref - shield) // TODO coastline - // TODO render : bridge (common way), tunnel, hw, railway : construction, proposed - public final static int HIGHWAY = 1; //TODO REVIEW,traffic + public final static int HIGHWAY = 1; public final static int BARRIER = 2; public final static int WATERWAY = 3; - public final static int RAILWAY = 4;//TODO RENDER + public final static int RAILWAY = 4; public final static int AEROWAY = 5; public final static int AERIALWAY = 6; public final static int POWER = 7; diff --git a/OsmAnd/src/net/osmand/render/OsmandRenderer.java b/OsmAnd/src/net/osmand/render/OsmandRenderer.java index 2cc38ef600..fd496f4f8c 100644 --- a/OsmAnd/src/net/osmand/render/OsmandRenderer.java +++ b/OsmAnd/src/net/osmand/render/OsmandRenderer.java @@ -30,6 +30,7 @@ import android.graphics.RectF; import android.graphics.Shader; import android.graphics.Bitmap.Config; import android.graphics.Paint.Align; +import android.graphics.Paint.Cap; import android.graphics.Paint.Style; import android.graphics.Shader.TileMode; import android.text.TextPaint; @@ -38,20 +39,14 @@ import android.util.FloatMath; public class OsmandRenderer implements Comparator { private static final Log log = LogUtil.getLog(OsmandRenderer.class); - private Paint paintStroke; private TextPaint paintText; - private Paint paintFill; + private Paint paint; private Paint paintFillEmpty; private Paint paintIcon; /// Colors private int clFillScreen = Color.rgb(241, 238, 232); - - private PathEffect arrowDashEffect1 = new DashPathEffect(new float[] { 0, 12, 10, 152 }, 0); - private PathEffect arrowDashEffect2 = new DashPathEffect(new float[] { 0, 12, 9, 153 }, 1); - private PathEffect arrowDashEffect3 = new DashPathEffect(new float[] { 0, 18, 2, 154 }, 1); - private PathEffect arrowDashEffect4 = new DashPathEffect(new float[] { 0, 18, 1, 155 }, 1); private Map dashEffect = new LinkedHashMap(); private Map shaders = new LinkedHashMap(); @@ -99,35 +94,65 @@ public class OsmandRenderer implements Comparator { // use to calculate points PointF tempPoint = new PointF(); + - // use to set rendering properties - int color = Color.BLACK; // polyline props boolean showText = true; - PathEffect pathEffect = null; - int shadowLayer = 0; - int shadowColor = 0; - float strokeWidth = 0; - float secondStrokeWidth = 0; - int secondColor = 0; - PathEffect secondEffect = null; + RenderingPaintProperties main = new RenderingPaintProperties(); + RenderingPaintProperties second = new RenderingPaintProperties(); + RenderingPaintProperties third = new RenderingPaintProperties(); + RenderingPaintProperties[] adds = null; - // polygon props - boolean showPolygon = true; - int colorAround = 0; - int widthAround = 1; - Shader shader = null; + } + + /* package*/ static class RenderingPaintProperties { + int color; + float strokeWidth; + int shadowLayer; + int shadowColor; + boolean fillArea; + PathEffect pathEffect; + Shader shader; + Cap cap; + public void emptyLine(){ + color = 0; + strokeWidth = 0; + cap = Cap.BUTT; + pathEffect = null; + fillArea = false; + shader = null; + shadowColor = 0; + shadowLayer = 0; + } + + public void updatePaint(Paint p){ + p.setStyle(fillArea ? Style.FILL_AND_STROKE : Style.STROKE); + p.setColor(color); + p.setShader(shader); + p.setShadowLayer(shadowLayer, 0, 0, shadowColor); + if (!fillArea) { + p.setStrokeCap(cap); + p.setPathEffect(pathEffect); + p.setStrokeWidth(strokeWidth); + } + } + + public void emptyArea(){ + color = 0; + strokeWidth = 0; + cap = Cap.BUTT; + fillArea = false; + shader = null; + pathEffect = null; + shadowColor = 0; + shadowLayer = 0; + } } public OsmandRenderer(Context context){ this.context = context; - paintStroke = new Paint(); - paintStroke.setStyle(Style.STROKE); - paintStroke.setStrokeWidth(2); - paintStroke.setColor(Color.BLACK); - paintStroke.setAntiAlias(true); paintIcon = new Paint(); paintIcon.setStyle(Style.STROKE); @@ -138,11 +163,8 @@ public class OsmandRenderer implements Comparator { paintText.setTextAlign(Align.CENTER); paintText.setAntiAlias(true); - paintFill = new Paint(); - paintFill.setStyle(Style.FILL_AND_STROKE); - paintFill.setStrokeWidth(2); - paintFill.setColor(Color.LTGRAY); - paintFill.setAntiAlias(true); + paint = new Paint(); + paint.setAntiAlias(true); paintFillEmpty = new Paint(); paintFillEmpty.setStyle(Style.FILL); @@ -304,28 +326,23 @@ public class OsmandRenderer implements Comparator { return rc.tempPoint; } - - private PointF drawPolygon(MapRenderObject obj, Canvas canvas, RenderingContext rc) { - Paint paint = paintFill; float xText = 0; float yText = 0; int zoom = rc.zoom; Path path = null; int type = MapRenderingTypes.getObjectType(obj.getType()); int subtype = MapRenderingTypes.getPolygonSubType(obj.getType()); - rc.color = Color.rgb(245, 245, 245); - rc.shader = null; - rc.colorAround = 0; - rc.showPolygon = true; + rc.main.emptyArea(); + rc.second.emptyLine(); + rc.main.color = Color.rgb(245, 245, 245); PolygonRenderer.renderPolygon(rc, zoom, type, subtype, this); - if(!rc.showPolygon){ + if(!rc.main.fillArea){ return null; } - paint.setColor(rc.color); for (int i = 0; i < obj.getPointsLength(); i++) { PointF p = calcPoint(obj, i, rc); xText += p.x; @@ -341,13 +358,11 @@ public class OsmandRenderer implements Comparator { if (path != null) { xText /= obj.getPointsLength(); yText /= obj.getPointsLength(); - paint.setShader(rc.shader); + rc.main.updatePaint(paint); canvas.drawPath(path, paint); - if(rc.colorAround != 0){ - paintStroke.setPathEffect(null); - paintStroke.setColor(rc.colorAround); - paintStroke.setStrokeWidth(1); - canvas.drawPath(path, paintStroke); + if(rc.second.strokeWidth != 0){ + rc.second.updatePaint(paint); + canvas.drawPath(path, paint); } String name = obj.getName(); if(name != null){ @@ -490,9 +505,13 @@ public class OsmandRenderer implements Comparator { private void drawPolyline(MapRenderObject obj, Canvas canvas, RenderingContext rc) { int type = MapRenderingTypes.getObjectType(obj.getType()); int subtype = MapRenderingTypes.getPolylineSubType(obj.getType()); + rc.main.emptyLine(); + rc.second.emptyLine(); + rc.third.emptyLine(); + rc.adds = null; PolylineRenderer.renderPolyline(type, subtype, obj.getType(), rc, this); - if(rc.strokeWidth == 0){ + if(rc.main.strokeWidth == 0){ return; } int length = obj.getPointsLength(); @@ -539,32 +558,24 @@ public class OsmandRenderer implements Comparator { yPrev = p.y; } if (path != null) { - paintStroke.setPathEffect(rc.pathEffect); - if(paintStroke.getShader() != null){ - paintStroke.setShader(null); - } - paintStroke.setShadowLayer(rc.shadowLayer, 0, 0, rc.shadowColor); - paintStroke.setColor(rc.color); - paintStroke.setStrokeWidth(rc.strokeWidth); - canvas.drawPath(path, paintStroke); - if (rc.secondStrokeWidth > 0) { - paintStroke.setPathEffect(rc.secondEffect); - paintStroke.setShader(null); - if (rc.shadowLayer != 0) { - paintStroke.setShadowLayer(0, 0, 0, 0); + rc.main.updatePaint(paint); + canvas.drawPath(path, paint); + if (rc.second.strokeWidth != 0) { + rc.second.updatePaint(paint); + canvas.drawPath(path, paint); + if (rc.third.strokeWidth != 0) { + rc.third.updatePaint(paint); + canvas.drawPath(path, paint); } - paintStroke.setColor(rc.secondColor); - paintStroke.setStrokeWidth(rc.secondStrokeWidth); - canvas.drawPath(path, paintStroke); } - if(type == MapRenderingTypes.HIGHWAY && rc.zoom >= 16 && MapRenderingTypes.isOneWayWay(obj.getType())){ - if (rc.shadowLayer != 0) { - paintStroke.setShadowLayer(0, 0, 0, 0); + if (rc.adds != null) { + for (int i = 0; i < rc.adds.length; i++) { + rc.adds[i].updatePaint(paint); + canvas.drawPath(path, paint); } - drawOneWayDirections(canvas, path); } if (obj.getName() != null && rc.showText) { - float w = rc.strokeWidth + 3; + float w = rc.main.strokeWidth + 3; if(w < 10){ w = 10; } @@ -592,33 +603,13 @@ public class OsmandRenderer implements Comparator { text.drawOnPath = path; text.textColor = Color.BLACK; text.textSize = w; - text.vOffset = rc.strokeWidth / 2 - 1; + text.vOffset = rc.main.strokeWidth / 2 - 1; rc.textToDraw.add(text); } } } } - public void drawOneWayDirections(Canvas canvas, Path path){ - paintStroke.setColor(0xff6c70d5); - - paintStroke.setStrokeWidth(1); - paintStroke.setPathEffect(arrowDashEffect1); - canvas.drawPath(path, paintStroke); - - paintStroke.setStrokeWidth(2); - paintStroke.setPathEffect(arrowDashEffect2); - canvas.drawPath(path, paintStroke); - - paintStroke.setStrokeWidth(3); - paintStroke.setPathEffect(arrowDashEffect3); - canvas.drawPath(path, paintStroke); - - paintStroke.setStrokeWidth(4); - paintStroke.setPathEffect(arrowDashEffect4); - canvas.drawPath(path, paintStroke); - } - } diff --git a/OsmAnd/src/net/osmand/render/PointRenderer.java b/OsmAnd/src/net/osmand/render/PointRenderer.java index 3f4cf4222a..27435b7c93 100644 --- a/OsmAnd/src/net/osmand/render/PointRenderer.java +++ b/OsmAnd/src/net/osmand/render/PointRenderer.java @@ -10,70 +10,81 @@ public class PointRenderer { */ public static int getPointBitmap(int zoom, int type, int subType) { int resId = 0; - if(type == MapRenderingTypes.HIGHWAY){ + switch (type) { + case MapRenderingTypes.HIGHWAY: { if (zoom >= 16) { - if(subType == 38){ - if(zoom > 16){ + if (subType == 38) { + if (zoom > 16) { resId = R.drawable.h_traffic_light; } - } else if(subType == 40){ + } else if (subType == 40) { resId = zoom == 16 ? R.drawable.h_bus_stop_small : R.drawable.h_bus_stop; - } else if(subType == 23){ + } else if (subType == 23) { resId = R.drawable.h_transport_ford; } - } - if(subType == 35){ - if(zoom >= 15){ + } + if (subType == 35) { + if (zoom >= 15) { resId = R.drawable.h_mini_round; } } - } else if(type == MapRenderingTypes.RAILWAY){ - if(subType == 13){ - if(zoom == 12){ + } + break; + case MapRenderingTypes.RAILWAY: { + if (subType == 13) { + if (zoom == 12) { resId = R.drawable.h_halt; - } else if(zoom == 13 || zoom == 14){ + } else if (zoom == 13 || zoom == 14) { resId = R.drawable.h_station_small; - } else if(zoom >= 15){ + } else if (zoom >= 15) { resId = R.drawable.h_station; } - } else if(subType == 22 || subType == 23){ - if(zoom == 13 || zoom == 14){ + } else if (subType == 22 || subType == 23) { + if (zoom == 13 || zoom == 14) { resId = R.drawable.h_halt; - } else if(zoom >= 15){ + } else if (zoom >= 15) { resId = R.drawable.h_station_small; } - } else if(subType == 25){ - if(zoom == 14 || zoom == 15){ + } else if (subType == 25) { + if (zoom == 14 || zoom == 15) { resId = R.drawable.h_level_crossing; - } else if(zoom >= 16){ + } else if (zoom >= 16) { resId = R.drawable.h_level_crossing2; } } - } else if(type == MapRenderingTypes.AEROWAY){ - if(subType == 1){ - if(zoom >= 10 && zoom <= 14){ + } + break; + case MapRenderingTypes.AEROWAY: { + if (subType == 1) { + if (zoom >= 10 && zoom <= 14) { resId = R.drawable.h_aerodrome; } - } else if(subType == 10){ - if(zoom >= 9 && zoom <= 13){ + } else if (subType == 10) { + if (zoom >= 9 && zoom <= 13) { resId = R.drawable.h_airport; } } - } else if(type == MapRenderingTypes.WATERWAY){ - if(subType == 8){ + } + break; + case MapRenderingTypes.WATERWAY: { + if (subType == 8) { if (zoom > 14) { resId = R.drawable.h_lock_gate; } } - } else if(type == MapRenderingTypes.AERIALWAY){ - if(subType == 7){ - if(zoom == 13 || zoom == 14){ + } + break; + case MapRenderingTypes.AERIALWAY: { + if (subType == 7) { + if (zoom == 13 || zoom == 14) { resId = R.drawable.h_halt; - } else if(zoom >= 15){ + } else if (zoom >= 15) { resId = R.drawable.h_station_small; } } - } else if(type == MapRenderingTypes.POWER){ + } + break; + case MapRenderingTypes.POWER: { if (zoom > 14) { if (subType == 1) { resId = R.drawable.h_power_tower; @@ -81,7 +92,9 @@ public class PointRenderer { resId = R.drawable.h_power_wind; } } - } else if (type == MapRenderingTypes.MAN_MADE) { + } + break; + case MapRenderingTypes.MAN_MADE: { if (subType == 25) { if (zoom >= 16) { resId = R.drawable.h_tower_water; @@ -95,7 +108,9 @@ public class PointRenderer { resId = R.drawable.h_windmill; } } - } else if(type == MapRenderingTypes.SHOP){ + } + break; + case MapRenderingTypes.SHOP: { if (zoom > 15) { switch (subType) { case 27: @@ -128,11 +143,12 @@ public class PointRenderer { case 16: resId = R.drawable.h_shop_convenience; break; - - + } } - } else if(type == MapRenderingTypes.TOURISM){ + } + break; + case MapRenderingTypes.TOURISM: { if (zoom > 15) { switch (subType) { case 4: @@ -166,27 +182,31 @@ public class PointRenderer { break; } } - } else if(type == MapRenderingTypes.NATURAL){ + } + break; + case MapRenderingTypes.NATURAL: { if (subType == 13) { if (zoom > 10) { resId = R.drawable.h_peak; } - } else if(subType == 3){ + } else if (subType == 3) { if (zoom > 14) { resId = R.drawable.h_cave_entrance; } - } else if(subType == 17){ + } else if (subType == 17) { if (zoom >= 14) { resId = R.drawable.h_spring; } - } else if(subType == 19){ + } else if (subType == 19) { if (zoom == 16) { resId = R.drawable.h_tree; } else if (zoom >= 17) { resId = R.drawable.h_tree2; } } - } else if(type == MapRenderingTypes.HISTORIC){ + } + break; + case MapRenderingTypes.HISTORIC: { if (zoom > 15) { if (subType == 6) { resId = R.drawable.h_memorial; @@ -194,31 +214,37 @@ public class PointRenderer { // something historic resId = R.drawable.h_view_point; } - + } - } else if(type == MapRenderingTypes.BARRIER){ - if(subType == 21){ - if(zoom >= 15){ + } + break; + case MapRenderingTypes.BARRIER: { + if (subType == 21) { + if (zoom >= 15) { resId = R.drawable.h_gate2; - } - } else if(subType == 22){ - if(zoom >= 16){ + } + } else if (subType == 22) { + if (zoom >= 16) { resId = R.drawable.h_liftgate; - } - } else if(subType == 26){ - if(zoom >= 16){ + } + } else if (subType == 26) { + if (zoom >= 16) { resId = R.drawable.h_bollard; - } + } } - } else if(type == MapRenderingTypes.EMERGENCY){ - if(zoom > 15){ - if(subType == 10){ + } + break; + case MapRenderingTypes.EMERGENCY: { + if (zoom > 15) { + if (subType == 10) { resId = R.drawable.h_firestation; - } else if(subType == 7){ + } else if (subType == 7) { resId = R.drawable.h_sosphone; } } - } else if(type == MapRenderingTypes.AMENITY_SUSTENANCE){ + } + break; + case MapRenderingTypes.AMENITY_SUSTENANCE: { if (zoom > 15) { switch (subType) { case 1: @@ -242,37 +268,43 @@ public class PointRenderer { break; } } - } else if(type == MapRenderingTypes.AMENITY_EDUCATION){ - if (zoom > 15){ - if(subType == 2){ + } + break; + case MapRenderingTypes.AMENITY_EDUCATION: { + if (zoom > 15) { + if (subType == 2) { resId = R.drawable.h_school; - } else if(subType == 4){ + } else if (subType == 4) { resId = R.drawable.h_library; } } - } else if (type == MapRenderingTypes.AMENITY_TRANSPORTATION) { + } + break; + case MapRenderingTypes.AMENITY_TRANSPORTATION: { if (subType == 1 || subType == 2) { if (zoom > 14) { resId = R.drawable.h_parking; } } else if (subType == 4) { - if(zoom > 13){ + if (zoom > 13) { resId = R.drawable.h_fuel; } } else if (subType == 17) { - if(zoom >= 17){ + if (zoom >= 17) { resId = R.drawable.h_rental_bicycle; } } else if (subType == 20) { - if(zoom >= 16){ + if (zoom >= 16) { resId = R.drawable.h_car_share; } } else if (subType == 18) { - if(zoom > 14){ + if (zoom > 14) { resId = R.drawable.h_bus_station; } } - } else if (type == MapRenderingTypes.AMENITY_FINANCE) { + } + break; + case MapRenderingTypes.AMENITY_FINANCE: { if (subType == 1) { if (zoom > 16) { resId = R.drawable.h_atm; @@ -282,25 +314,31 @@ public class PointRenderer { resId = R.drawable.h_bank; } } - } else if (type == MapRenderingTypes.AMENITY_HEALTHCARE) { + } + break; + case MapRenderingTypes.AMENITY_HEALTHCARE: { if (subType == 1) { if (zoom > 15) { resId = R.drawable.h_pharmacy; } } else if (subType == 2) { - if(zoom >= 15){ + if (zoom >= 15) { resId = R.drawable.h_hospital; } } - } else if (type == MapRenderingTypes.AMENITY_ENTERTAINMENT) { + } + break; + case MapRenderingTypes.AMENITY_ENTERTAINMENT: { if (zoom >= 15) { if (subType == 3) { resId = R.drawable.h_cinema; - } else if(subType == 9) { + } else if (subType == 9) { resId = R.drawable.h_theatre; } } - } else if(type == MapRenderingTypes.AMENITY_OTHER){ + } + break; + case MapRenderingTypes.AMENITY_OTHER: { if (zoom > 16) { switch (subType) { case 10: @@ -332,14 +370,15 @@ public class PointRenderer { break; } } - if(zoom >= 16){ - if(subType == 26){ + if (zoom >= 16) { + if (subType == 26) { resId = R.drawable.h_place_of_worship; - } else if(subType == 13){ + } else if (subType == 13) { resId = R.drawable.h_prison; } } } + } return resId; } } diff --git a/OsmAnd/src/net/osmand/render/PolygonRenderer.java b/OsmAnd/src/net/osmand/render/PolygonRenderer.java index dcec90eb3f..8cf89cb4c2 100644 --- a/OsmAnd/src/net/osmand/render/PolygonRenderer.java +++ b/OsmAnd/src/net/osmand/render/PolygonRenderer.java @@ -11,293 +11,298 @@ public class PolygonRenderer { if (type == MapRenderingTypes.HIGHWAY) { if (subtype == MapRenderingTypes.PL_HW_SERVICE || subtype == MapRenderingTypes.PL_HW_UNCLASSIFIED || subtype == MapRenderingTypes.PL_HW_RESIDENTIAL) { - rc.colorAround = Color.rgb(194, 194, 194); - rc.color = Color.WHITE; + rc.second.color = Color.rgb(194, 194, 194); + rc.second.strokeWidth = 1; + rc.main.color= Color.WHITE; } else if(subtype == MapRenderingTypes.PL_HW_PEDESTRIAN || subtype == MapRenderingTypes.PL_HW_FOOTWAY){ - rc.color = Color.rgb(236, 236, 236); - rc.colorAround = Color.rgb(176, 176, 176); + rc.main.color = Color.rgb(236, 236, 236); + rc.second.color = Color.rgb(176, 176, 176); + rc.second.strokeWidth = 1; } } else if (type == MapRenderingTypes.RAILWAY) { if(subtype == 13){ - rc.showPolygon = zoom >= 13; - rc.color = 0xffd4aaaa; + rc.main.fillArea = zoom >= 13; + rc.main.color = 0xffd4aaaa; } } else if (type == MapRenderingTypes.WATERWAY) { if(subtype == 3){ - rc.showPolygon = zoom >= 7; - rc.color = 0xffb5d0d0; + rc.main.fillArea = zoom >= 7; + rc.main.color = 0xffb5d0d0; } else if(subtype == 4 || subtype == 7 || subtype == 13){ - rc.showPolygon = zoom >= 10; - rc.color = 0xffb5d0d0; + rc.main.fillArea = zoom >= 10; + rc.main.color = 0xffb5d0d0; } } else if (type == MapRenderingTypes.AEROWAY) { if(subtype == 1 || subtype == 10){ - rc.showPolygon = zoom >= 12; - rc.color = 0x80cccccc; + rc.main.fillArea = zoom >= 12; + rc.main.color = 0x80cccccc; } else if(subtype == 2){ - rc.showPolygon = zoom >= 15; - rc.color = 0xffcc99ff; + rc.main.fillArea = zoom >= 15; + rc.main.color = 0xffcc99ff; } else if(subtype == 9){ // apron - rc.showPolygon = zoom >= 13; - rc.color = 0xffe9d1ff; + rc.main.fillArea = zoom >= 13; + rc.main.color = 0xffe9d1ff; } } else if (type == MapRenderingTypes.POWER) { if(subtype == 5 || subtype == 6){ - rc.showPolygon = zoom >= 13; - rc.color = 0xffbbbbbb; + rc.main.fillArea = zoom >= 13; + rc.main.color = 0xffbbbbbb; } } else if (type == MapRenderingTypes.MAN_MADE) { - rc.showPolygon = zoom > 15; + rc.main.fillArea = zoom > 15; if (subtype == MapRenderingTypes.SUBTYPE_BUILDING) { - rc.color = Color.rgb(188, 169, 169); + rc.main.color = Color.rgb(188, 169, 169); } else if (subtype == MapRenderingTypes.SUBTYPE_GARAGES) { - rc.color = Color.rgb(221, 221, 221); + rc.main.color = Color.rgb(221, 221, 221); } } else if (type == MapRenderingTypes.TOURISM) { if (subtype == 2 || subtype == 7) { - rc.showPolygon = zoom >= 13; - rc.color = 0xfff2caea; + rc.main.fillArea = zoom >= 13; + rc.main.color = 0xfff2caea; if(subtype == 7){ - rc.colorAround = 0xff734a08; - rc.pathEffect = o.getDashEffect("9_3"); //$NON-NLS-1$ + rc.second.color = 0xff734a08; + rc.second.pathEffect = o.getDashEffect("9_3"); //$NON-NLS-1$ if(zoom <= 15){ - rc.strokeWidth = 1; + rc.second.strokeWidth = 1; } else { - rc.strokeWidth = 2; + rc.second.strokeWidth = 2; } } } else if(subtype >= 4 && subtype <= 6){ - rc.showPolygon = zoom >= 15; - rc.color = 0xa0ccff99; + rc.main.fillArea = zoom >= 15; + rc.main.color = 0xa0ccff99; } else if(subtype == 8){ - rc.showPolygon = zoom >= 13; - rc.shader = o.getShader(R.drawable.h_zoo); + rc.main.fillArea = zoom >= 13; + rc.main.shader = o.getShader(R.drawable.h_zoo); } } else if (type == MapRenderingTypes.NATURAL) { switch(subtype){ case 2 : - rc.showPolygon = zoom >= 13; - rc.shader = o.getShader(R.drawable.h_beach); + rc.main.fillArea = zoom >= 13; + rc.main.shader = o.getShader(R.drawable.h_beach); case 5: // TODO coastline break; case 7: - rc.showPolygon = zoom >= 8; - rc.shader = o.getShader(R.drawable.h_glacier); + rc.main.fillArea = zoom >= 8; + rc.main.shader = o.getShader(R.drawable.h_glacier); if(zoom >= 10){ - rc.colorAround = 0xff99ccff; - rc.widthAround = 2; + rc.second.color = 0xff99ccff; + rc.second.strokeWidth = 2; } break; case 8: - rc.showPolygon = zoom >= 10; - rc.color = 0xffffffc0; + rc.main.fillArea = zoom >= 10; + rc.main.color = 0xffffffc0; break; case 9: - rc.showPolygon = zoom >= 11; - rc.color = 0xfff2efe9; + rc.main.fillArea = zoom >= 11; + rc.main.color = 0xfff2efe9; break; case 11: case 22: - rc.showPolygon = zoom >= 13; - rc.shader = o.getShader(R.drawable.h_marsh); + rc.main.fillArea = zoom >= 13; + rc.main.shader = o.getShader(R.drawable.h_marsh); break; case 12 : - rc.showPolygon = zoom >= 13; - rc.shader = o.getShader(R.drawable.h_mud); + rc.main.fillArea = zoom >= 13; + rc.main.shader = o.getShader(R.drawable.h_mud); break; case 16 : - rc.showPolygon = zoom >= 13; - rc.shader = o.getShader(R.drawable.h_scrub); + rc.main.fillArea = zoom >= 13; + rc.main.shader = o.getShader(R.drawable.h_scrub); break; case 21: - rc.showPolygon = zoom >= 7; - rc.color = 0xffb5d0d0; + rc.main.fillArea = zoom >= 7; + rc.main.color = 0xffb5d0d0; break; case 23 : - rc.showPolygon = zoom >= 8; - rc.color = 0xffaed1a0; + rc.main.fillArea = zoom >= 8; + rc.main.color = 0xffaed1a0; break; } } else if (type == MapRenderingTypes.LANDUSE) { switch (subtype) { case 1: - rc.showPolygon = zoom >= 13; - rc.color = 0xffc8b084; + rc.main.fillArea = zoom >= 13; + rc.main.color = 0xffc8b084; break; case 2: - rc.showPolygon = zoom >= 10; - rc.color = 0xffb5d0d0; + rc.main.fillArea = zoom >= 10; + rc.main.color = 0xffb5d0d0; break; case 4: - rc.showPolygon = zoom >= 12; + rc.main.fillArea = zoom >= 12; if(zoom >= 12 && zoom <= 14){ - rc.color = 0xffaacbaf; + rc.main.color = 0xffaacbaf; } else if (zoom > 14) { - rc.shader = o.getShader(R.drawable.h_grave_yard); + rc.main.shader = o.getShader(R.drawable.h_grave_yard); } break; case 5: - rc.showPolygon = zoom >= 12; - rc.color = 0xffefc8c8; + rc.main.fillArea = zoom >= 12; + rc.main.color = 0xffefc8c8; break; case 3: case 6: case 13: case 16: - rc.showPolygon = zoom >= 12; - rc.color = 0xff9d9d6c; + rc.main.fillArea = zoom >= 12; + rc.main.color = 0xff9d9d6c; break; case 7: - rc.showPolygon = zoom >= 11; - rc.color = 0xffead8bd; + rc.main.fillArea = zoom >= 11; + rc.main.color = 0xffead8bd; break; case 9: - rc.showPolygon = zoom >= 11; - rc.color = 0xffddbf92; + rc.main.fillArea = zoom >= 11; + rc.main.color = 0xffddbf92; break; case 10: if(zoom < 8){ - rc.showPolygon = false; + rc.main.fillArea = false; } else if(zoom <= 13){ - rc.color = 0xff8dc56c; + rc.main.color = 0xff8dc56c; } else { - rc.shader = o.getShader(R.drawable.h_forest); + rc.main.shader = o.getShader(R.drawable.h_forest); } break; case 11 : - rc.color = Color.rgb(223, 209, 214); + rc.main.color = Color.rgb(223, 209, 214); break; case 12: case 17: - rc.showPolygon = zoom >= 12; - rc.color = 0xffcfeca8; + rc.main.fillArea = zoom >= 12; + rc.main.color = 0xffcfeca8; break; case 15: case 20: - rc.color = 0xffdfd1d6; - rc.showPolygon = zoom >= 12; + rc.main.color = 0xffdfd1d6; + rc.main.fillArea = zoom >= 12; break; case 18: - rc.showPolygon = zoom >= 12; - rc.color = 0xa0ffa8a8; + rc.main.fillArea = zoom >= 12; + rc.main.color = 0xa0ffa8a8; break; case 19: - rc.showPolygon = zoom >= 10; - rc.shader = o.getShader(R.drawable.h_orchard); + rc.main.fillArea = zoom >= 10; + rc.main.shader = o.getShader(R.drawable.h_orchard); break; case 21: - rc.color = 0xffcfeca8; - rc.showPolygon = zoom >= 12; + rc.main.color = 0xffcfeca8; + rc.main.fillArea = zoom >= 12; break; case 22 : - rc.showPolygon = zoom >= 7; - rc.color = 0xffb5d0d0; + rc.main.fillArea = zoom >= 7; + rc.main.color = 0xffb5d0d0; break; case 23: - rc.showPolygon = zoom >= 12; - rc.color = 0xffdddddd; + rc.main.fillArea = zoom >= 12; + rc.main.color = 0xffdddddd; break; case 24: - rc.showPolygon = zoom >= 12; - rc.color = 0xffcfeca8; + rc.main.fillArea = zoom >= 12; + rc.main.color = 0xffcfeca8; if(zoom >= 15){ - rc.colorAround = Color.RED; + rc.second.color = Color.RED; + rc.second.strokeWidth = 1; } break; case 26: - rc.showPolygon = zoom >= 13; - rc.shader = o.getShader(R.drawable.h_quarry2); + rc.main.fillArea = zoom >= 13; + rc.main.shader = o.getShader(R.drawable.h_quarry2); break; case 27: - rc.showPolygon = zoom >= 10; + rc.main.fillArea = zoom >= 10; if(zoom < 14){ - rc.color = 0xffabdf96; + rc.main.color = 0xffabdf96; } else { - rc.shader = o.getShader(R.drawable.h_vineyard); + rc.main.shader = o.getShader(R.drawable.h_vineyard); } break; } } else if (type == MapRenderingTypes.MILITARY) { if(subtype == 3){ - rc.showPolygon = zoom >= 13; - rc.color = 0xffff8f8f; + rc.main.fillArea = zoom >= 13; + rc.main.color = 0xffff8f8f; } else if(subtype == 4){ - rc.showPolygon = zoom >= 10; - rc.shader = o.getShader(R.drawable.h_danger); + rc.main.fillArea = zoom >= 10; + rc.main.shader = o.getShader(R.drawable.h_danger); } } else if (type == MapRenderingTypes.LEISURE) { switch (subtype) { case 2: case 4: - rc.showPolygon = zoom >= 13; - rc.color = 0xff33cc99; + rc.main.fillArea = zoom >= 13; + rc.main.color = 0xff33cc99; break; case 3: - rc.showPolygon = zoom >= 12; - rc.color = 0xffb5e3b5; + rc.main.fillArea = zoom >= 12; + rc.main.color = 0xffb5e3b5; break; case 5: - rc.showPolygon = zoom >= 12; - rc.colorAround = 0xff888888; - rc.widthAround = 1; - rc.color = 0xff74dcba; + rc.main.fillArea = zoom >= 12; + rc.second.color = 0xff888888; + rc.second.strokeWidth = 1; + rc.main.color = 0xff74dcba; break; case 6: - rc.color = 0xff8ad3af; - rc.showPolygon = zoom >= 13; - rc.colorAround = 0xff888888; - rc.widthAround = 1; + rc.main.color = 0xff8ad3af; + rc.main.fillArea = zoom >= 13; + rc.second.color = 0xff888888; + rc.second.strokeWidth = 1; break; case 11: if(zoom < 8){ - rc.showPolygon = false; + rc.main.fillArea = false; } else if(zoom >= 8 && zoom <= 12){ - rc.showPolygon = true; - rc.color = 0xffabdf96; + rc.main.fillArea = true; + rc.main.color = 0xffabdf96; } else { - rc.showPolygon = true; - rc.shader = o.getShader(R.drawable.h_nr); + rc.main.fillArea = true; + rc.main.shader = o.getShader(R.drawable.h_nr); } break; case 12: - rc.showPolygon = zoom >= 12; - rc.color = 0xb0b6fdb6; + rc.main.fillArea = zoom >= 12; + rc.main.color = 0xb0b6fdb6; break; case 13: - rc.color = 0xffccfff1; - rc.showPolygon = zoom >= 15; + rc.main.color = 0xffccfff1; + rc.main.fillArea = zoom >= 15; break; case 14: case 15: - rc.showPolygon = zoom >= 12; - rc.color = 0xffcfeca8; + rc.main.fillArea = zoom >= 12; + rc.main.color = 0xffcfeca8; break; } } else if (type == MapRenderingTypes.AMENITY_HEALTHCARE) { if (subtype == 2) { - rc.showPolygon = zoom >= 15; - rc.color = 0xfff0f0d8; - rc.colorAround = Color.rgb(212, 168, 158); + rc.main.fillArea = zoom >= 15; + rc.main.color = 0xfff0f0d8; + rc.second.color = Color.rgb(212, 168, 158); + rc.second.strokeWidth = 1; } } else if (type == MapRenderingTypes.AMENITY_TRANSPORTATION) { if (subtype == 1 || subtype == 2) { - rc.color = Color.rgb(246, 238, 183); + rc.main.color = Color.rgb(246, 238, 183); } } else if (type == MapRenderingTypes.AMENITY_ENTERTAINMENT) { if (subtype == 3) { - rc.color = Color.rgb(204, 153, 153); + rc.main.color = Color.rgb(204, 153, 153); } } else if (type == MapRenderingTypes.AMENITY_EDUCATION) { if(subtype == 1 || subtype == 2 || subtype == 3 || subtype == 5){ - rc.showPolygon = zoom >= 15; - rc.color = 0xfff0f0d8; - rc.colorAround = Color.rgb(212, 168, 158); + rc.main.fillArea = zoom >= 15; + rc.main.color = 0xfff0f0d8; + rc.second.color = Color.rgb(212, 168, 158); + rc.second.strokeWidth = 1; } else { // draw as building education - rc.color = Color.rgb(188, 169, 169); + rc.main.color = Color.rgb(188, 169, 169); } } } diff --git a/OsmAnd/src/net/osmand/render/PolylineRenderer.java b/OsmAnd/src/net/osmand/render/PolylineRenderer.java index e818970069..c88135f6bb 100644 --- a/OsmAnd/src/net/osmand/render/PolylineRenderer.java +++ b/OsmAnd/src/net/osmand/render/PolylineRenderer.java @@ -2,24 +2,24 @@ package net.osmand.render; import net.osmand.osm.MapRenderingTypes; import net.osmand.render.OsmandRenderer.RenderingContext; +import net.osmand.render.OsmandRenderer.RenderingPaintProperties; import android.graphics.Color; +import android.graphics.DashPathEffect; import android.graphics.PathEffect; +import android.graphics.Paint.Cap; public class PolylineRenderer { public static void renderPolyline(int type, int subtype, int objType, RenderingContext rc, OsmandRenderer o){ int zoom = rc.zoom; - int color = Color.BLACK; boolean showText = true; + + int color = Color.BLACK; PathEffect pathEffect = null; + float strokeWidth = zoom >= 15 ? 1 : 0; int shadowLayer = 0; int shadowColor = 0; - float strokeWidth = zoom >= 15 ? 1 : 0; - - float secondStrokeWidth = 0; - int secondColor = 0; - PathEffect secondEffect = null; switch (type) { case MapRenderingTypes.HIGHWAY: { @@ -111,9 +111,9 @@ public class PolylineRenderer { if (hwType == MapRenderingTypes.PL_HW_CONSTRUCTION || hwType == MapRenderingTypes.PL_HW_PROPOSED) { strokeWidth = zoom >= 15 ? (zoom == 15 ? 6 : 8) : 0; color = 0xff99cccc; - secondColor = Color.WHITE; - secondStrokeWidth = strokeWidth - 1; - secondEffect = o.getDashEffect("8_6"); //$NON-NLS-1$ + rc.second.color = Color.WHITE; + rc.second.strokeWidth = strokeWidth - 1; + rc.second.pathEffect = o.getDashEffect("8_6"); //$NON-NLS-1$ } else { if (hwType == MapRenderingTypes.PL_HW_TRACK) { strokeWidth = zoom >= 14 ? 2f : 0; @@ -166,12 +166,26 @@ public class PolylineRenderer { } } } - if(bridge && zoom > 12){ - if(secondStrokeWidth == 0){ - shadowLayer = 2; - shadowColor = Color.BLACK; + if(bridge && zoom > 14){ + if(rc.second.strokeWidth == 0){ + rc.second.color = color; + rc.second.strokeWidth = strokeWidth; + rc.second.pathEffect = pathEffect; + strokeWidth += 2; + color = Color.BLACK; + pathEffect = null; + if(rc.second.pathEffect == null){ + rc.second.cap = Cap.SQUARE; + } else { + color = 0x88ffffff; + } } } + if(type == MapRenderingTypes.HIGHWAY && rc.zoom >= 16 && MapRenderingTypes.isOneWayWay(objType)){ + rc.adds = getOneWayProperties(); + + } + if (tunnel && zoom > 12 && carRoad) { pathEffect = o.getDashEffect("4_4"); //$NON-NLS-1$ } @@ -197,27 +211,32 @@ public class PolylineRenderer { } else if(zoom == 13){ color = 0xff999999; strokeWidth = 3; - secondColor = Color.WHITE; - secondStrokeWidth = 1; - secondEffect = o.getDashEffect("8_12"); //$NON-NLS-1$ + rc.second.color = Color.WHITE; + rc.second.strokeWidth = 1; + rc.second.pathEffect = o.getDashEffect("8_12"); //$NON-NLS-1$ } else { color = 0xff999999; strokeWidth = 3; - secondColor = Color.WHITE; - secondStrokeWidth = 1; + rc.second.color = Color.WHITE; + rc.second.strokeWidth = 1; if(tunnel){ - // TODO tunnel + rc.second.strokeWidth = 3; + rc.second.pathEffect = o.getDashEffect("4_4"); //$NON-NLS-1$ } else if(bridge){ - // TODO bridge - secondStrokeWidth = 5; - strokeWidth = 7; + rc.third.color = color; + rc.third.strokeWidth = 1; + rc.third.pathEffect = o.getDashEffect("12_8_1_0"); //$NON-NLS-1$ + rc.second.strokeWidth = 4; + strokeWidth = 5; + color = Color.BLACK ; } else { - secondEffect = o.getDashEffect("0_11_8_1"); //$NON-NLS-1$ + rc.second.strokeWidth = 1; + rc.second.pathEffect = o.getDashEffect("0_11_8_1"); //$NON-NLS-1$ } } } else if(subtype == 2 ) { - color = 0xff44444; + color = 0xff444444; if(zoom < 13){ strokeWidth = 0; } else if(zoom < 15){ @@ -248,9 +267,9 @@ public class PolylineRenderer { if(bridge){ strokeWidth = 4.5f; color = Color.BLACK; - secondStrokeWidth = 2; - secondColor = Color.GRAY; - secondEffect =o.getDashEffect("4_2"); //$NON-NLS-1$ + rc.second.strokeWidth = 2; + rc.second.color = Color.GRAY; + rc.second.pathEffect = o.getDashEffect("4_2"); //$NON-NLS-1$ } else { strokeWidth = 2; color = Color.GRAY; @@ -273,9 +292,9 @@ public class PolylineRenderer { } else { color = 0xff999999; strokeWidth = 3; - secondColor = Color.WHITE; - secondStrokeWidth = 1; - secondEffect = o.getDashEffect("0_1_8_1"); //$NON-NLS-1$ + rc.second.color = Color.WHITE; + rc.second.strokeWidth = 1; + rc.second.pathEffect = o.getDashEffect("0_1_8_1"); //$NON-NLS-1$ } } else if (subtype == 8 || subtype == 11) { if(zoom < 15){ @@ -286,8 +305,8 @@ public class PolylineRenderer { if(tunnel){ strokeWidth = 5; pathEffect = o.getDashEffect("5_3"); //$NON-NLS-1$ - secondColor = 0xffcccccc; - secondStrokeWidth = 3; + rc.second.color = 0xffcccccc; + rc.second.strokeWidth = 3; } } } else if (subtype == 10) { @@ -383,8 +402,8 @@ public class PolylineRenderer { } if(zoom > 12 && MapRenderingTypes.getWayLayer(objType) == 1){ pathEffect = o.getDashEffect("4_2"); //$NON-NLS-1$ - secondStrokeWidth = strokeWidth - 2; - secondColor = Color.WHITE; + rc.second.strokeWidth = strokeWidth - 2; + rc.second.color = Color.WHITE; } } break; @@ -454,9 +473,19 @@ public class PolylineRenderer { } } if(MapRenderingTypes.getWayLayer(objType) == 2 && zoom > 12){ - if(secondStrokeWidth == 0){ - shadowLayer = 2; - shadowColor = Color.BLACK; + if(rc.second.strokeWidth == 0){ + rc.second.color = color; + rc.second.strokeWidth = strokeWidth; + rc.second.pathEffect = pathEffect; + strokeWidth += 2; + color = Color.BLACK; + pathEffect = null; + if(rc.second.pathEffect == null){ + rc.second.cap = Cap.SQUARE; + } else { + color = Color.GRAY; + } + } } } @@ -592,14 +621,49 @@ public class PolylineRenderer { break; } - rc.color = color; - rc.pathEffect = pathEffect; - rc.shadowColor = shadowColor; - rc.shadowLayer = shadowLayer; + rc.main.color = color; + rc.main.pathEffect = pathEffect; + rc.main.shadowColor = shadowColor; + rc.main.shadowLayer = shadowLayer; + rc.main.strokeWidth = strokeWidth; rc.showText = showText; - rc.strokeWidth = strokeWidth; - rc.secondColor = secondColor; - rc.secondEffect = secondEffect; - rc.secondStrokeWidth = secondStrokeWidth; + } + + private static RenderingPaintProperties[] oneWay = null; + public static RenderingPaintProperties[] getOneWayProperties(){ + if(oneWay == null){ + PathEffect arrowDashEffect1 = new DashPathEffect(new float[] { 0, 12, 10, 152 }, 0); + PathEffect arrowDashEffect2 = new DashPathEffect(new float[] { 0, 12, 9, 153 }, 1); + PathEffect arrowDashEffect3 = new DashPathEffect(new float[] { 0, 18, 2, 154 }, 1); + PathEffect arrowDashEffect4 = new DashPathEffect(new float[] { 0, 18, 1, 155 }, 1); + oneWay = new RenderingPaintProperties[4]; + oneWay[0] = new RenderingPaintProperties(); + oneWay[0].emptyLine(); + oneWay[0].color = 0xff6c70d5; + oneWay[0].strokeWidth = 1; + oneWay[0].pathEffect = arrowDashEffect1; + + oneWay[1] = new RenderingPaintProperties(); + oneWay[1].emptyLine(); + oneWay[1].color = 0xff6c70d5; + oneWay[1].strokeWidth = 2; + oneWay[1].pathEffect = arrowDashEffect2; + + oneWay[2] = new RenderingPaintProperties(); + oneWay[2].emptyLine(); + oneWay[2].color = 0xff6c70d5; + oneWay[2].strokeWidth = 3; + oneWay[2].pathEffect = arrowDashEffect3; + + oneWay[3] = new RenderingPaintProperties(); + oneWay[3].emptyLine(); + oneWay[3].color = 0xff6c70d5; + oneWay[3].strokeWidth = 4; + oneWay[3].pathEffect = arrowDashEffect4; + + } + return oneWay; + } + } diff --git a/OsmAnd/src/net/osmand/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/views/OsmandMapTileView.java index b10c6d3c6e..ef2af7f7e3 100644 --- a/OsmAnd/src/net/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/views/OsmandMapTileView.java @@ -243,8 +243,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall public void setZoom(float zoom){ - if ((map == null && zoom < 22) || - ((map.getMaximumZoomSupported() + OVERZOOM_IN) >= zoom && map.getMinimumZoomSupported() <= zoom)) { + if ((map == null && zoom < 22 && zoom > 0) || + (map != null && (map.getMaximumZoomSupported() + OVERZOOM_IN) >= zoom && map.getMinimumZoomSupported() <= zoom)) { animatedDraggingThread.stopAnimating(); this.zoom = zoom; refreshMap();