Added small stop bitmaps along transport route if overlapped
This commit is contained in:
parent
76d5d36b1e
commit
37d9ec6a78
2 changed files with 74 additions and 5 deletions
|
@ -169,7 +169,8 @@ public abstract class OsmandMapLayer {
|
|||
private Bitmap arrowBitmap;
|
||||
private Bitmap walkArrowBitmap;
|
||||
private Bitmap anchorBitmap;
|
||||
private Map<Pair<Integer, Bitmap>, Bitmap> stopBitmapsCache = new HashMap();
|
||||
private Map<Pair<Integer, Bitmap>, Bitmap> stopBitmapsCache = new HashMap<>();
|
||||
private Map<Integer, Bitmap> stopSmallBitmapsCache = new HashMap<>();
|
||||
|
||||
public GeometryWayContext(Context ctx, float density) {
|
||||
this.ctx = ctx;
|
||||
|
@ -354,6 +355,35 @@ public abstract class OsmandMapLayer {
|
|||
}
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public Bitmap getStopSmallShieldBitmap(int color) {
|
||||
Bitmap bmp = stopSmallBitmapsCache.get(color);
|
||||
if (bmp == null) {
|
||||
int fillColor = UiUtilities.getContrastColor(getApp(), color, true);
|
||||
int strokeColor = getStrokeColor(color);
|
||||
|
||||
float routeShieldRadius = attrsPT.paint3.getStrokeWidth() / 4;
|
||||
|
||||
float margin = 3f * density;
|
||||
float width = routeShieldRadius * 2 + margin * 2;
|
||||
float height = routeShieldRadius * 2 + margin * 2;
|
||||
bmp = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
|
||||
|
||||
Canvas canvas = new Canvas(bmp);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStrokeWidth(1f * density);
|
||||
paint.setColor(fillColor);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
canvas.drawCircle(width / 2, height / 2, routeShieldRadius, paint);
|
||||
paint.setColor(strokeColor);
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
canvas.drawCircle(width / 2, height / 2, routeShieldRadius, paint);
|
||||
|
||||
stopSmallBitmapsCache.put(color, bmp);
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class GeometryWayStyle {
|
||||
|
|
|
@ -19,6 +19,7 @@ import net.osmand.Location;
|
|||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.QuadRect;
|
||||
import net.osmand.data.QuadTree;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.data.TransportRoute;
|
||||
import net.osmand.data.TransportStop;
|
||||
|
@ -372,6 +373,17 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
|||
}
|
||||
|
||||
private static class PathTransportStop extends PathPoint {
|
||||
|
||||
private boolean smallPoint;
|
||||
|
||||
public boolean isSmallPoint() {
|
||||
return smallPoint;
|
||||
}
|
||||
|
||||
public void setSmallPoint(boolean smallPoint) {
|
||||
this.smallPoint = smallPoint;
|
||||
}
|
||||
|
||||
PathTransportStop(float x, float y, GeometryTransportWayStyle style) {
|
||||
super(x, y, 0, style);
|
||||
}
|
||||
|
@ -380,9 +392,11 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
|||
return (GeometryTransportWayStyle) style;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void draw(Canvas canvas, GeometryWayContext context) {
|
||||
Bitmap stopBitmap = getTransportWayStyle().getStopBitmap();
|
||||
Bitmap stopBitmap = smallPoint ?
|
||||
getTransportWayStyle().getStopSmallBitmap() : getTransportWayStyle().getStopBitmap();
|
||||
float paintH2 = stopBitmap.getHeight() / 2f;
|
||||
float paintW2 = stopBitmap.getWidth() / 2f;
|
||||
|
||||
|
@ -542,6 +556,10 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
|||
return getContext().getStopShieldBitmap(color, stopBitmap);
|
||||
}
|
||||
|
||||
public Bitmap getStopSmallBitmap() {
|
||||
return getContext().getStopSmallShieldBitmap(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTransportLine() {
|
||||
return true;
|
||||
|
@ -669,9 +687,30 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
|||
PathAnchor anchor = anchors.get(i);
|
||||
anchor.draw(canvas, wayContext);
|
||||
}
|
||||
for (int i = stops.size() - 1; i >= 0; i--) {
|
||||
PathTransportStop stop = stops.get(i);
|
||||
stop.draw(canvas, wayContext);
|
||||
if (stops.size() > 0) {
|
||||
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tb);
|
||||
List<PathTransportStop> fullObjects = new ArrayList<>();
|
||||
Bitmap stopBitmap = null;
|
||||
float iconSize = 1f;
|
||||
for (int i = stops.size() - 1; i >= 0; i--) {
|
||||
PathTransportStop stop = stops.get(i);
|
||||
if (stopBitmap == null) {
|
||||
stopBitmap = stop.getTransportWayStyle().getStopBitmap();
|
||||
iconSize = stopBitmap.getWidth() * 3 / 2.5f;
|
||||
}
|
||||
float x = stop.x;
|
||||
float y = stop.y;
|
||||
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
|
||||
stop.setSmallPoint(true);
|
||||
stop.draw(canvas, wayContext);
|
||||
} else {
|
||||
stop.setSmallPoint(false);
|
||||
fullObjects.add(stop);
|
||||
}
|
||||
}
|
||||
for (PathTransportStop stop : fullObjects) {
|
||||
stop.draw(canvas, wayContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue