diff --git a/leafmap/maplibregl.py b/leafmap/maplibregl.py index 81c8ee321f..c67460164e 100644 --- a/leafmap/maplibregl.py +++ b/leafmap/maplibregl.py @@ -2760,7 +2760,11 @@ def add_legend( if isinstance(colors[0], tuple) and len(colors[0]) == 2: labels = [color[0] for color in colors] colors = [color[1] for color in colors] - + if all(isinstance(item, tuple) for item in colors): + try: + colors = [common.rgb_to_hex(x) for x in colors] + except Exception as e: + print(e) allowed_positions = [ "top-left", "top-right", @@ -2787,7 +2791,7 @@ def add_legend( for index, key in enumerate(labels): color = colors[index] - if not color.startswith("#"): + if isinstance(color, str) and (not color.startswith("#")): color = "#" + color item = "