I'm trying to add my own drawable and use it in a series of overlays on a MapView. The drawable is basically a rounded box with a black outline and a number in the middle.
I have managed to achieve this using the code below, however there is what looks like a flag to the left of my box, which I certainly don't think I have drawn - so I'm wondering what it can be.
This is an example of the image:
Edit - this is what happens if a circle is drawn:
My code is below:
Custom Drawable:
public class BikeDrawable extends Drawable {
int colour;
String bikes;
public BikeDrawable (int bikes){
this.bikes = Integer.toString(bikes);
if (bikes < 4) {
colour = Color.RED;
}
else if (bikes > 3 && bikes < 9){
colour = Color.argb(244, 255, 127, 42);
}
else {
colour = Color.GREEN;
}
}
@Override
public void draw(Canvas canvas) {
Paint rectanglePaint = new Paint();
rectanglePaint.setColor(colour);
rectanglePaint.setStyle(Style.FILL);
RectF rectangle = new RectF(0.0f, 0.0f, 20.0f, 20.0f);
Paint strokepaint = new Paint();
strokepaint.setStyle(Paint.Style.STROKE);
strokepaint.setStrokeWidth(2);
strokepaint.setARGB(255, 0, 0, 0);
canvas.drawRoundRect(rectangle, 4.0f, 4.0f, rectanglePaint);
canvas.drawRoundRect(rectangle, 4.0f, 4.0f, strokepaint);
Paint textpaint = new Paint();
textpaint.setARGB(255, 0, 0, 0);
textpaint.setTextAlign(Paint.Align.CENTER);
canvas.drawText(bikes, 10, 14, textpaint);
}
@Override
public int getOpacity() {
return 0;
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter cf) {
}
}
Use in MapView:
bikeOverlay = new PointsOverlay(start_icon);
BikeDrawable start_1_drawable = new BikeDrawable (start_1.capacity);
OverlayItem start_1_overlayitem = new OverlayItem(new GeoPoint(start_1.lat,start_1.lon), null, null);
start_1_overlayitem.setMarker(start_1_drawable);
mapOverlays.add(bikeOverlay);
bikeOverlay.addOverlay(start_1_overlayitem);
Does anyone have any idea what is going on here? Is it an artefact from OverlayItem?