Small fixes

This commit is contained in:
cepprice 2021-04-16 19:23:54 +05:00
parent 0bdf2dfa8a
commit fbec2abd19
5 changed files with 47 additions and 33 deletions

View file

@ -266,6 +266,8 @@ public class RouteColorize {
List<RouteColorizationPoint> sublist = dataList.subList(prevId, currentId); List<RouteColorizationPoint> sublist = dataList.subList(prevId, currentId);
simplified.addAll(getExtremums(sublist)); simplified.addAll(getExtremums(sublist));
} }
Node lastSurvivedPoint = result.get(result.size() - 1);
simplified.add(dataList.get((int) lastSurvivedPoint.getId()));
return simplified; return simplified;
} }

View file

@ -139,6 +139,11 @@ public abstract class GeometryWay<T extends GeometryWayContext, D extends Geomet
@NonNull @NonNull
public abstract GeometryWayStyle<?> getDefaultWayStyle(); public abstract GeometryWayStyle<?> getDefaultWayStyle();
@NonNull
protected Map<Integer, GeometryWayStyle<?>> getStyleMap() {
return styleMap;
}
public Location getNextVisiblePoint() { public Location getNextVisiblePoint() {
return null; return null;
} }
@ -380,6 +385,8 @@ public abstract class GeometryWay<T extends GeometryWayContext, D extends Geomet
} }
} }
context.clearCustomColor(); context.clearCustomColor();
context.clearCustomShader();
} }
drawer.drawArrowsOverPath(canvas, tb, tx, ty, angles, distances, distToFinish, styles); drawer.drawArrowsOverPath(canvas, tb, tx, ty, angles, distances, distToFinish, styles);
} finally { } finally {

View file

@ -105,6 +105,10 @@ public abstract class GeometryWayContext {
attrs.customColor = 0; attrs.customColor = 0;
} }
public void clearCustomShader() {
attrs.customColorPaint.setShader(null);
}
public int getStrokeColor(int sourceColor) { public int getStrokeColor(int sourceColor) {
return ColorUtils.blendARGB(sourceColor, Color.BLACK, 0.6f); return ColorUtils.blendARGB(sourceColor, Color.BLACK, 0.6f);
} }

View file

