-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DivIcon transparent background #798
Comments
I'm using these two cells for now as a workaround: %%html
<style>
.leaflet-div-icon { background-color: transparent; border-color: transparent }
</style> from ipyleaflet import DivIcon, Map, Marker
m = Map(center=(0, 0), zoom=1)
w, h = 32, 32
html = f'<img src="https://simpleicons.org/icons/apple.svg" width="{w}" height="{h}"/>'
icon = DivIcon(html=html, bg_pos=(0, 0), icon_size=[w, h])
apple_loc = (37.3351901, -122.0114123)
mark = Marker(location=apple_loc, icon=icon, draggable=True)
m.add_layer(mark)
m |
@deeplook Thank you for sharing the workaround. The html magic command will only work in Jupyter notebook. To integrate this into leafmap, we need a workaround that works in a Python script. |
You could maybe import |
@deeplook Do you have the sample code for this? I am trying to integrate this into geemap for labeling features. gee-community/geemap#815 |
@giswqs It took some time to undust it, but yes! Here it is cell by cell. I hope it's useful: import requests
from ipyleaflet import basemaps, DivIcon, GeoJSON, Map, Marker
from IPython.display import HTML
from shapely.geometry import shape # Workaround for cleaning the icon background (must be on a separate cell):
HTML("""<style>
.leaflet-div-icon { background-color: transparent; border-color: transparent }
</style>""") m = Map(center=([53.33, 7.25]), zoom=3.5, basemap=basemaps.CartoDB.Positron)
url = "https://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json"
data = requests.get(url).json()
data2 = {feat["id"]: feat["geometry"] for feat in data["features"]}
w, h = 32, 32
url_base = "https://upload.wikimedia.org/wikipedia/en"
for cc3 in 'GBR ALB EST LTU LVA UKR BLR CHE AUT SVN SVK SRB BGR CZE BIH NOR ISL GRC HRV MKD MDA SWE ESP DEU DNK BEL LUX NLD FRA ITA ROU POL HUN PRT FIN IRL'.split():
geometry = data2[cc3]
sh = shape(geometry)
lat, lon = (61.81, 9.05) if cc3 == "NOR" else (sh.centroid.y, sh.centroid.x)
url = (url_base + "/b/be/Flag_of_England.svg") if cc3 == "GBR" else (url_base + "/0/03/Flag_of_Italy.svg")
html = f'<img src="{url}" width="{w}" height="{h}"/>'
icon = DivIcon(html=html, bg_pos=(0, 0), icon_size=[w, h])
m.add_layer(Marker(location=(lat, lon), icon=icon, draggable=False))
m += GeoJSON(data=geometry, style={"fill": None})
m.layout.height = "550px"
m |
@deeplook Great! Thanks for sharing. I will try it out. |
My pleasure! |
This has been implemented in leafmap. See notebook example https://leafmap.org/notebooks/36_add_labels |
If you don't mind, we could keep this issue open until this is properly implemented in ipyleaflet 😊 |
@martinRenou Do you know if any solution has been worked on? I am having same issue until now. |
The DivIcon has a white background. Is it possible to make it transparent? Thanks.
Relevant issue: #792 @deeplook
The text was updated successfully, but these errors were encountered: