Android Map Overlay Disappears on Zoom

2019-02-25 01:39发布

问题:

I'm having a headache with Android's Google Maps API... I draw some overlays on the map and it's all fine, it updates regularly and handles gestures well, no problem... However, when I zoom in to perhaps level 15-16 or beyond, one or more of the larger polygons aren't redrawn. This only occurs in cases where the centroid of a circle for example lies beyond the bounds of the screen, and only occurs when zooming in.. it does not occur when zooming out, nor does it occur if one pans the map in any direction (translation).

When zooming in very close, I'm guessing the system disregards the overlay/shape, treating it as unimportant? I want any shape intersecting with the screen's bounds to be drawn. Am I missing something obvious here, because I can't seem to find any definitive answer on how to treat this scenario.

回答1:

I'd a similar problem, but I was using only squares, which make it easier to solve.

Problem details (at lest with squares):

canvas.drawRect() only draws the rectangle if both top and bottom of rectangle have coordinates within visible screen. As soon as the top or the bottom of the rectangle have a coordinate outside screen, it's not drawn.

Solution I've used for squares

I croped the square to make it always fit within the visible screen coordinates, and it was correctly drawn.

If you are using more complex figures, this solution may be more dificult to implement.

good luck.



回答2:

The way I implemented it was using the mapviewballons as library here then using the call to
super(boundCenter(defaultMarker), mapView);

The boundCenter keeps the centroid on the screen whose overlay is on screen and on zooming it is unaffected.