Hi
I tried to put "\n" and "br<>" to make a newline on Marker Popup. But they are not working. The letters are still in one line.
Could you tell me how to make a newline?
Thank you
If put popup = 'First Line
Second Line', it seems folium convert the text to First Line <br> Second Line, and pass it to leaflet. Therefore the leaflet can not recognize it. (leaflet do recognize
as newline).
A simple walk around for now: after you generate the html file, find the line of this popup text, and change the <br> to
, this should work to separate the lines in the popup. You can find the attached html file I generated, and I changed line 78.
Let me see if I can make some changes to it for long term solution.
It does seem there's a better solution discussed before in #332, and a related issue #294, using IFrame.
You can check out the following notebook made by @BibMartin:
http://nbviewer.jupyter.org/github/bibmartin/folium/blob/issue288/examples/Popups.ipynb
Hi Qingkai:
Your help are very useful to me, I would like to make a Html as @BibMartin
https://github.com/BibMartin:'s example.
My issue is solved
Thanks a lot .
Sincerely
Huanxin(Xavier)
On Thu, Jul 21, 2016 at 1:11 AM, Qingkai Kong [email protected]
wrote:
It does seem there's a better solution discussed before in #332
https://github.com/python-visualization/folium/issues/332, using
IFrame.You can check out the following notebook made by @BibMartin
https://github.com/BibMartin:http://nbviewer.jupyter.org/github/bibmartin/folium/blob/issue288/examples/Popups.ipynb
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/python-visualization/folium/issues/469#issuecomment-234158375,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC3reSoN193X9c0NfGvDL6-V2eCL5amvks5qXv9zgaJpZM4JPFtV
.
Thanks @qingkaikong!
You are welcome, and glad to help!
Although iFrame solves this problem, the lack of HTML formatting for a popup is annoying. An iframe can't to relative source linking, AFAIK. Here's a solution someone could add to folium if they cared:
from jinja2 import Template
popup_template = Template(u"""
var {{this.get_name()}} = L.popup({maxWidth: '{{this.max_width}}'});
{% for name, element in this.html._children.items() %}
var raw_html = String.raw`{{element.render(**kwargs).replace('\\n',' ')}}`
var {{name}} = $('<div/>').html(raw_html).text()
{{this.get_name()}}.setContent({{name}});
{% endfor %}
{{this._parent.get_name()}}.bindPopup({{this.get_name()}});
{% for name, element in this.script._children.items() %}
{{element.render()}}
{% endfor %}""") # noqa
html = """
<img width="{width}" height="{height}" src="{href}"><a href="{href}" target="_new">{href}</a>"""
popup = folium.Popup(html)
popup._template = popup_template
If someone takes this up, they should also add a class variable which store the raw string put into the jinja2 Template function
Here's a solution someone could add to folium if they cared:
We all care. However, folium is maintained by volunteers on their spare time, day jobs are always keeping us away from fun coding :wink:
Would you care to send a PR yourself?
@ocefpaf I appreciate all the work here. But you've closed all the issues mentioned here, which suggests these arn't problems. When I review the organization of this library, I don't find anything comfortable enough to suggest anything other than overrides and workarounds. I left the above so that anyone else google searching finds a more satisfying option than an iframe.
As the code I posited simply replaces the functionality that appears broken because, there's clearly an upstream issue waiting to be reviewed.
I suspect it's broken as the keyword "html" suggests you can input html, but in actuallity, it only takes raw strings. That's broken, is it not?
That's broken, is it not?
Only if you expect it to be HTML :wink:
The author of that code designed it to be raw strings, and the use of HTML via the IFrame. Hence the closed issue. I understand that it is convenient to add HTML directly, but I believe @BibMartin had a reason to do it this way.
Again, if you send a PR, we ca review and check how that goes with the rest of the functionality.
Hi guys,
I try to accomplish something like that in a popup,
popup = ('Time: '+ row.name.strftime('%H:%M')+ ' \nSpeed: '+ str(round(row['spd'],2))+' km/h'))
which doesnt work, and I cannot come up with idea how to insert variables into html = """...""" to use its <br>.
Is there a way to get it done?
You can try something like:
popup = (
"Time: {time}<br>"
"Speed: {speed} km/h<br>"
).format(time=row.name.strftime('%H:%M'),
speed=str(round(row['spd'],2)),
)
Thanks @BibMartin, that solved it!
using the .format() method did not work for me, for some reason, the
is being ignored. Here is what I have written:
for lt, ln, el, nm in zip(lat, lon, elev, volname):
fg.add_child(folium.Marker(location=[lat, lon])),
popup = (
"Elevation: {elev}</br>"
"Name: {volname}<br>"
).format(elev=str(el), volname=str(nm))
map.add_child(fg)
map.save("USA_Volcanoes_b.html")
It seems you're not adding the Popup to Marker. Also, is fg a feature group? You only have to add it to map once.
for lt, ln, el, nm in zip(lat, lon, elev, volname):
fg.add_child(folium.Marker(location=[lat, lon],
popup = (
"Elevation: {elev}<br>"
"Name: {volname}<br>"
).format(elev=str(el), volname=str(nm))))
map.add_child(fg)
Hi @Conengmo I am making a feature group (fg), I do have the popup inside of the folium.Marker code, thank you for letting me know I can take the map.add_child(fg) out of the loop
Most helpful comment
It does seem there's a better solution discussed before in #332, and a related issue #294, using IFrame.
You can check out the following notebook made by @BibMartin:
http://nbviewer.jupyter.org/github/bibmartin/folium/blob/issue288/examples/Popups.ipynb