diff --git a/leafmap/foliumap.py b/leafmap/foliumap.py index 9dd054438d..febbbb59ee 100644 --- a/leafmap/foliumap.py +++ b/leafmap/foliumap.py @@ -1235,7 +1235,11 @@ def random_color(feature): tooltip = None popup = None if info_mode is not None: - props = list(data["features"][0]["properties"].keys()) + if "fields" in kwargs: + props = kwargs["fields"] + kwargs.pop("fields") + else: + props = list(data["features"][0]["properties"].keys()) if info_mode == "on_hover": tooltip = folium.GeoJsonTooltip(fields=props) elif info_mode == "on_click": @@ -2435,6 +2439,7 @@ def add_data( highlight_function = lambda feat: {"fillColor": feat["properties"]["color"]} 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". + **kwargs: Additional keyword arguments to pass to the GeoJSON class, such as fields, which can be a list of column names to be included in the popup. """ import warnings diff --git a/leafmap/leafmap.py b/leafmap/leafmap.py index 442632154c..79094cd878 100644 --- a/leafmap/leafmap.py +++ b/leafmap/leafmap.py @@ -2137,6 +2137,7 @@ def add_geojson( fill_colors=["black"], info_mode="on_hover", encoding="utf-8", + **kwargs, ): """Adds a GeoJSON file to the map. @@ -2276,12 +2277,23 @@ def close_btn_click(change): close_button.observe(close_btn_click, "value") - def update_html(feature, **kwargs): + if "fields" in kwargs: + fields = kwargs["fields"] + kwargs.pop("fields") + else: + fields = None + + def update_html(feature, fields=fields, **kwargs): + + if fields is None: + fields = list(feature["properties"].keys()) + if "style" in fields: + fields.remove("style") value = [ "{}: {}
".format(prop, feature["properties"][prop]) - for prop in feature["properties"].keys() - ][:-1] + for prop in fields + ] value = """{}""".format("".join(value)) html.value = value @@ -2362,6 +2374,7 @@ def add_gdf( info_mode="on_hover", zoom_to_layer=True, encoding="utf-8", + **kwargs ): """Adds a GeoDataFrame to the map. @@ -2388,6 +2401,7 @@ def add_gdf( fill_colors, info_mode, encoding, + **kwargs, ) if zoom_to_layer: @@ -3549,6 +3563,8 @@ def add_data( style_callback = lambda feat: {"fillColor": feat["properties"]["color"]} 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". + **kwargs: Additional keyword arguments to pass to the GeoJSON class, such as fields, which can be a list of column names to be included in the popup. + """ gdf, legend_dict = classify(