Python 如何使用JSON文件使用folium显示工具提示?
我想在地图上悬停时显示国家名称。我使用JSON文件表示国家坐标。以下是我的python代码:Python 如何使用JSON文件使用folium显示工具提示?,python,json,leaflet,data-visualization,folium,Python,Json,Leaflet,Data Visualization,Folium,我想在地图上悬停时显示国家名称。我使用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}/{
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.geojsontoltip(fields=[“name”])出现错误。添加到(g)
我从字段名中知道,但不知道正确的字段名是什么:(
以下是一些JSON文件的图片。我需要知道在地图上显示这些国家的名称的位置:
需要获取geojson文件(而不是json) 我进去了 调整后的代码为:
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')
仅更改geojson文件的位置。。。。