Search code examples
androidgoogle-mapsgeojson

Android Google Maps supporting intersection in MultiPolygon


I trying to draw a Polygon inside a Polygon hole using a single Feature MultiPolygon, like this:

enter image description here

However, when I add this GeoJson file on Android the background is not being fulfilled, only the lines are being drawn:

enter image description here

When I remove the most inner Polygon, it works fine:

enter image description here

Does the Google Maps SDK somehow supports intersection on MultiPolygons?

Follows the GeoJson file:

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": {},
        "geometry": {
            "type": "MultiPolygon",
            "coordinates": [
                [
                    [
                        [-119.443359, 18.646245],
                        [-70.751953, 18.646245],
                        [-70.751953, 46.619261],
                        [-119.443359, 46.619261],
                        [-119.443359, 18.646245]
                    ],
                    [
                        [-105.732422, 25.324167],
                        [-105.732422, 39.164141],
                        [-80.332031, 39.164141],
                        [-80.332031, 25.324167],
                        [-105.732422, 25.324167]
                    ],
                    [
                        [-96.152344, 29.305561],
                        [-96.152344, 35.029996],
                        [-86.132813, 35.029996],
                        [-86.132813, 29.305561],
                        [-96.152344, 29.305561]
                    ]
                ]
            ]
        }
    }]
}

Solution

  • GeoJSON "MultiPolygon" with holes should have structure like that:

    {
        "type": "MultiPolygon", 
        "coordinates": [
            [
                [<coordinates of first polygone>],
                [<coordinates of first hole in first polygone>],
                [<coordinates of second hole in first polygone>],
                ...
                [<coordinates of last hole in first polygone>]
            ], 
            ...
            [
                [<coordinates of last polygone>],
                [<coordinates of first hole in last polygone>],
                [<coordinates of second hole in last polygone>],
                ...
                [<coordinates of last hole in last polygone>]
            ]
        ]
    }
    

    So, exactly for yours case "most inner Polygon" should be moved one level up and GeoJSON should be like that:

    {
        "type": "FeatureCollection",
        "features": [{
            "type": "Feature",
            "properties": {},
            "geometry": {
                "type": "MultiPolygon",
                "coordinates": [
                    [
                        [
                            [-119.443359, 18.646245],
                            [-70.751953, 18.646245],
                            [-70.751953, 46.619261],
                            [-119.443359, 46.619261],
                            [-119.443359, 18.646245]
                        ],
                        [
                            [-105.732422, 25.324167],
                            [-105.732422, 39.164141],
                            [-80.332031, 39.164141],
                            [-80.332031, 25.324167],
                            [-105.732422, 25.324167]
                        ]
                    ],
                    [
                       [
                            [-96.152344, 29.305561],
                            [-96.152344, 35.029996],
                            [-86.132813, 35.029996],
                            [-86.132813, 29.305561],
                            [-96.152344, 29.305561]
                        ]
                      ]
                ]
            }
        }]
    }
    

    The result in that case is:

    enter image description here