From 01f9055c45d2ec87398422a356376405a1f1cfca Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Sat, 21 Sep 2024 21:22:43 -0400 Subject: [PATCH] Fix add_geojson style callback bug (#898) * Fix add_geojson style callback bug * Fix folium style callback bug --- leafmap/foliumap.py | 9 +++++---- leafmap/leafmap.py | 17 +++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/leafmap/foliumap.py b/leafmap/foliumap.py index dbb0a2523f..f33e986bea 100644 --- a/leafmap/foliumap.py +++ b/leafmap/foliumap.py @@ -1449,6 +1449,10 @@ def add_geojson( raise Exception(e) # interchangeable parameters between ipyleaflet and folium. + + if "style_callback" in kwargs: + kwargs["style_function"] = kwargs.pop("style_callback") + style_dict = {} if "style_function" not in kwargs: if "style" in kwargs: @@ -1456,7 +1460,7 @@ def add_geojson( if isinstance(kwargs["style"], dict) and len(kwargs["style"]) > 0: kwargs["style_function"] = lambda x: style_dict kwargs.pop("style") - else: + elif "fill_colors" not in kwargs: style_dict = { # "stroke": True, "color": "#3388ff", @@ -1470,9 +1474,6 @@ def add_geojson( } kwargs["style_function"] = lambda x: style_dict - if "style_callback" in kwargs: - kwargs.pop("style_callback") - if "hover_style" in kwargs: kwargs.pop("hover_style") diff --git a/leafmap/leafmap.py b/leafmap/leafmap.py index 801174b36c..df80a971e7 100644 --- a/leafmap/leafmap.py +++ b/leafmap/leafmap.py @@ -2630,10 +2630,10 @@ def add_geojson( import random import requests - style_callback_only = False + # style_callback_only = False - if fill_colors is not None: - style_callback_only = True + # if fill_colors is not None: + # style_callback_only = True try: if isinstance(in_geojson, str): @@ -2670,7 +2670,7 @@ def add_geojson( geom_type = get_geometry_type(data) - if not style: + if style is None and (style_callback is None): style = { # "stroke": True, "color": "#3388ff", @@ -2779,23 +2779,20 @@ def update_html(feature, fields=fields, **kwargs): if fill_colors is not None: style_callback = random_color - if style_callback_only: + if style_callback is None: geojson = ipyleaflet.GeoJSON( data=data, + style=style, hover_style=hover_style, - style_callback=style_callback, name=layer_name, ) else: - kwargs = {} - if style_callback is not None: - kwargs["style_callback"] = style_callback geojson = ipyleaflet.GeoJSON( data=data, style=style, hover_style=hover_style, name=layer_name, - **kwargs, + style_callback=style_callback, ) if info_mode == "on_hover":