传单地图中的多边形叠加

Polygon overlay in leaflet map

我正在使用 ipyleaflet 使用以下代码创建交互式地图:

from ipyleaflet import Map, Polygon


polygon = Polygon(
    locations=[[(38.844185,-4.804621),(39.241299,-1.899833),(40.74308,-2.205491),(40.34742,-5.17429),(38.844185,-4.804621)],[(39.365192,-1.941078),(40.867912,-1.567062),(41.276688,-4.670904),(39.775406,-4.976737),(39.365192,-1.941078)],[(39.706161,-1.849863),(41.207623,-1.465817),(41.617561,-4.594476),(40.117233,-4.908839),(39.706161,-1.849863)],[(39.702591,-5.033657),(40.101254,-2.077048),(41.602196,-2.389729),(41.204681,-5.413605),(39.702591,-5.033657)]],
    color="green",
    fill_opacity= 0.5,
    fill_color="green"
)

m = Map(center=(38.5531, -4.6914), zoom=6)
m.add_layer(polygon);

m

输出看起来像这样:

我想知道如何使多边形的交点不完全透明。查看文档中的属性 https://ipyleaflet.readthedocs.io/en/latest/api_reference/polygon.html,我没有看到任何选项?

下图中可以看到所需输出的示例:

你得到了不好的结果,因为 ipyleaflet 减去了卵形多边形(你可以在你发布的文档 link 的第二个例子中看到它,"Polygon with hole")

您需要分别添加每个多边形,我稍微更改了您的代码,现在它循环创建和应用多边形:

from ipyleaflet import Map, Polygon

poligons = [[(38.844185,-4.804621),(39.241299,-1.899833),(40.74308,-2.205491),(40.34742,-5.17429),(38.844185,-4.804621)],
            [(39.365192,-1.941078),(40.867912,-1.567062),(41.276688,-4.670904),(39.775406,-4.976737),(39.365192,-1.941078)],
            [(39.706161,-1.849863),(41.207623,-1.465817),(41.617561,-4.594476),(40.117233,-4.908839),(39.706161,-1.849863)],
            [(39.702591,-5.033657),(40.101254,-2.077048),(41.602196,-2.389729),(41.204681,-5.413605),(39.702591,-5.033657)]]

m = Map(center=(38.5531, -4.6914), zoom=6)

for poly in poligons:
    polygon = Polygon(
        locations= poly,
        color="green",
        fill_opacity= 0.5,
        fill_color="green"
    )
    m.add_layer(polygon);

m

结果: