diff --git a/folium/features.py b/folium/features.py index 65b6da9475..eaa4cd55d0 100644 --- a/folium/features.py +++ b/folium/features.py @@ -1053,9 +1053,12 @@ def recursive_get(data, keys): else: return data - geometries = recursive_get(self.data, self.object_path.split("."))[ - "geometries" - ] # noqa + geometry = recursive_get(self.data, self.object_path.split(".")) + geometries = ( + geometry["geometries"] + if geometry["type"] == "GeometryCollection" + else [geometry] + ) for feature in geometries: feature.setdefault("properties", {}).setdefault("style", {}).update( self.style_function(feature) diff --git a/tests/test_features.py b/tests/test_features.py index ecb5398f81..7b3c20ff06 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -17,6 +17,27 @@ from folium.utilities import JsCode +@pytest.mark.parametrize("geometry_type", ["Polygon", "MultiPolygon"]) +def test_topojson_non_collection_geometry(geometry_type): + """TopoJson supports objects that are not GeometryCollections.""" + topology = { + "type": "Topology", + "objects": { + "shape": { + "type": geometry_type, + "arcs": [[0]] if geometry_type == "Polygon" else [[[0]]], + } + }, + "arcs": [[[0, 0], [1, 0], [0, 1], [-1, -1]]], + "transform": {"scale": [1, 1], "translate": [0, 0]}, + } + + map_ = folium.Map() + folium.TopoJson(topology, "objects.shape").add_to(map_) + + assert "topojson.feature" in map_.get_root().render() + + @pytest.fixture def tmpl(): yield ("""