Android Maps V2: polygon fill disappears when scaling

I am trying to show several polygons on my MapView, some of them overlap and have different colors. When I add them, everything looks good, but as soon as I zoom out, many (not all) of the polygons stop filling. Scaling back and forth and scrolling sometimes fill some of them again, but this seems to be random behavior.

Code for adding polygons:

clearAreas(); for (Area area: areas) { for (List<LatLng> subArea: area.getSubAreas()) { mAreaPolygons.add(getMap().addPolygon( new PolygonOptions() .strokeWidth(2.0f) .zIndex(++zIndex) .strokeColor(area.getColor()) .fillColor(area.getTransparentColor()) .addAll(subArea))); } } 

I understand that (according to the documentation) Polygon will not fill up if its geometry is not specified correctly. I tried to add points both clockwise and counterclockwise, it does not matter.

Can anyone explain this behavior?

Update . If the debugger is connected, everything works fine! Polygons are filled and remain filled when scaling. As soon as I disconnect the debugger, the polygons again begin to lose their filling. What's going on here?

Update # 2 . The problem appears in my Galaxy S3. Surprisingly, it works on a slower, older device! Since attaching a debugger makes the application rather slow, is there maybe some kind of connection here?

Thanks a lot Marco

+7
android polygon google-maps
source share
1 answer

It smells like streams if what you said in your two updates is true. Somewhere you have a thread problem. With just the code of the code you provided, nothing seems out of place, but for this you need to study the rest of your code. It is most likely that the call to draw these polygons begins before the view is ready to draw. Without seeing anything, I would suggest something in this direction to approach the correction:

 mMap.setOnCameraChangeListener(new OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition pos) { if (pos.zoom != currentZoom) { mMap.post(new Runnable() { public void run() { // TODO: call the method that wraps the code you provided }); } }); 

What this will do is call Runnable , which you provided here after the submissions are done. This may not work as intended on the map, you may have to publish it in another queue or make some pending messages. I'm not familiar enough with the wireframe card to know for sure that this will solve it, but it definitely sounds like there are problems with threads here.

0
source share

All Articles