Python地理地图可视化folium标记点弹窗设置代码(推荐)

python代码如下:

import webbrowser as wb
import folium
 
if __name__ == \'__main__\':
    loc = [30.679943, 104.067923]  # 成都中心位置经纬度
    map = folium.Map(location=loc,
                     zoom_start=11,
                     zoom_control=True,
                     tiles=\'OpenStreetMap\')  # 默认OpenStreetMap
 
    s1 = \'地理位置标记点上的弹出窗口,展示标记点数据内容\'
    s2 = \'zhang phil\'
    s3 = \'https://zhangphil.blog.csdn.net/\'
    WIDTH = max(len(s1.encode(\'utf-8\')), len(s2.encode(\'utf-8\')), len(s3.encode(\'utf-8\')))
    pop = folium.Popup(html=folium.Html(\"\"\"
                            {}</br>
                            {}</br>
                            {}</br>
                            \"\"\".format(s1, s2, s3),
                                        script=True,
                                        width=WIDTH * 4),
 
                       parse_html=True,
                       max_width=3000,
                       )
 
    # 添加一个标记,然后设置弹窗。
    folium.Marker(
        location=loc,
        popup=pop,
        tooltip=\"标记点\"
    ).add_to(map)
 
    map.save(\'map.html\')
    wb.open(\'map.html\')
 
# https://nbviewer.jupyter.org/github/python-visualization/folium/blob/master/examples/Popups.ipynb

输出结果如图:

Python地理地图可视化folium标记点弹窗设置代码(推荐)

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容