I am trying to hide the whole map except a zone, for that I am using a polygon with a hole in the area that I want to show.
The problem is that depending on the zoom the empty area is covered with the color of the polygon or the polygon loses its color.
This is the code:
//polygon hide all world map
float delta = 0.1f; //0.1f
List points = Arrays.asList(new LatLng(90, -180),
new LatLng(-90+delta, -180+delta),
new LatLng(-90+delta, 0),
new LatLng(-90+delta, 180-delta),
new LatLng(0, 180-delta),
new LatLng(90-delta, 180-delta),
new LatLng(90-delta, 0),
new LatLng(90-delta, -180+delta),
new LatLng(0,-180+delta));
PolygonOptions rectOptions = new PolygonOptions();
rectOptions.addAll(points);
//hole
ArrayList<LatLng> a = new ArrayList<>();
a.add(new LatLng(centro.getLatitud1(), centro.getLongitud1()));
a.add(new LatLng(centro.getLatitud2(), centro.getLongitud1()));
a.add(new LatLng(centro.getLatitud2(), centro.getLongitud2()));
a.add(new LatLng(centro.getLatitud1(), centro.getLongitud2()));
Iterable<LatLng> iterator = a;
rectOptions.addHole(iterator);
// Get back the mutable Polygon
rectOptions.fillColor(ResourcesCompat.getColor(getResources(), R.color.colorPrimary, null));
polygon = mMap.addPolygon(rectOptions);
Images:
All correct
polygon colour dissapear
Hole is filled with the color of the polygon
If I keep zooming everything turns right.
Im using 'com.google.android.gms:play-services:9.6.1'
I do not know how to fix it and I am a noob in maps, if someone knows how to do it or knows some other method to do what I want I would be very grateful.