将 folium 地图上的菜单栏添加到 select 或 deselect 特定对象(标记)
Add menu bar on folium map to select or deselect particular object (Marker)
我制作了一张很酷的地图,如下图所示,但包含更多对象。
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")
结果:
问: 我想知道是否有一种方法可以构建某种菜单栏,使 select 地图中的特定对象成为可能。例如只有汽车,只有火车或汽车和黄线。
它不会成为任何网站的一部分 - 只是一个合并到 .html 文件中的解决方案,如下面的
感谢帮助!!
感谢@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")
我制作了一张很酷的地图,如下图所示,但包含更多对象。
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")
结果:
问: 我想知道是否有一种方法可以构建某种菜单栏,使 select 地图中的特定对象成为可能。例如只有汽车,只有火车或汽车和黄线。
它不会成为任何网站的一部分 - 只是一个合并到 .html 文件中的解决方案,如下面的
感谢帮助!!
感谢@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")