From 37d9ec6a784460b70c076fa1cf58e1b17e0e6d1b Mon Sep 17 00:00:00 2001 From: crimean Date: Tue, 5 Feb 2019 18:42:50 +0300 Subject: [PATCH] Added small stop bitmaps along transport route if overlapped --- .../net/osmand/plus/views/OsmandMapLayer.java | 32 ++++++++++++- .../src/net/osmand/plus/views/RouteLayer.java | 47 +++++++++++++++++-- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 297a19ec3c..b84e4c277b 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -169,7 +169,8 @@ public abstract class OsmandMapLayer { private Bitmap arrowBitmap; private Bitmap walkArrowBitmap; private Bitmap anchorBitmap; - private Map, Bitmap> stopBitmapsCache = new HashMap(); + private Map, Bitmap> stopBitmapsCache = new HashMap<>(); + private Map stopSmallBitmapsCache = new HashMap<>(); public GeometryWayContext(Context ctx, float density) { this.ctx = ctx; @@ -354,6 +355,35 @@ public abstract class OsmandMapLayer { } return bmp; } + + public Bitmap getStopSmallShieldBitmap(int color) { + Bitmap bmp = stopSmallBitmapsCache.get(color); + if (bmp == null) { + int fillColor = UiUtilities.getContrastColor(getApp(), color, true); + int strokeColor = getStrokeColor(color); + + float routeShieldRadius = attrsPT.paint3.getStrokeWidth() / 4; + + float margin = 3f * density; + float width = routeShieldRadius * 2 + margin * 2; + float height = routeShieldRadius * 2 + margin * 2; + bmp = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888); + + Canvas canvas = new Canvas(bmp); + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setStrokeWidth(1f * density); + paint.setColor(fillColor); + paint.setStyle(Paint.Style.FILL); + canvas.drawCircle(width / 2, height / 2, routeShieldRadius, paint); + paint.setColor(strokeColor); + paint.setStyle(Paint.Style.STROKE); + canvas.drawCircle(width / 2, height / 2, routeShieldRadius, paint); + + stopSmallBitmapsCache.put(color, bmp); + } + return bmp; + } } public abstract static class GeometryWayStyle { diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index cb06c398e7..a17ff85a9d 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -19,6 +19,7 @@ import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; +import net.osmand.data.QuadTree; import net.osmand.data.RotatedTileBox; import net.osmand.data.TransportRoute; import net.osmand.data.TransportStop; @@ -372,6 +373,17 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont } private static class PathTransportStop extends PathPoint { + + private boolean smallPoint; + + public boolean isSmallPoint() { + return smallPoint; + } + + public void setSmallPoint(boolean smallPoint) { + this.smallPoint = smallPoint; + } + PathTransportStop(float x, float y, GeometryTransportWayStyle style) { super(x, y, 0, style); } @@ -380,9 +392,11 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont return (GeometryTransportWayStyle) style; } + @Override void draw(Canvas canvas, GeometryWayContext context) { - Bitmap stopBitmap = getTransportWayStyle().getStopBitmap(); + Bitmap stopBitmap = smallPoint ? + getTransportWayStyle().getStopSmallBitmap() : getTransportWayStyle().getStopBitmap(); float paintH2 = stopBitmap.getHeight() / 2f; float paintW2 = stopBitmap.getWidth() / 2f; @@ -542,6 +556,10 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont return getContext().getStopShieldBitmap(color, stopBitmap); } + public Bitmap getStopSmallBitmap() { + return getContext().getStopSmallShieldBitmap(color); + } + @Override public boolean isTransportLine() { return true; @@ -669,9 +687,30 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont PathAnchor anchor = anchors.get(i); anchor.draw(canvas, wayContext); } - for (int i = stops.size() - 1; i >= 0; i--) { - PathTransportStop stop = stops.get(i); - stop.draw(canvas, wayContext); + if (stops.size() > 0) { + QuadTree boundIntersections = initBoundIntersections(tb); + List fullObjects = new ArrayList<>(); + Bitmap stopBitmap = null; + float iconSize = 1f; + for (int i = stops.size() - 1; i >= 0; i--) { + PathTransportStop stop = stops.get(i); + if (stopBitmap == null) { + stopBitmap = stop.getTransportWayStyle().getStopBitmap(); + iconSize = stopBitmap.getWidth() * 3 / 2.5f; + } + float x = stop.x; + float y = stop.y; + if (intersects(boundIntersections, x, y, iconSize, iconSize)) { + stop.setSmallPoint(true); + stop.draw(canvas, wayContext); + } else { + stop.setSmallPoint(false); + fullObjects.add(stop); + } + } + for (PathTransportStop stop : fullObjects) { + stop.draw(canvas, wayContext); + } } }