|
15 | 15 | import matplotlib.pyplot as plt |
16 | 16 |
|
17 | 17 |
|
| 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 | + |
18 | 28 | def check_file_path(file_path, make_dirs=True): |
19 | 29 | """Gets the absolute file path. |
20 | 30 |
|
@@ -1739,26 +1749,42 @@ def marker_callback(chooser): |
1739 | 1749 | coords = [[point.x, point.y] for point in centroids] |
1740 | 1750 | for coord in coords: |
1741 | 1751 | 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 | + ) |
1750 | 1768 | m.fg_layer.add(marker) |
1751 | 1769 | m.fg_markers.append(marker) |
1752 | 1770 | fg_count.value = len(m.fg_markers) |
1753 | 1771 | 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 | + ) |
1762 | 1788 | m.bg_layer.add(marker) |
1763 | 1789 | m.bg_markers.append(marker) |
1764 | 1790 | bg_count.value = len(m.bg_markers) |
@@ -1832,26 +1858,42 @@ def handle_map_interaction(**kwargs): |
1832 | 1858 | if kwargs.get("type") == "click": |
1833 | 1859 | latlon = kwargs.get("coordinates") |
1834 | 1860 | 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 | + ) |
1843 | 1877 | fg_layer.add(marker) |
1844 | 1878 | m.fg_markers.append(marker) |
1845 | 1879 | fg_count.value = len(m.fg_markers) |
1846 | 1880 | 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 | + ) |
1855 | 1897 | bg_layer.add(marker) |
1856 | 1898 | m.bg_markers.append(marker) |
1857 | 1899 | bg_count.value = len(m.bg_markers) |
|
0 commit comments