@ -15,6 +15,7 @@ import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.track.GradientScaleType; import net.osmand.plus.track.GradientScaleType;
import net.osmand.router.RouteColorize; import net.osmand.router.RouteColorize;
import net.osmand.router.RouteColorize.RouteColorizationPoint; import net.osmand.router.RouteColorize.RouteColorizationPoint;
import net.osmand.util.Algorithms;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -46,6 +47,11 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Route
@Nullable Float width, @Nullable Float width,
@Nullable @ColorInt Integer pointColor, @Nullable @ColorInt Integer pointColor,
@Nullable GradientScaleType scaleType) { @Nullable GradientScaleType scaleType) {
if (scaleType != null && !Algorithms.objectEquals(customWidth, width)) {
for (GeometryWayStyle<?> style : getStyleMap().values()) {
style.width = width;
}
}
this.customColor = color; this.customColor = color;
this.customWidth = width; this.customWidth = width;
this.customPointColor = pointColor; this.customPointColor = pointColor;
@ -54,50 +60,46 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Route
if (width != null) { if (width != null) {
getContext().getAttrs().shadowPaint.setStrokeWidth(width + getContext().getDensity() * 2); getContext().getAttrs().shadowPaint.setStrokeWidth(width + getContext().getDensity() * 2);
} }
getContext().getAttrs().customColorPaint.setStrokeCap(scaleType != null ? Paint.Cap.ROUND : Paint.Cap.BUTT);
} }
public void updateRoute(RotatedTileBox tb, RouteCalculationResult route, OsmandApplication app) { public void updateRoute(RotatedTileBox tb, RouteCalculationResult route, OsmandApplication app) {
if (tb.getMapDensity() == getMapDensity() && this.route == route && prevScaleType == scaleType) { if (tb.getMapDensity() != getMapDensity() || this.route != route || prevScaleType != scaleType) {
return; this.route = route;
List<Location> locations = route != null ? route.getImmutableAllLocations() : Collections.<Location>emptyList();
if (scaleType == null || locations.size() < 2) {
updateWay(locations, tb);
return;
}
GPXFile gpxFile = GpxUiHelper.makeGpxFromRoute(route, app);
if (!gpxFile.hasAltitude) {
updateWay(locations, tb);
return;
}
// Start point can have wrong zero altitude
List<GPXUtilities.WptPt> pts = gpxFile.tracks.get(0).segments.get(0).points;
GPXUtilities.WptPt firstPt = pts.get(0);
if (firstPt.ele == 0) {
firstPt.ele = pts.get(1).ele;
}
RouteColorize routeColorize = new RouteColorize(tb.getZoom(), gpxFile, null, scaleType.toColorizationType(), 0);
List<RouteColorizationPoint> points = routeColorize.getResult(false);
updateWay(new GradientGeometryWayProvider(routeColorize, points), createStyles(points), tb);
} }
this.route = route;
List<Location> locations = route != null ? route.getImmutableAllLocations() : Collections.<Location>emptyList();
if (scaleType == null || locations.size() < 2) {
updateWay(locations, tb);
return;
}
GPXFile gpxFile = GpxUiHelper.makeGpxFromRoute(route, app);
if (!gpxFile.hasAltitude) {
updateWay(locations, tb);
return;
}
// Start point can have wrong zero altitude
List<GPXUtilities.WptPt> pts = gpxFile.tracks.get(0).segments.get(0).points;
GPXUtilities.WptPt firstPt = pts.get(0);
if (firstPt.ele == 0) {
firstPt.ele = pts.get(1).ele;
}
RouteColorize routeColorize = new RouteColorize(tb.getZoom(), gpxFile, null, scaleType.toColorizationType(), 0);
List<RouteColorizationPoint> points = routeColorize.getResult(false);
updateWay(new GradientGeometryWayProvider(routeColorize), createStyles(points), tb);
} }
private Map<Integer, GeometryWayStyle<?>> createStyles(List<RouteColorizationPoint> points) { private Map<Integer, GeometryWayStyle<?>> createStyles(List<RouteColorizationPoint> points) {
Map<Integer, GeometryWayStyle<?>> styleMap = new TreeMap<>(); Map<Integer, GeometryWayStyle<?>> styleMap = new TreeMap<>();
for (int i = 1; i < points.size(); i++) { for (int i = 1; i < points.size(); i++) {
GeometryGradientWayStyle style = getGradientWayStyle(); GeometryGradientWayStyle style = getGradientWayStyle();
style.startColor = points.get(i - 1).color; style.startColor = points.get(i - 1).color;
style.endColor = points.get(i).color; style.endColor = points.get(i).color;
styleMap.put(i, style); styleMap.put(i, style);
} }
return styleMap; return styleMap;
} }
@ -183,9 +185,9 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Route
private final RouteColorize routeColorize; private final RouteColorize routeColorize;
private final List<RouteColorizationPoint> locations; private final List<RouteColorizationPoint> locations;
public GradientGeometryWayProvider(RouteColorize routeColorize) { public GradientGeometryWayProvider(RouteColorize routeColorize, List<RouteColorizationPoint> locations) {
this.routeColorize = routeColorize; this.routeColorize = routeColorize;
locations = routeColorize.getResult(false); this.locations = locations;
} }
public List<RouteColorizationPoint> simplify(int zoom) { public List<RouteColorizationPoint> simplify(int zoom) {

View file

@ -44,7 +44,6 @@ public class RouteGeometryWayDrawer extends GeometryWayDrawer<RouteGeometryWayCo
LinearGradient gradient = new LinearGradient(style.startXY.x, style.startXY.y, style.endXY.x, style.endXY.y, LinearGradient gradient = new LinearGradient(style.startXY.x, style.startXY.y, style.endXY.x, style.endXY.y,
style.startColor, style.endColor, Shader.TileMode.CLAMP); style.startColor, style.endColor, Shader.TileMode.CLAMP);
getContext().getAttrs().customColorPaint.setShader(gradient); getContext().getAttrs().customColorPaint.setShader(gradient);
getContext().getAttrs().customColorPaint.setStrokeCap(Paint.Cap.ROUND);
} }
super.drawPath(canvas, path, s); super.drawPath(canvas, path, s);
} }