Skip to content

Commit 563a99b

Browse files
authored
Fixed Colab Marker AwesomeIcon bug (#50)
1 parent 67c0549 commit 563a99b

File tree

1 file changed

+74
-32
lines changed

1 file changed

+74
-32
lines changed

samgeo/common.py

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
import matplotlib.pyplot as plt
1616

1717

18+
def is_colab():
19+
"""Tests if the code is being executed within Google Colab."""
20+
import sys
21+
22+
if "google.colab" in sys.modules:
23+
return True
24+
else:
25+
return False
26+
27+
1828
def check_file_path(file_path, make_dirs=True):
1929
"""Gets the absolute file path.
2030
@@ -1739,26 +1749,42 @@ def marker_callback(chooser):
17391749
coords = [[point.x, point.y] for point in centroids]
17401750
for coord in coords:
17411751
if plus_button.value:
1742-
marker = ipyleaflet.Marker(
1743-
location=[coord[1], coord[0]],
1744-
icon=ipyleaflet.AwesomeIcon(
1745-
name="plus-circle",
1746-
marker_color="green",
1747-
icon_color="darkred",
1748-
),
1749-
)
1752+
if is_colab(): # Colab does not support AwesomeIcon
1753+
marker = ipyleaflet.CircleMarker(
1754+
location=(coord[1], coord[0]),
1755+
radius=2,
1756+
color="green",
1757+
fill_color="green",
1758+
)
1759+
else:
1760+
marker = ipyleaflet.Marker(
1761+
location=[coord[1], coord[0]],
1762+
icon=ipyleaflet.AwesomeIcon(
1763+
name="plus-circle",
1764+
marker_color="green",
1765+
icon_color="darkred",
1766+
),
1767+
)
17501768
m.fg_layer.add(marker)
17511769
m.fg_markers.append(marker)
17521770
fg_count.value = len(m.fg_markers)
17531771
elif minus_button.value:
1754-
marker = ipyleaflet.Marker(
1755-
location=[coord[1], coord[0]],
1756-
icon=ipyleaflet.AwesomeIcon(
1757-
name="minus-circle",
1758-
marker_color="red",
1759-
icon_color="darkred",
1760-
),
1761-
)
1772+
if is_colab():
1773+
marker = ipyleaflet.CircleMarker(
1774+
location=(coord[1], coord[0]),
1775+
radius=2,
1776+
color="red",
1777+
fill_color="red",
1778+
)
1779+
else:
1780+
marker = ipyleaflet.Marker(
1781+
location=[coord[1], coord[0]],
1782+
icon=ipyleaflet.AwesomeIcon(
1783+
name="minus-circle",
1784+
marker_color="red",
1785+
icon_color="darkred",
1786+
),
1787+
)
17621788
m.bg_layer.add(marker)
17631789
m.bg_markers.append(marker)
17641790
bg_count.value = len(m.bg_markers)
@@ -1832,26 +1858,42 @@ def handle_map_interaction(**kwargs):
18321858
if kwargs.get("type") == "click":
18331859
latlon = kwargs.get("coordinates")
18341860
if radio_buttons.value == "Foreground":
1835-
marker = ipyleaflet.Marker(
1836-
location=latlon,
1837-
icon=ipyleaflet.AwesomeIcon(
1838-
name="plus-circle",
1839-
marker_color="green",
1840-
icon_color="darkred",
1841-
),
1842-
)
1861+
if is_colab():
1862+
marker = ipyleaflet.CircleMarker(
1863+
location=tuple(latlon),
1864+
radius=2,
1865+
color="green",
1866+
fill_color="green",
1867+
)
1868+
else:
1869+
marker = ipyleaflet.Marker(
1870+
location=latlon,
1871+
icon=ipyleaflet.AwesomeIcon(
1872+
name="plus-circle",
1873+
marker_color="green",
1874+
icon_color="darkred",
1875+
),
1876+
)
18431877
fg_layer.add(marker)
18441878
m.fg_markers.append(marker)
18451879
fg_count.value = len(m.fg_markers)
18461880
elif radio_buttons.value == "Background":
1847-
marker = ipyleaflet.Marker(
1848-
location=latlon,
1849-
icon=ipyleaflet.AwesomeIcon(
1850-
name="minus-circle",
1851-
marker_color="red",
1852-
icon_color="darkred",
1853-
),
1854-
)
1881+
if is_colab():
1882+
marker = ipyleaflet.CircleMarker(
1883+
location=tuple(latlon),
1884+
radius=2,
1885+
color="red",
1886+
fill_color="red",
1887+
)
1888+
else:
1889+
marker = ipyleaflet.Marker(
1890+
location=latlon,
1891+
icon=ipyleaflet.AwesomeIcon(
1892+
name="minus-circle",
1893+
marker_color="red",
1894+
icon_color="darkred",
1895+
),
1896+
)
18551897
bg_layer.add(marker)
18561898
m.bg_markers.append(marker)
18571899
bg_count.value = len(m.bg_markers)

0 commit comments

Comments
 (0)