Skip to content

Commit

Permalink
Fix legend bug (opengeos#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Nov 21, 2024
1 parent 3f2982c commit 6364168
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions leafmap/maplibregl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 = " <li><span style='background:{};'></span>{}</li>\n".format(
color, key
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 6364168

Please sign in to comment.