Add drawing track border by params
This commit is contained in:
parent
8487444779
commit
15fb2b6774
2 changed files with 33 additions and 7 deletions
|
@ -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<WptPt> points = null; // Original list of points
|
||||
protected List<WptPt> 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) {
|
||||
if (drawBorder && zoom < BORDER_TYPE_ZOOM_THRESHOLD) {
|
||||
drawSolid(points, borderPaint, canvas, tileBox);
|
||||
drawGradient(points, paint, 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<WptPt> pts, Paint p, Canvas canvas, RotatedTileBox tileBox) {
|
||||
protected void drawGradient(double zoom, List<WptPt> 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<Integer> gradientColors = new ArrayList<>();
|
||||
float gradientAngle = 0;
|
||||
|
||||
List<Path> paths = new ArrayList<>();
|
||||
List<LinearGradient> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue