我已经建立了一个很酷的地图,类似于下面的地图,但是有更多的对象。
import folium
base_map = folium.Map(location=[52.2297, 21.0122], control_scale=True, zoom_start=10)
points1 = [(52.228771, 21.003146),
( 52.238025, 21.050971),
(52.255008, 21.036172),
(52.252831, 21.051385),
(52.219995, 20.965021)]
for tuple_ in points1:
icon=folium.Icon(color='white', icon='train', icon_color="red", prefix='fa')
folium.Marker(tuple_, icon=icon).add_to(base_map)
points2 = [(52.239062, 21.131601),
(52.204905, 21.168202),
(52.181296, 20.987486),
(52.206272, 20.914988),
(52.254395, 21.224107)]
for tuple_ in points2:
icon=folium.Icon(color='white', icon='car', icon_color="blue", prefix='fa')
folium.Marker(tuple_, icon=icon).add_to(base_map)
line_points = [(52.204905, 21.168202),(52.255008, 21.036172), (52.219995, 20.965021), (52.239062, 21.131601), (52.254395, 21.224107)]
folium.PolyLine(locations=line_points, weight=3,color = 'yellow').add_to(base_map)
base_map.save("example_map.html")
结果:
问::我想知道是否有一种方法可以构建某种菜单栏,从而可以从地图中选择特定对象。例如只有汽车,只有火车或汽车以及黄线。
它不会成为任何网站的一部分-仅仅是一种将其合并到.html文件中的解决方案,就像下面的那个
感谢帮助!
答案 0 :(得分:2)
由于@BobHaffner,我找到了解决方案。谢谢鲍勃!
import folium
base_map = folium.Map(location=[52.2297, 21.0122], control_scale=True, zoom_start=10)
points1 = [(52.228771, 21.003146),
( 52.238025, 21.050971),
(52.255008, 21.036172),
(52.252831, 21.051385),
(52.219995, 20.965021)]
train_group = folium.FeatureGroup(name="Trains").add_to(base_map)
for tuple_ in points1:
icon=folium.Icon(color='white', icon='train', icon_color="red", prefix='fa')
train_group.add_child(folium.Marker(tuple_, icon=icon))
points2 = [(52.239062, 21.131601),
(52.204905, 21.168202),
(52.181296, 20.987486),
(52.206272, 20.914988),
(52.254395, 21.224107)]
cars_group = folium.FeatureGroup(name="Cars").add_to(base_map)
for tuple_ in points2:
icon=folium.Icon(color='white', icon='car', icon_color="blue", prefix='fa')
cars_group.add_child(folium.Marker(tuple_, icon=icon))
line_points = [(52.204905, 21.168202),(52.255008, 21.036172), (52.219995, 20.965021), (52.239062, 21.131601), (52.254395, 21.224107)]
lines_group = folium.FeatureGroup(name="Lines").add_to(base_map)
lines_group.add_child(folium.PolyLine(locations=line_points, weight=3,color = 'yellow'))
folium.LayerControl().add_to(base_map)
base_map.save("example_map.html")