Skip to content

Commit 8e30645

Browse files
Allow to send options directly as str for vector tiles (#702)
* Allow to send options directly as str * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent dd2da39 commit 8e30645

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

leafmap/foliumap.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -3024,8 +3024,7 @@ def add_text(
30243024
def add_vector_tile(
30253025
self,
30263026
url: Optional[str],
3027-
attribution: Optional[str] = "",
3028-
styles: Optional[dict] = {},
3027+
styles: Optional[Union[dict, str]] = {},
30293028
layer_name: Optional[str] = "Vector Tile",
30303029
**kwargs,
30313030
):
@@ -3036,22 +3035,26 @@ def add_vector_tile(
30363035
url (str, optional): The URL of the tile layer, such as
30373036
'https://tile.nextzen.org/tilezen/vector/v1/512/all/{z}/{x}/{y}.mvt?api_key=gCZXZglvRQa6sB2z7JzL1w'.
30383037
attribution (str, optional): The attribution to use. Defaults to ''.
3039-
styles (dict,optional): Style dict, specific to the vector tile source.
3038+
styles (dict | str, optional): Style dict, specific to the vector tile source.
3039+
If styles is given as a string, it will be passed directly to folium.plugins.VectorGrid
3040+
directly, ignoring additional kwargs. See the "conditional styling" example in
3041+
https://github.com/iwpnd/folium-vectorgrid
30403042
layer_name (str, optional): The layer name to use for the layer. Defaults to 'Vector Tile'.
3041-
kwargs: Additional keyword arguments to pass to the ipyleaflet.VectorTileLayer class.
3043+
kwargs: Additional keyword arguments to pass to the folium.plugins.VectorGridProtobuf class.
30423044
"""
3045+
if isinstance(styles, str):
3046+
options = styles
3047+
else:
3048+
options = {}
3049+
for key, value in kwargs.items():
3050+
options[key] = value
30433051

3044-
options = {}
3045-
3046-
for key, value in kwargs.items():
3047-
options[key] = value
3048-
3049-
if "vector_tile_layer_styles" in options:
3050-
styles = options["vector_tile_layer_styles"]
3051-
del options["vector_tile_layer_styles"]
3052+
if "vector_tile_layer_styles" in options:
3053+
styles = options["vector_tile_layer_styles"]
3054+
del options["vector_tile_layer_styles"]
30523055

3053-
if styles:
3054-
options["vectorTileLayerStyles"] = styles
3056+
if styles:
3057+
options["vectorTileLayerStyles"] = styles
30553058

30563059
vc = plugins.VectorGridProtobuf(url, layer_name, options)
30573060
self.add_child(vc)

0 commit comments

Comments
 (0)