Skip to content

Commit

Permalink
Fix vector styling bug (#880)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Sep 1, 2024
1 parent 9142bd8 commit 74b403d
Showing 1 changed file with 48 additions and 20 deletions.
68 changes: 48 additions & 20 deletions leafmap/leafmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2628,7 +2628,7 @@ def add_shp(
style: Optional[Dict] = {},
hover_style: Optional[Dict] = {},
style_callback: Optional[Callable] = None,
fill_colors: Optional[list[str]] = ["black"],
fill_colors: Optional[list[str]] = None,
info_mode: Optional[str] = "on_hover",
zoom_to_layer: Optional[bool] = False,
encoding: Optional[str] = "utf-8",
Expand Down Expand Up @@ -3072,19 +3072,25 @@ def add_kml(
style: Optional[dict] = {},
hover_style: Optional[dict] = {},
style_callback: Optional[Callable] = None,
fill_colors: Optional[list[str]] = ["black"],
fill_colors: Optional[list[str]] = None,
info_mode: Optional[str] = "on_hover",
) -> None:
"""Adds a KML file to the map.
Args:
in_kml (str): The input file path or HTTP URL to the KML.
layer_name (str, optional): The layer name to be used.. Defaults to "Untitled".
style (dict, optional): A dictionary specifying the style to be used. Defaults to {}.
style (dict, optional): A dictionary specifying the style to be used.
Defaults to {}.
hover_style (dict, optional): Hover style dictionary. Defaults to {}.
style_callback (function, optional): Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None.
fill_colors (list, optional): The random colors to use for filling polygons. Defaults to ["black"].
info_mode (str, optional): Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover".
style_callback (function, optional): Styling function that is called
for each feature, and should return the feature style. This
styling function takes the feature as argument. Defaults to None.
fill_colors (list, optional): The random colors to use for filling
polygons. Defaults to ["black"].
info_mode (str, optional): Displays the attributes by either on_hover
or on_click. Any value other than "on_hover" or "on_click" will
be treated as None. Defaults to "on_hover".
Raises:
FileNotFoundError: The provided KML file could not be found.
Expand Down Expand Up @@ -3122,7 +3128,7 @@ def add_vector(
style: Optional[dict] = {},
hover_style: Optional[dict] = {},
style_callback: Optional[Callable] = None,
fill_colors: list[str] = ["black"],
fill_colors: list[str] = None,
info_mode: Optional[str] = "on_hover",
zoom_to_layer: Optional[bool] = False,
encoding: Optional[str] = "utf-8",
Expand All @@ -3131,16 +3137,32 @@ def add_vector(
"""Adds any geopandas-supported vector dataset to the map.
Args:
filename (str): Either the absolute or relative path to the file or URL to be opened, or any object with a read() method (such as an open file or StringIO).
filename (str): Either the absolute or relative path to the file or
URL to be opened, or any object with a read() method (such as
an open file or StringIO).
layer_name (str, optional): The layer name to use. Defaults to "Untitled".
bbox (tuple | GeoDataFrame or GeoSeries | shapely Geometry, optional): Filter features by given bounding box, GeoSeries, GeoDataFrame or a shapely geometry. CRS mis-matches are resolved if given a GeoSeries or GeoDataFrame. Cannot be used with mask. Defaults to None.
mask (dict | GeoDataFrame or GeoSeries | shapely Geometry, optional): Filter for features that intersect with the given dict-like geojson geometry, GeoSeries, GeoDataFrame or shapely geometry. CRS mis-matches are resolved if given a GeoSeries or GeoDataFrame. Cannot be used with bbox. Defaults to None.
rows (int or slice, optional): Load in specific rows by passing an integer (first n rows) or a slice() object.. Defaults to None.
style (dict, optional): A dictionary specifying the style to be used. Defaults to {}.
bbox (tuple | GeoDataFrame or GeoSeries | shapely Geometry, optional):
Filter features by given bounding box, GeoSeries, GeoDataFrame or
a shapely geometry. CRS mis-matches are resolved if given a
GeoSeries or GeoDataFrame. Cannot be used with mask. Defaults to None.
mask (dict | GeoDataFrame or GeoSeries | shapely Geometry, optional):
Filter for features that intersect with the given dict-like geojson
geometry, GeoSeries, GeoDataFrame or shapely geometry. CRS mis-matches
are resolved if given a GeoSeries or GeoDataFrame. Cannot be used with bbox.
Defaults to None.
rows (int or slice, optional): Load in specific rows by passing an
integer (first n rows) or a slice() object.. Defaults to None.
style (dict, optional): A dictionary specifying the style to be used.
Defaults to {}.
hover_style (dict, optional): Hover style dictionary. Defaults to {}.
style_callback (function, optional): Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None.
fill_colors (list, optional): The random colors to use for filling polygons. Defaults to ["black"].
info_mode (str, optional): Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover".
style_callback (function, optional): Styling function that is called
for each feature, and should return the feature style. This
styling function takes the feature as argument. Defaults to None.
fill_colors (list, optional): The random colors to use for filling polygons.
Defaults to ["black"].
info_mode (str, optional): Displays the attributes by either on_hover
or on_click. Any value other than "on_hover" or "on_click" will
be treated as None. Defaults to "on_hover".
encoding (str, optional): The encoding to use to read the file. Defaults to "utf-8".
"""
Expand Down Expand Up @@ -5570,19 +5592,25 @@ def geojson_layer(
style: Optional[dict] = {},
hover_style: Optional[dict] = {},
style_callback: Optional[Callable] = None,
fill_colors: Optional[list[str]] = ["black"],
fill_colors: Optional[list[str]] = None,
encoding: Optional[str] = "utf-8",
) -> None:
"""Adds a GeoJSON file to the map.
Args:
in_geojson (str | dict): The file path or http URL to the input GeoJSON or a dictionary containing the geojson.
in_geojson (str | dict): The file path or http URL to the input GeoJSON
or a dictionary containing the geojson.
layer_name (str, optional): The layer name to be used.. Defaults to "Untitled".
style (dict, optional): A dictionary specifying the style to be used. Defaults to {}.
hover_style (dict, optional): Hover style dictionary. Defaults to {}.
style_callback (function, optional): Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None.
fill_colors (list, optional): The random colors to use for filling polygons. Defaults to ["black"].
info_mode (str, optional): Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover".
style_callback (function, optional): Styling function that is called for
each feature, and should return the feature style. This styling
function takes the feature as argument. Defaults to None.
fill_colors (list, optional): The random colors to use for filling polygons.
Defaults to ["black"].
info_mode (str, optional): Displays the attributes by either on_hover or
on_click. Any value other than "on_hover" or "on_click" will be
treated as None. Defaults to "on_hover".
encoding (str, optional): The encoding of the GeoJSON file. Defaults to "utf-8".
Raises:
Expand Down

0 comments on commit 74b403d

Please sign in to comment.