简体   繁体   English

如何使用python folium标记保存自定义信息?

[英]How to use python folium marker save custom information?

I currently have some information like images, videos, I want to save them into the folium marker.我目前有一些信息,如图像、视频,我想将它们保存到 folium 标记中。

I am not quite sure how to add that information into this:我不太确定如何将该信息添加到此:

image = "sample.png"

folium.Marker(location = [lat, long], ??, ??).add_to(current_map)

Is there any way to achieve that?有什么方法可以实现吗? Thank you!谢谢!

To save an image to a folium marker, the target image needs to be converted by base64.要将图像保存到 folium 标记,目标图像需要通过 base64 进行转换。 The converted image is then converted into an IFrame that can be displayed on the web.然后将转换后的图像转换为可以在 Web 上显示的 IFrame。 For other marker customization, please refer to the official reference .其他marker定制请参考官方参考

import folium
import base64
from folium import IFrame

logo_png = './data/logo-stackoverflow_resize.png'
encoded = base64.b64encode(open(logo_png, 'rb').read()).decode()

lat, lon = 40.70896, -74.00680
m = folium.Map(location=[lat, lon], zoom_start=15)

html = '<img src="data:image/png;base64,{}">'.format
iframe = IFrame(html(encoded), width=311+20, height=62+20)
popup = folium.Popup(iframe, max_width=400)

icon = folium.Icon(color="red", icon="ok")
marker = folium.Marker(location=[lat, lon], popup=popup, icon=icon)
marker.add_to(m)

m

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM