diff --git a/OsmAnd/src/net/osmand/plus/views/Renderable.java b/OsmAnd/src/net/osmand/plus/views/Renderable.java index dd8ba55b8a..992bc06a8f 100644 --- a/OsmAnd/src/net/osmand/plus/views/Renderable.java +++ b/OsmAnd/src/net/osmand/plus/views/Renderable.java @@ -58,6 +58,7 @@ public class Renderable { public static abstract class RenderableSegment { protected static final int MIN_CULLER_ZOOM = 16; + protected static final int BORDER_TYPE_ZOOM_THRESHOLD = MapTileLayer.DEFAULT_MAX_ZOOM + MapTileLayer.OVERZOOM_IN; public List points = null; // Original list of points protected List culled = new ArrayList<>(); // Reduced/resampled list of points @@ -70,6 +71,7 @@ public class Renderable { protected Paint paint = null; // MUST be set by 'updateLocalPaint' before use protected Paint borderPaint; protected GradientScaleType scaleType = null; + protected boolean drawBorder = false; protected GpxGeometryWay geometryWay; @@ -101,6 +103,10 @@ public class Renderable { this.scaleType = type; } + public void shouldDrawBorder(boolean drawBorder) { + this.drawBorder = drawBorder; + } + public GpxGeometryWay getGeometryWay() { return geometryWay; } @@ -119,8 +125,10 @@ public class Renderable { updateLocalPaint(p); canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); if (scaleType != null) { - drawSolid(points, borderPaint, canvas, tileBox); - drawGradient(points, paint, canvas, tileBox); + if (drawBorder && zoom < BORDER_TYPE_ZOOM_THRESHOLD) { + drawSolid(points, borderPaint, canvas, tileBox); + } + drawGradient(zoom, points, paint, canvas, tileBox); } else { drawSolid(getPointsForDrawing(), paint, canvas, tileBox); } @@ -186,8 +194,9 @@ public class Renderable { } } - protected void drawGradient(List pts, Paint p, Canvas canvas, RotatedTileBox tileBox) { + protected void drawGradient(double zoom, List pts, Paint p, Canvas canvas, RotatedTileBox tileBox) { QuadRect tileBounds = tileBox.getLatLonBounds(); + boolean drawSegmentBorder = drawBorder && zoom >= BORDER_TYPE_ZOOM_THRESHOLD; Path path = new Path(); boolean recalculateLastXY = true; WptPt lastPt = pts.get(0); @@ -196,6 +205,9 @@ public class Renderable { List gradientColors = new ArrayList<>(); float gradientAngle = 0; + List paths = new ArrayList<>(); + List gradients = new ArrayList<>(); + for (int i = 1; i < pts.size(); i++) { WptPt pt = pts.get(i); WptPt nextPt = i + 1 < pts.size() ? pts.get(i + 1) : null; @@ -209,8 +221,8 @@ public class Renderable { lastX = tileBox.getPixXFromLatLon(lastPt.lat, lastPt.lon); lastY = tileBox.getPixYFromLatLon(lastPt.lat, lastPt.lon); if (!path.isEmpty()) { - p.setShader(createGradient(gradientPoints, gradientColors)); - canvas.drawPath(path, p); + paths.add(new Path(path)); + gradients.add(createGradient(gradientPoints, gradientColors)); } path.reset(); path.moveTo(lastX, lastY); @@ -241,8 +253,21 @@ public class Renderable { lastPt = pt; } if (!path.isEmpty()) { - p.setShader(createGradient(gradientPoints, gradientColors)); - canvas.drawPath(path, p); + paths.add(new Path(path)); + gradients.add(createGradient(gradientPoints, gradientColors)); + } + + if (!paths.isEmpty()) { + if (drawSegmentBorder) { + canvas.drawPath(paths.get(0), borderPaint); + } + for (int i = 0; i < paths.size(); i++) { + if (drawSegmentBorder && i + 1 < paths.size()) { + canvas.drawPath(paths.get(i + 1), borderPaint); + } + p.setShader(gradients.get(i)); + canvas.drawPath(paths.get(i), p); + } } } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java index 007e6fe700..3e040a534c 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java @@ -721,6 +721,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM Renderable.RenderableSegment renderableSegment = (Renderable.RenderableSegment) ts.renderer; renderableSegment.setBorderPaint(borderPaint); renderableSegment.setGradientScaleType(scaleType); + renderableSegment.shouldDrawBorder(true); renderableSegment.drawSegment(view.getZoom(), paint, canvas, tileBox); } }