我尝试使用python3
和folium
在pandas
中构建一个Web地图应用程序,其中我尝试读取一个excel
文件(名称-{{1} }(含04张),并使用图层控件对其进行绘制。
我的代码如下:
vessels_data.xlsx
我在命令行中没有出现任何错误,并且该位置显示了import folium
import pandas
map = folium.Map(location = [10,74], zoom_start= 4, tiles= 'Mapbox Bright')
fg = folium.FeatureGroup(name = "big_vessel")
fg2 = folium.FeatureGroup(name = "medium_vessel")
fg3 = folium.FeatureGroup(name = "trawlers")
fg4 = folium.FeatureGroup(name = "fishing_boats")
db = pandas.read_excel("vessel_data.xlsx", sheet_name = 0)
lat = list(db['lat'])
lon = list(db['long'])
name = list(db['name'])
time = list(db['time'])
for i_lat, i_lon, i_name in zip(lat, lon, name):
fg.add_child(folium.CircleMarker(location =[i_lat, i_lon],radius=6, popup=str(name), fill_color= 'red', fill = True, color = 'red', fill_opacity = 0.7 ))
db2 = pandas.read_excel("vessel_data.xlsx", sheet_name = 1)
lat2 = list(db2['lat'])
lon2 = list(db2['long'])
name2 = list(db2['name'])
time2 = list(db2['time'])
for i_lat, i_lon, i_name in zip(lat2, lon2, name2):
fg2.add_child(folium.CircleMarker(location =[i_lat, i_lon],radius=6, popup=str(name2), fill_color= 'green', fill = True, color = 'green', fill_opacity = 0.7 ))
db3 = pandas.read_excel("vessel_data.xlsx", sheet_name = 2)
lat3 = list(db3['lat'])
lon3 = list(db3['long'])
name3 = list(db3['name'])
time3 = list(db3['time'])
for i_lat, i_lon, i_name in zip(lat3, lon3, name3):
fg3.add_child(folium.CircleMarker(location =[i_lat, i_lon],radius=6, popup=str(name3), fill_color= 'yellow', fill = True, color = 'yellow', fill_opacity = 0.7 ))
db4 = pandas.read_excel("vessel_data.xlsx", sheet_name = 3)
lat4 = list(db4['lat'])
lon4 = list(db4['long'])
name4= list(db4['name'])
time4 = list(db4['time'])
for i_lat, i_lon, i_name in zip(lat4, lon4, name4):
fg4.add_child(folium.CircleMarker(location =[i_lat, i_lon],radius=6, popup=str(name4), fill_color= 'black', fill = True, color = 'black', fill_opacity = 0.7 ))
map.add_child(fg)
map.add_child(fg2)
map.add_child(fg3)
map.add_child(fg4)
map.add_child(folium.LayerControl())
map.save("Map.html")
,但是该地图是空白的,没有显示包括底图在内的任何图层。
您能帮我调试错误吗?