首页 > 解决方案 > Android Google Maps 支持 MultiPolygon 中的交叉点

问题描述

我尝试使用单个特征 MultiPolygon 在多边形孔内绘制多边形,如下所示:

在此处输入图像描述

但是,当我在 Android 上添加这个 GeoJson 文件时,背景没有得到满足,只有线条被绘制:

在此处输入图像描述

当我删除最内部的多边形时,它工作正常:

在此处输入图像描述

Google Maps SDK 是否以某种方式支持 MultiPolygons 上的交集?

遵循 GeoJson 文件:

{
    "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]
                    ]
                ]
            ]
        }
    }]
}

标签: androidgoogle-mapsgeojson

解决方案


带孔的GeoJSON "MultiPolygon"应具有如下结构:

{
    "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>]
        ]
    ]
}

所以,对于你的情况,“最内部的多边形”应该向上移动一级,GeoJSON 应该是这样的:

{
    "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]
                    ]
                  ]
            ]
        }
    }]
}

这种情况下的结果是:

在此处输入图像描述


推荐阅读