0

I am trying to extend/subclass ShapeDrawable. The results are really perplexing. My simple code should create a small dot and also a small triangle. And in fact, these shapes do appear on the mapview, where they are drawn. However, a second triangle with a somewhat different shape is also appearing and I have no idea why this is. Why the heck does my ShapeDrawable subclass create an extra triangle?

EXAMPLE SCREENSHOT --->> http://www.activemetrics.com/DrawableProb.png

    private class CustomDrawable extends ShapeDrawable
    {
        public CustomDrawable() //GeoPoint point, MapView mapView)
        {
        }

        public void draw(Canvas canvas)
        {
            canvas.drawCircle(0, 0, 2/*radius*/,    getPaint());
            Paint paint = new Paint();
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(2);
            paint.setColor(Color.RED);
            Path path = new Path();
            path.reset();
            path.moveTo(0, -10);
            path.lineTo(5, 0);
            path.lineTo(-5, 0);
            path.close();
            path.offset(10, 40);
            canvas.drawPath(path, paint);
        }
    }   
John Dorsey
  • 157
  • 1
  • 11

1 Answers1

0

I guess maybe this question is too hard. Perhaps something is going wrong somewhere outside of this subclass. (But it is strange then that the ghost triangle disappears by removing the drawing logic here, and that really does happen.) Anyway, I have got a better experience by making a single overlay that i add to the mapview and then overload the draw method...

    private class MapOverlay extends com.google.android.maps.Overlay
    {
        @Override
        public boolean draw(Canvas canvas, MapView mapView,
        boolean shadow, long when)
        {
            super.draw(canvas, mapView, shadow);

            Bitmap bmp = BitmapFactory.decodeResource(
                    getResources(), R.drawable.ic_launcher);

            //---translate the GeoPoint to screen pixels---
            Point screenPts1 = new Point();
            mapView.getProjection().toPixels(p1, screenPts1);

            //---translate the GeoPoint to screen pixels---
            Point screenPts2 = new Point();
            mapView.getProjection().toPixels(p2, screenPts2);

            //---add the first marker---
            canvas.drawBitmap(bmp, screenPts1.x - bmp.getWidth()/2,
                                   screenPts1.y - bmp.getHeight()/2, null);

(...snip...)

John Dorsey
  • 157
  • 1
  • 11