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 = "
  • {}
  • \n".format( color, key @@ -3640,7 +3644,10 @@ def add_gps_trace( } self.add_legend(**legend_args) - if isinstance(list(colormap.values())[0], tuple): + if ( + isinstance(list(colormap.values())[0], tuple) + and len(list(colormap.values())[0]) == 2 + ): keys = list(colormap.keys()) values = [value[1] for value in colormap.values()] colormap = dict(zip(keys, values))