Skip to content

Commit

Permalink
Allow to send options directly as str for vector tiles (#702)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
lopezvoliver and pre-commit-ci[bot] authored Mar 13, 2024
1 parent dd2da39 commit 8e30645
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions leafmap/foliumap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3024,8 +3024,7 @@ def add_text(
def add_vector_tile(
self,
url: Optional[str],
attribution: Optional[str] = "",
styles: Optional[dict] = {},
styles: Optional[Union[dict, str]] = {},
layer_name: Optional[str] = "Vector Tile",
**kwargs,
):
Expand All @@ -3036,22 +3035,26 @@ def add_vector_tile(
url (str, optional): The URL of the tile layer, such as
'https://tile.nextzen.org/tilezen/vector/v1/512/all/{z}/{x}/{y}.mvt?api_key=gCZXZglvRQa6sB2z7JzL1w'.
attribution (str, optional): The attribution to use. Defaults to ''.
styles (dict,optional): Style dict, specific to the vector tile source.
styles (dict | str, optional): Style dict, specific to the vector tile source.
If styles is given as a string, it will be passed directly to folium.plugins.VectorGrid
directly, ignoring additional kwargs. See the "conditional styling" example in
https://github.com/iwpnd/folium-vectorgrid
layer_name (str, optional): The layer name to use for the layer. Defaults to 'Vector Tile'.
kwargs: Additional keyword arguments to pass to the ipyleaflet.VectorTileLayer class.
kwargs: Additional keyword arguments to pass to the folium.plugins.VectorGridProtobuf class.
"""
if isinstance(styles, str):
options = styles
else:
options = {}
for key, value in kwargs.items():
options[key] = value

options = {}

for key, value in kwargs.items():
options[key] = value

if "vector_tile_layer_styles" in options:
styles = options["vector_tile_layer_styles"]
del options["vector_tile_layer_styles"]
if "vector_tile_layer_styles" in options:
styles = options["vector_tile_layer_styles"]
del options["vector_tile_layer_styles"]

if styles:
options["vectorTileLayerStyles"] = styles
if styles:
options["vectorTileLayerStyles"] = styles

vc = plugins.VectorGridProtobuf(url, layer_name, options)
self.add_child(vc)
Expand Down

0 comments on commit 8e30645

Please sign in to comment.