How do you control the size of OverlayItem on a Google Android map?

Thus, I have almost the same problem discussed in this post , except that the problem is with the solution, the solution that they decided to go simply will not work for me. I need a real solution, so I decided to rework the source code of the Android map to find the best solution.

My current solution is to override the draw method in my class that extends OverlayItem, but then I ran into a problem where clicking on an overlay element on a map does not work (tap registers in a place different from where the actual element is drawn ) So, I'll just keep digging until I find the right combination of methods to override.

+1
source share
1 answer

For everyone who has the same problem as me, the solution is actually quite simple.

All you have to do is set the borders to OverlayItem drawable, for example:

Drawable d = myOverlayItem.getMarker(0);
d.setBounds(-xWidth/2, -yWidth/2, xWidth, yWidth);

The parameter for getMarker actually depends on the state of overlayItem, but for me personally it is the same for all my states, so I didn’t care and just used 0.

I'm not sure how the solution will change depending on where you actually set the borders, but for me I did this in the draw method of my subclass of ItemizedOverlay:

@Override
public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) {
    if (!shadow) {
        // Do your projection calculations here, if necessary

        for (int i = 0; i < mOverlays.size(); i++) {
            Drawable d = mOverlays.get(i).getMarker(0);
            d.setBounds(-width/2, -height/2, width/2, height/2);
        }
    }

    super.draw(canvas, mapView, shadow);
}

, overlay 0,0, , OverlayIcon. , 50 50, OverlayItem ( OverlayItem). Overlay:

protected static void drawAt(Canvas canvas, Drawable drawable, int x, int y, boolean shadow)
  {
      // .... Do Stuff ....

      canvas.save();
      canvas.translate(x, y);

      // .... Do Stuff ....

      drawable.draw(canvas);

      // .... Do Stuff ....

      canvas.restore();
  }

( canvas.translate)

, - Overlay.

( maps.jar, ).

+1

All Articles