Add configurable drawing of route line border

This commit is contained in:
cepprice 2021-04-15 17:28:48 +05:00
parent ff7aa932a3
commit 149b89090b
5 changed files with 67 additions and 4 deletions

View file

@ -141,6 +141,8 @@ public class RouteLayer extends OsmandMapLayer implements IContextMenuProvider {
attrs.defaultWidth = (int) (12 * density);
attrs.defaultWidth3 = (int) (7 * density);
attrs.defaultColor = view.getResources().getColor(R.color.nav_track);
attrs.shadowPaint.setColor(0x80000000);
attrs.shadowPaint.setStrokeCap(Cap.ROUND);
attrs.paint3.setStrokeCap(Cap.BUTT);
attrs.paint3.setColor(Color.WHITE);
attrs.paint2.setStrokeCap(Cap.BUTT);

View file

@ -168,7 +168,7 @@ public abstract class GeometryWay<T extends GeometryWayContext, D extends Geomet
int previous = -1;
for (int i = startLocationIndex; i < locationProvider.getSize(); i++) {
style = getStyle(i, defaultWayStyle);
if (simplification.getQuick(i) == 0 && !styleMap.containsKey(i)) {
if (shouldSkipLocation(simplification, styleMap, i)) {
continue;
}
if (shouldAddLocation(simplification, leftLongitude, rightLongitude, bottomLatitude, topLatitude,
@ -202,6 +202,10 @@ public abstract class GeometryWay<T extends GeometryWayContext, D extends Geomet
drawRouteSegment(tb, canvas, tx, ty, angles, distances, 0, styles);
}
protected boolean shouldSkipLocation(TByteArrayList simplification, Map<Integer, GeometryWayStyle<?>> styleMap, int locationIdx) {
return simplification.getQuick(locationIdx) == 0 && !styleMap.containsKey(locationIdx);
}
protected boolean shouldAddLocation(TByteArrayList simplification, double leftLon, double rightLon, double bottomLat,
double topLat, GeometryWayProvider provider, int currLocationIdx) {
double lat = provider.getLatitude(currLocationIdx);
@ -358,7 +362,18 @@ public abstract class GeometryWay<T extends GeometryWayContext, D extends Geomet
List<Pair<Path, GeometryWayStyle<?>>> paths = new ArrayList<>();
canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
calculatePath(tb, tx, ty, styles, paths);
for (Pair<Path, GeometryWayStyle<?>> pc : paths) {
drawer.drawFullBorder(canvas, tb.getZoom(), paths);
drawer.drawSegmentBorder(canvas, tb.getZoom(), paths.get(0).first, paths.get(0).second);
for (int i = 1; i <= paths.size(); i++) {
if (i != paths.size()) {
Pair<Path, GeometryWayStyle<?>> prev = paths.get(i);
if (prev.second.hasPathLine()) {
drawer.drawSegmentBorder(canvas, tb.getZoom(), prev.first, prev.second);
}
}
Pair<Path, GeometryWayStyle<?>> pc = paths.get(i - 1);
GeometryWayStyle<?> style = pc.second;
if (style.hasPathLine()) {
drawer.drawPath(canvas, pc.first, style);

View file

@ -7,6 +7,7 @@ import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.util.Pair;
import net.osmand.data.RotatedTileBox;
@ -89,6 +90,12 @@ public class GeometryWayDrawer<T extends GeometryWayContext> {
}
}
protected void drawFullBorder(Canvas canvas, int zoom, List<Pair<Path, GeometryWayStyle<?>>> paths) {
}
protected void drawSegmentBorder(Canvas canvas, int zoom, Path path, GeometryWayStyle<?> style) {
}
protected PathPoint getArrowPathPoint(float iconx, float icony, GeometryWayStyle<?> style, double angle) {
return new PathPoint(iconx, icony, angle, style);
}

View file

@ -36,7 +36,7 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Route
private GradientScaleType scaleType;
public RouteGeometryWay(RouteGeometryWayContext context) {
super(context, new RouteGeometryWayDrawer(context));
super(context, new RouteGeometryWayDrawer(context, true));
this.helper = context.getApp().getRoutingHelper();
}
@ -48,6 +48,9 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Route
this.customWidth = width;
this.customPointColor = pointColor;
this.scaleType = GradientScaleType.ALTITUDE;
if (width != null) {
getContext().getAttrs().shadowPaint.setStrokeWidth(width + getContext().getDensity() * 2);
}
}
public void updateRoute(RotatedTileBox tb, RouteCalculationResult route, OsmandApplication app) {
@ -87,6 +90,13 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Route
return styleMap;
}
@Override
protected boolean shouldSkipLocation(TByteArrayList simplification, Map<Integer, GeometryWayStyle<?>> styleMap, int locationIdx) {
return scaleType == null ?
super.shouldSkipLocation(simplification, styleMap, locationIdx) :
simplification.getQuick(locationIdx) == 0;
}
@Override
protected void addLocation(RotatedTileBox tb, int locationIdx, GeometryWayStyle<?> style, List<Float> tx, List<Float> ty, List<Double> angles, List<Double> distances, double dist, List<GeometryWayStyle<?>> styles) {
super.addLocation(tb, getLocationProvider().getLatitude(locationIdx),

View file

@ -5,14 +5,36 @@ import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Shader;
import android.util.Pair;
import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.layers.geometry.RouteGeometryWay.GeometryGradientWayStyle;
import java.util.List;
public class RouteGeometryWayDrawer extends GeometryWayDrawer<RouteGeometryWayContext> {
private final int BORDER_TYPE_ZOOM_THRESHOLD = MapTileLayer.DEFAULT_MIN_ZOOM;
public RouteGeometryWayDrawer(RouteGeometryWayContext context) {
private final boolean drawBorder;
public RouteGeometryWayDrawer(RouteGeometryWayContext context, boolean drawBorder) {
super(context);
this.drawBorder = drawBorder;
}
@Override
protected void drawFullBorder(Canvas canvas, int zoom, List<Pair<Path, GeometryWayStyle<?>>> paths) {
if (drawBorder && zoom > BORDER_TYPE_ZOOM_THRESHOLD) {
Paint borderPaint = getContext().getAttrs().shadowPaint;
Path fullPath = new Path();
for (Pair<Path, GeometryWayStyle<?>> path : paths) {
if (path.second instanceof GeometryGradientWayStyle) {
fullPath.addPath(path.first);
}
}
canvas.drawPath(fullPath, borderPaint);
}
}
@Override
@ -26,4 +48,11 @@ public class RouteGeometryWayDrawer extends GeometryWayDrawer<RouteGeometryWayCo
}
super.drawPath(canvas, path, s);
}
@Override
protected void drawSegmentBorder(Canvas canvas, int zoom, Path path, GeometryWayStyle<?> style) {
if (drawBorder && zoom < BORDER_TYPE_ZOOM_THRESHOLD) {
canvas.drawPath(path, getContext().getAttrs().shadowPaint);
}
}
}