Fix unknown PT geometry color

This commit is contained in:
crimean 2019-04-05 20:59:49 +03:00
parent 8a0304f99f
commit 2611dbf829
2 changed files with 32 additions and 14 deletions

View file

@ -28,6 +28,8 @@ import net.osmand.util.MapUtils;
public class TransportRoutePlanner { public class TransportRoutePlanner {
private static final boolean MEASURE_TIME = false; private static final boolean MEASURE_TIME = false;
public static final long GEOMETRY_WAY_ID = -1;
public static final long STOPS_WAY_ID = -2;
public List<TransportRouteResult> buildRoute(TransportRoutingContext ctx, LatLon start, LatLon end) throws IOException, InterruptedException { public List<TransportRouteResult> buildRoute(TransportRoutingContext ctx, LatLon start, LatLon end) throws IOException, InterruptedException {
ctx.startCalcTime = System.currentTimeMillis(); ctx.startCalcTime = System.currentTimeMillis();
@ -402,14 +404,16 @@ public class TransportRoutePlanner {
} }
} }
} }
Way way = new Way(-1); Way way;
if (res.isEmpty() || endInd == -1) { if (res.isEmpty() || endInd == -1) {
way = new Way(STOPS_WAY_ID);
for (int i = start; i <= end; i++) { for (int i = start; i <= end; i++) {
LatLon l = getStop(i).getLocation(); LatLon l = getStop(i).getLocation();
Node n = new Node(l.getLatitude(), l.getLongitude(), -1); Node n = new Node(l.getLatitude(), l.getLongitude(), -1);
way.addNode(n); way.addNode(n);
} }
} else { } else {
way = new Way(GEOMETRY_WAY_ID);
for(int k = 0; k < res.size() && k < endInd; k++) { for(int k = 0; k < res.size() && k < endInd; k++) {
way.addNode(res.get(k)); way.addNode(res.get(k));
} }

View file

@ -13,6 +13,7 @@ import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffColorFilter;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.Pair; import android.util.Pair;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
@ -39,6 +40,7 @@ import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.TransportRoutingHelper; import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.transport.TransportStopType; import net.osmand.plus.transport.TransportStopType;
import net.osmand.router.TransportRoutePlanner;
import net.osmand.router.TransportRoutePlanner.TransportRouteResult; import net.osmand.router.TransportRoutePlanner.TransportRouteResult;
import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment; import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -412,7 +414,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
private static class GeometryWalkWayStyle extends GeometryWayStyle { private static class GeometryWalkWayStyle extends GeometryWayStyle {
public GeometryWalkWayStyle(GeometryWayContext context) { GeometryWalkWayStyle(GeometryWayContext context) {
super(context); super(context);
} }
@ -449,7 +451,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
private static class GeometryAnchorWayStyle extends GeometryWayStyle { private static class GeometryAnchorWayStyle extends GeometryWayStyle {
public GeometryAnchorWayStyle(GeometryWayContext context) { GeometryAnchorWayStyle(GeometryWayContext context) {
super(context); super(context);
} }
@ -481,7 +483,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
private static class GeometrySolidWayStyle extends GeometryWayStyle { private static class GeometrySolidWayStyle extends GeometryWayStyle {
public GeometrySolidWayStyle(GeometryWayContext context, Integer color) { GeometrySolidWayStyle(GeometryWayContext context, Integer color) {
super(context, color); super(context, color);
} }
@ -502,13 +504,22 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
} }
} }
private static class TransportStopsWayStyle extends GeometryTransportWayStyle {
TransportStopsWayStyle(GeometryWayContext context, TransportRouteResultSegment segment) {
super(context, segment);
OsmandApplication app = (OsmandApplication) getCtx().getApplicationContext();
this.color = ContextCompat.getColor(app, R.color.icon_color);
this.pointColor = UiUtilities.getContrastColor(app, color, true);
}
}
private static class GeometryTransportWayStyle extends GeometryWayStyle { private static class GeometryTransportWayStyle extends GeometryWayStyle {
private TransportRouteResultSegment segment; private TransportRouteResultSegment segment;
private Bitmap stopBitmap; private Bitmap stopBitmap;
private Integer pointColor; protected Integer pointColor;
public GeometryTransportWayStyle(GeometryWayContext context, TransportRouteResultSegment segment) { GeometryTransportWayStyle(GeometryWayContext context, TransportRouteResultSegment segment) {
super(context); super(context);
this.segment = segment; this.segment = segment;
@ -1213,7 +1224,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
addRouteWalk(prev, s, p, floc, res, styles); addRouteWalk(prev, s, p, floc, res, styles);
List<Way> geometry = s.getGeometry(); List<Way> geometry = s.getGeometry();
res.addAll(geometry); res.addAll(geometry);
addStyle(s, geometry.size(), styles); addStyle(s, geometry, styles);
p = s.getEnd().getLocation(); p = s.getEnd().getLocation();
prev = s; prev = s;
} }
@ -1226,32 +1237,35 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
final RouteCalculationResult walkingRouteSegment = transportHelper.getWalkingRouteSegment(s1, s2); final RouteCalculationResult walkingRouteSegment = transportHelper.getWalkingRouteSegment(s1, s2);
if (walkingRouteSegment != null && walkingRouteSegment.getRouteLocations().size() > 0) { if (walkingRouteSegment != null && walkingRouteSegment.getRouteLocations().size() > 0) {
final List<Location> routeLocations = walkingRouteSegment.getRouteLocations(); final List<Location> routeLocations = walkingRouteSegment.getRouteLocations();
Way way = new Way(-1); Way way = new Way(TransportRoutePlanner.GEOMETRY_WAY_ID);
way.putTag(OSMSettings.OSMTagKey.NAME.getValue(), String.format(Locale.US, "Walk %d m", walkingRouteSegment.getWholeDistance())); way.putTag(OSMSettings.OSMTagKey.NAME.getValue(), String.format(Locale.US, "Walk %d m", walkingRouteSegment.getWholeDistance()));
for (Location l : routeLocations) { for (Location l : routeLocations) {
way.addNode(new Node(l.getLatitude(), l.getLongitude(), -1)); way.addNode(new Node(l.getLatitude(), l.getLongitude(), -1));
} }
res.add(way); res.add(way);
addStyle(null, 1, styles); addStyle(null, Collections.singletonList(way), styles);
} else { } else {
double dist = MapUtils.getDistance(start, end); double dist = MapUtils.getDistance(start, end);
Way way = new Way(-1); Way way = new Way(TransportRoutePlanner.GEOMETRY_WAY_ID);
way.putTag(OSMSettings.OSMTagKey.NAME.getValue(), String.format(Locale.US, "Walk %.1f m", dist)); way.putTag(OSMSettings.OSMTagKey.NAME.getValue(), String.format(Locale.US, "Walk %.1f m", dist));
way.addNode(new Node(start.getLatitude(), start.getLongitude(), -1)); way.addNode(new Node(start.getLatitude(), start.getLongitude(), -1));
way.addNode(new Node(end.getLatitude(), end.getLongitude(), -1)); way.addNode(new Node(end.getLatitude(), end.getLongitude(), -1));
res.add(way); res.add(way);
addStyle(null, 1, styles); addStyle(null, Collections.singletonList(way), styles);
} }
} }
private void addStyle(TransportRouteResultSegment segment, int count, List<GeometryWayStyle> styles) { private void addStyle(TransportRouteResultSegment segment, List<Way> geometry, List<GeometryWayStyle> styles) {
GeometryWayStyle style; GeometryWayStyle style;
Way w = geometry.get(0);
if (segment == null || segment.route == null) { if (segment == null || segment.route == null) {
style = new GeometryWalkWayStyle(wayContext); style = new GeometryWalkWayStyle(wayContext);
} else { } else if (w.getId() == TransportRoutePlanner.GEOMETRY_WAY_ID) {
style = new GeometryTransportWayStyle(wayContext, segment); style = new GeometryTransportWayStyle(wayContext, segment);
} else {
style = new TransportStopsWayStyle(wayContext, segment);
} }
for (int i = 0; i < count; i++) { for (int i = 0; i < geometry.size(); i++) {
styles.add(style); styles.add(style);
} }
} }