【问题标题】:How to show tooltip using folium using JSON file?如何使用 JSON 文件使用 folium 显示工具提示?
【发布时间】:2021-05-02 18:09:43
【问题描述】:

当我将鼠标悬停在地图上时,我想显示国家名称。我正在使用 JSON 文件作为国家坐标。这是我的python代码:

import folium
 

m = folium.Map(location=[47.516232 , 47.516232],
           zoom_start=5,
           tiles='https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
           attr='My Data Attribution')


geoJson = r'/Users/bader/Desktop/pandaTable/european-union-countries.json'

g = folium.GeoJson(

    geoJson,
    name='geoJson').add_to(m)

folium.GeoJsonToolTip(fields=["name"]).add_to(g)


m.save('map.html')

我收到这条线的错误folium.GeoJsonToolTip(fields=["name"]).add_to(g) 我从字段名称中知道它,但我不知道正确的字段名称是什么:(

这是 JSON 文件的一些图片。我需要知道国家名称在哪里才能在地图上显示:The beginning of json code

Each several lines there is smilier code like this

Here is the map pic of EU countries

【问题讨论】:

    标签: python json leaflet data-visualization folium


    【解决方案1】:

    需要获取geojson文件(不是json)...

    我进入https://data.opendatasoft.com/explore/dataset/european-union-countries@public/export/

    而调整后的代码是:

    import folium
    
    m = folium.Map(
        location=[47.516232 , 47.516232],
        zoom_start=5,
        tiles='https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
        attr='My Data Attribution'
    )
    
    folium.GeoJson(
        #r'/Users/bader/Desktop/pandaTable/european-union-countries.json',
        '/home/michel/Downloads/european-union-countries.geojson',    
        name='geoJson',
        tooltip=folium.features.GeoJsonTooltip(
            fields=['name_sort', 'gu_a3'],
            aliases=['Name', 'Code'],
            sticky=True,
            opacity=0.9,
            direction='right',
        ),
    ).add_to(m)
    
    m.save('map.html')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      相关资源
      最近更新 更多