在folium中更改弹出窗口的背景颜色是否可行?

3

我想要改变弹出窗口的背景颜色。

我尝试了许多方法,但都没有成功。根据我的研究,我怀疑我需要进入leaflet的css中来改变背景颜色,但我不确定如何做到这一点。

这是我正在使用的函数:

def MapCircle(data_set_index):
"""
:param data_set_index: Takes input of the index that contains the relevant data needed to plot each point on
the map.
:return: returns the plots on the map.
"""
html_popup = folium.Html(**'''
<!doctype html>
<html>

<h1 style='color: red;'>{country}
<body style='color: blue;'>
</h1>
<br/>

<h1>
Cases: {cases}
</h1>
<br/>

<h1> 
New Cases: {newcases}
</h1>
<br/>

</body>
</html>
'''**.format(country=data_set_index[3], cases=data_set_index[4],
                                               newcases=data_set_index[2]), script=True)

popup_settings = folium.Popup(html_popup, max_width=300, min_width=200)

folium.Circle(location=[data_set_index[0], data_set_index[1]],
              radius=80000, color='#C03A3A', fill=True,
              popup=popup_settings).add_to(world_map)

我尝试了类似于以下的CSS字符串,但当然我不能通过它...

<style> .leaflet-popup-content-wrapper {background-color:black; color:white} </style>

非常感谢您的咨询!如果您在使用Python中的folium遇到了问题,我可以为您提供帮助。请问您需要什么样的指导呢?另外,以下是您提供的图片链接:enter image description here
2个回答

3

虽然不是最终解决方案,但您可以使用IFrame()的功能作为一种解决方法:

import folium

m = folium.Map(location=[-25.274398, 133.775136],
               zoom_start=4)

html = '''<body style="background-color:pink;"><p style="color:red;">Australia</p>
<p>Cases: 8,886</p>
<p>New Cases: +131</p></body>'''

iframe = folium.IFrame(html,
                       width=200,
                       height=120)

popup = folium.Popup(iframe)

marker = folium.Marker([-25.274398, 133.775136],
                       popup=popup).add_to(m)
m

你会得到:

输入图像描述


1
这不完全是我想要的,但非常有帮助,比我之前拥有的好多了!谢谢。 - Jordan

0

可能对@Zeevex来说有点晚了,但如果其他人像我一样到达了这里

html_to_insert = "<style>.leaflet-popup-content-wrapper, .leaflet-popup.tip {background-color: #000 !important; }</style>"

map_.get_root().header.add_child(folium.Element(html_to_insert))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接