Open rl-utility-man opened 9 months ago
@rl-utility-man I managed to reproduce the error. The issue seems to be that there is a parent-child relationship between the Marker
and the Icon
. Since each child can have only one parent (in this context at least) the code breaks. Are you still willing to help fix this?
A possible solution would be to add a clone()
method to Icon
and make a clone inside Marker. __init__
.
Thanks @hansthen! Yes, I can take a look at a fix along the lines you recommend and either issue a pull request or circle back with questions. Give me a week or two.
Duplicate of https://github.com/python-visualization/folium/issues/744 it seems. I'll leave this one open since we have more recent discussion here.
Describe the bug
If I pass the same object reference to Marker twice, it fails cryptically, but if I pass two distinct but identical objects to Marker, it succeeds
If I create one marker containing a variable that contains a DivIcon with an svg image tag, it works. If I add a second marker containing a different svg image tag -- even if the code underlying the divicon is identical, it will also work (see the left panel). But if I create a second marker containing the same svg icon variable, both of the icons fail (see the right panel).
For now, a viable workaround seems to be to avoid creating an icon variable and instead to just use:
I suspect based on some struggles I've had in the last few days, but have not confirmed, that this affects font-awesome DivIcons as well.
To Reproduce
I think the problem is in the following section of output: Here is the last section of output for the working version:
Here is the last section of output for the failing version:
Expected behavior
Using one variable pointing at an svg icon variable in multiple maps should work. In other words, both maps should work.
The behavior should be the same and correct regardless of whether you specify
or
Right now, specifying
folium.Marker(...icon=icon...)
repeatedly will fail, but repeatingfolium.Marker(...icon=folium.DivIcon(...
works.Environment (please complete the following information):
Additional context Add any other context about the problem here.
Possible solutions List any solutions you may have come up with.
folium is maintained by volunteers. Can you help making a fix for this issue?
Yes, I can try to help. Are these the relevant sections of code? https://github.com/python-visualization/folium/blob/226ba52c7e94850859a8bc6a23d8035e56f3c97e/folium/map.py#L363 https://github.com/python-visualization/branca/blob/f3d866f598a194f9acd30e24e1affe52a32a9f05/branca/element.py#L129
The SVG icon I saved locally and used is: