Android-maps-utils: Polygon does not fill correctly.

Created on 10 Mar 2016  ·  7Comments  ·  Source: googlemaps/android-maps-utils

I attempting to draw a filled Polygon as the same image rendered by GeoJSONLint.com.

geojsonlint

I tried to do it customizing demo app.
The polygon is stroked but not filled.

demo

My code

GeoJsonDemoActivity.java

@Override
protected void startDemo() {
    try {
        GeoJsonLayer layer = new GeoJsonLayer(getMap(), R.raw.test, getApplicationContext());
        for (GeoJsonFeature feature : layer.getFeatures()) {
            GeoJsonPolygonStyle style = new GeoJsonPolygonStyle();
            style.setFillColor(0x80ff7fff);
            style.setStrokeColor(0x80ff7fff);
            feature.setPolygonStyle(style);
        }
        layer.addLayerToMap();
    } catch (Exception e) {
        Log.e("TEST", "Exception occured.", e);
    }
}

test.json

{
    "type": "Feature",
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [
                    139.793638,
                    35.7324
                ],
                [
                    139.793638,
                    35.733441
                ],
                [
                    139.79520000000002,
                    35.733441
                ],
                [
                    139.79520000000002,
                    35.734483
                ],
                [
                    139.79520000000002,
                    35.735525
                ],
                [
                    139.79676199999994,
                    35.735525
                ],
                [
                    139.79676199999994,
                    35.736566
                ],
                [
                    139.79832499999998,
                    35.736566
                ],
                [
                    139.79832499999998,
                    35.737608
                ],
                [
                    139.79832499999998,
                    35.738649
                ],
                [
                    139.799887,
                    35.73865
                ],
                [
                    139.799887,
                    35.737608
                ],
                [
                    139.799887,
                    35.736566
                ],
                [
                    139.799887,
                    35.735525
                ],
                [
                    139.799887,
                    35.734483
                ],
                [
                    139.799887,
                    35.733441
                ],
                [
                    139.80144999999993,
                    35.733441
                ],
                [
                    139.80144999999993,
                    35.734483
                ],
                [
                    139.80301199999997,
                    35.734483
                ],
                [
                    139.80301199999997,
                    35.735525
                ],
                [
                    139.804575,
                    35.735525
                ],
                [
                    139.804575,
                    35.736566
                ],
                [
                    139.804575,
                    35.737608
                ],
                [
                    139.80613700000004,
                    35.737608
                ],
                [
                    139.80613700000004,
                    35.73865
                ],
                [
                    139.80770000000007,
                    35.73865
                ],
                [
                    139.80770000000007,
                    35.739691
                ],
                [
                    139.80770000000007,
                    35.740733
                ],
                [
                    139.80613700000004,
                    35.740733
                ],
                [
                    139.80613600000004,
                    35.741775
                ],
                [
                    139.80770000000007,
                    35.741775
                ],
                [
                    139.809261,
                    35.741775
                ],
                [
                    139.809262,
                    35.740733
                ],
                [
                    139.81082400000003,
                    35.740733
                ],
                [
                    139.81082400000003,
                    35.739691
                ],
                [
                    139.81238600000006,
                    35.739691
                ],
                [
                    139.81394899999998,
                    35.739691
                ],
                [
                    139.81394899999998,
                    35.73865
                ],
                [
                    139.81394999999998,
                    35.737608
                ],
                [
                    139.81394999999998,
                    35.736567
                ],
                [
                    139.81238699999994,
                    35.736567
                ],
                [
                    139.81238600000006,
                    35.737608
                ],
                [
                    139.81082500000002,
                    35.737608
                ],
                [
                    139.809262,
                    35.737608
                ],
                [
                    139.809262,
                    35.736566
                ],
                [
                    139.81082500000002,
                    35.736566
                ],
                [
                    139.81082500000002,
                    35.735526
                ],
                [
                    139.809262,
                    35.735526
                ],
                [
                    139.80770000000007,
                    35.735526
                ],
                [
                    139.80770000000007,
                    35.734484
                ],
                [
                    139.80770099999995,
                    35.733442
                ],
                [
                    139.80770099999995,
                    35.732401
                ],
                [
                    139.809263,
                    35.732401
                ],
                [
                    139.809263,
                    35.731359
                ],
                [
                    139.809263,
                    35.730318
                ],
                [
                    139.80770099999995,
                    35.730317
                ],
                [
                    139.80613800000003,
                    35.730317
                ],
                [
                    139.804576,
                    35.730317
                ],
                [
                    139.80301199999997,
                    35.730317
                ],
                [
                    139.80301299999996,
                    35.729276
                ],
                [
                    139.804576,
                    35.729276
                ],
                [
                    139.80613800000003,
                    35.729276
                ],
                [
                    139.80613800000003,
                    35.728234
                ],
                [
                    139.80770099999995,
                    35.728235
                ],
                [
                    139.80770099999995,
                    35.727193
                ],
                [
                    139.80770099999995,
                    35.726152
                ],
                [
                    139.80770099999995,
                    35.72511
                ],
                [
                    139.80770099999995,
                    35.724068
                ],
                [
                    139.80613800000003,
                    35.724068
                ],
                [
                    139.80613800000003,
                    35.723027
                ],
                [
                    139.80770099999995,
                    35.723027
                ],
                [
                    139.80770099999995,
                    35.721985
                ],
                [
                    139.80613800000003,
                    35.721985
                ],
                [
                    139.80613800000003,
                    35.720943
                ],
                [
                    139.804576,
                    35.720943
                ],
                [
                    139.804576,
                    35.719902
                ],
                [
                    139.80301299999996,
                    35.719902
                ],
                [
                    139.80301299999996,
                    35.720943
                ],
                [
                    139.80301299999996,
                    35.721985
                ],
                [
                    139.80301299999996,
                    35.723026
                ],
                [
                    139.80301299999996,
                    35.724067
                ],
                [
                    139.80301299999996,
                    35.725109
                ],
                [
                    139.80301299999996,
                    35.726151
                ],
                [
                    139.80301299999996,
                    35.727192
                ],
                [
                    139.80144999999993,
                    35.727192
                ],
                [
                    139.799887,
                    35.727191
                ],
                [
                    139.799887,
                    35.726151
                ],
                [
                    139.79832499999998,
                    35.72615
                ],
                [
                    139.79832499999998,
                    35.727191
                ],
                [
                    139.79676199999994,
                    35.727191
                ],
                [
                    139.79676199999994,
                    35.728233
                ],
                [
                    139.79520000000002,
                    35.728233
                ],
                [
                    139.79520000000002,
                    35.729275
                ],
                [
                    139.793637,
                    35.729275
                ],
                [
                    139.793637,
                    35.730316
                ],
                [
                    139.793638,
                    35.731358
                ],
                [
                    139.793638,
                    35.7324
                ]
            ],
            [
                [
                    139.81082500000002,
                    35.73865
                ],
                [
                    139.81082400000003,
                    35.739691
                ],
                [
                    139.809262,
                    35.739691
                ],
                [
                    139.809262,
                    35.73865
                ],
                [
                    139.81082500000002,
                    35.73865
                ]
            ],
            [
                [
                    139.80613800000003,
                    35.732401
                ],
                [
                    139.804576,
                    35.732401
                ],
                [
                    139.804576,
                    35.731359
                ],
                [
                    139.80613800000003,
                    35.731359
                ],
                [
                    139.80613800000003,
                    35.732401
                ]
            ]
        ]
    },
    "properties": {
        "A31_001": 26,
        "A31_002": 83,
        "A31_003": "国土交通省関東地方整備局 荒川上流河川事務所 国土交通省関東地方整備局 荒川下流河川事務所",
        "A31_004": "平成17年7月8日",
        "A31_005": "国土交通省関東地方整備局告示第359号(荒川)、第360号(入間川)、第361号(越辺川)、第362号(小畔川)、第363号(高麗川)第364号(都幾川)",
        "A31_006": "83003",
        "id": "AVM7nnPVThwKvWXT9iuS",
        "type": "inundation"
    }
}

