0

My Code is as follows. Essentially, I am trying to replace each marker with my custom marker, namely my drawable beer_full.

This overridden draw function in my custom overlay is doing the job perfectly, BUT it leaves the default icon there too. So my markers are appearing on my map as my custom marker on top of the default marker.

Anyone know how I stop the default marker showing?

Cheers

@Override
    public void draw(Canvas canvas, MapView mapview, boolean shadow) {
        // TODO Auto-generated method stub
        super.draw(canvas, mapview, shadow);

        if(!shadow)
        {
        for (int ctr = 0; ctr < myOverlays.size(); ctr++)
        {
            GeoPoint in = myOverlays.get(ctr).getPoint();

            //Toast.makeText(mapview.getContext(), ctr, Toast.LENGTH_SHORT).show();

            Point out = new Point();
            mapview.getProjection().toPixels(in, out);

            Bitmap bm = BitmapFactory.decodeResource(mapview.getResources(), 
              R.drawable.beer_full);


            canvas.drawBitmap(bm, 
              out.x - bm.getWidth()/2,  //shift the bitmap center
              out.y - bm.getHeight()/2,  //shift the bitmap center
              null);
        }
        }
    }
teoREtik
  • 7,886
  • 15
  • 46
  • 65
Thomas Clowes
  • 4,529
  • 8
  • 41
  • 73
  • Can you remove the `super.draw(canvas,mapview,shadow)` and check what happens? – Marcelo Nov 13 '12 at 13:20
  • It works :) I am an idiot. SO am I correct to understand that by having that super constructor it was simply calling the default draw function too? Are there any other problems with not having the super constructor? – Thomas Clowes Nov 13 '12 at 13:24
  • 1
    That is not a constructor, it's just a method. And yes, you are correct, you were telling the super class to draw the default icon, and then drawing your custom icon. As to any problems about not calling draw on the super class, that will depend on how it was implemented, but if you tried it with no problems, it'll hardly be a problem. If you have access to the super class source code, i'd recommend you to check it out and see if they do anything else there. – Marcelo Nov 13 '12 at 13:28

1 Answers1

1

Remove the line super.draw(canvas, mapview, shadow);. You are basically drawing the default icon (by calling the default implementation of the draw method), and then drawing your custom icon over it.

Marcelo
  • 1,471
  • 3
  • 19
  • 22