Issue in filling color of the polygon drawn on a Map

Viewed 919
private void drawPolygon(List<LocationPointsModel> locationPoints, String fencingColor) {

    mMap.clear();
    PolygonOptions rectOptions = new PolygonOptions();
    rectOptions.strokeColor(Color.parseColor(fencingColor));
    rectOptions.strokeWidth(2);
    String fillcolor = Constants.FILL_COLOR_GEOFENCE + fencingColor.substring(1);//creating opacity less color
    rectOptions.fillColor(Color.parseColor(fillcolor));
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    int size = locationPoints.size();
    for (int i = 0; i < size; i++) {
        LatLng latLng = new LatLng(locationPoints.get(i).getLat(), locationPoints.get(i).getLon());
        latList.add(latLng);
        rectOptions.add(latLng);
    }

    Polygon polygon = mMap.addPolygon(rectOptions);
}

In some cases if the polygon lines intersect fill color is not properly rendered.Polygon Fill color Issue. Is that possible to fill polygon with following way. Desired output.

1 Answers

It looks like filling color of self intersecting polygons is not supported by Google Maps Android API.

There is a bug report in the Google issue tracker:

https://issuetracker.google.com/issues/35823225#comment15

The comment #15 posted by Google rep states

We do not support self-intersecting polygons (either the outline or the hole intersecting)

Also the issue with intersecting polygons and filling is mentioned in the documentation. Look at the hollow polygons section

If the hole intersects the outline of the polygon, the polygon will be rendered without any fill.

https://developers.google.com/maps/documentation/android-api/shapes#create_a_hollow_polygon

Looks like polygon intersections and filling are not compatible in Maps Android API.

Related