Note
This was done with a Nexus 5X running 6.0.1 and Play Services(8.7.03) installed.

Thank you.

stale

Most helpful comment

@SeijiIto @mathieu-pousse @stephenmcd @w3ggy @infinityb
Any update on this issues.

All 7 comments

I tried to draw polygons with easier GeoJSONs.

The image rendered by GeoJSONLint.com is below.

geojsonlint-160311

and Nexus 5X.

nexus5x-160311

Sample GeoJSONs

Pattern1

{
    "type": "Feature",
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [141.328125, 36.738884],
                [141.328125, 36.469889],
                [141.937866, 36.469889],
                [141.937866, 36.738884],
                [141.328125, 36.738884]
            ],
            [
                [141.328125, 36.738884],
                [141.328125, 36.509889],
                [141.508125, 36.509889],
                [141.508125, 36.738884],
                [141.328125, 36.738884]
            ]
        ]
    },
    "properties": {
    }
}

Pattern2

{
    "type": "Feature",
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [141.328125, 36.738884],
                [141.328125, 36.469889],
                [141.937866, 36.469889],
                [141.937866, 36.738884],
                [141.328125, 36.738884]
            ],
            [
                [141.328125, 36.738884],
                [141.358125, 36.609889],
                [141.508125, 36.609889],
                [141.508125, 36.708884],
                [141.328125, 36.738884]
            ]
        ]
    },
    "properties": {
    }
}

Pattern3

{
    "type": "Feature",
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [141.328125, 36.738884],
                [141.328125, 36.469889],
                [141.937866, 36.469889],
                [141.937866, 36.738884],
                [141.328125, 36.738884]
            ],
            [
                [141.328125, 36.738884],
                [141.358125, 36.609889],
                [141.508125, 36.609889],
                [141.508125, 36.738884],
                [141.328125, 36.738884]
            ]
        ]
    },
    "properties": {
    }
}

Pattern4

{
    "type": "Feature",
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [141.328125, 36.738884],
                [141.328125, 36.469889],
                [141.937866, 36.469889],
                [141.937866, 36.738884],
                [141.328125, 36.738884]
            ],
            [
                [141.328125, 36.738884],
                [141.328125, 36.609889],
                [141.508125, 36.609889],
                [141.508125, 36.708884],
                [141.328125, 36.738884]
            ]
        ]
    },
    "properties": {
    }
}

+1 for a PR

I confirm the fix works even if looks like a workaround more than a fix :)

Thanks for excellent details here!

I believe the issue is with the underlying Google Play Services library. A workaround in android-maps-utils would definitely be welcome, but it would need to work for all scenarios.

I took a look at the attached PR and while it works for the cases you've highlighted, it does modify the geometry of holes, up to 10s of kilometres at a time - I don't think that would be acceptable for all use-cases.

We'll leave this issue open for now, more as a feature request than a bug-fix.

Doesn't work for complicated polygon (3.5k+ point polygon and 100-300 points for few holes) on the Android Maps Utils 0.5, Google Maps 11.0.4.
May be there are another ways to fix this issue until Google fix this? (This "bug" is 4 years old and it won't be fixed).
On IOS version polygon fills correctly

@SeijiIto @mathieu-pousse @stephenmcd @w3ggy @infinityb
Any update on this issues.

This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!

Closing this. Please reopen if you believe it should be addressed. Thank you for your contribution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vardaan picture vardaan  ·  6Comments

WeiLinJoe picture WeiLinJoe  ·  4Comments

syedalibumpin picture syedalibumpin  ·  5Comments

Slake07 picture Slake07  ·  3Comments

edumucelli picture edumucelli  ·  5Comments