| import folium | |
| from folium.plugins import MarkerCluster | |
| class MapHandler: | |
| def create_map(self, lat, lon, zoom=13): | |
| """Create a Folium map centered on the given coordinates.""" | |
| m = folium.Map(location=[lat, lon], zoom_start=zoom) | |
| return m | |
| def get_map_bounds(self, map_object): | |
| """Get the current bounds of the map.""" | |
| bounds = map_object.get_bounds() | |
| return { | |
| 'north': bounds[0][0], | |
| 'south': bounds[0][1], | |
| 'east': bounds[1][1], | |
| 'west': bounds[1][0] | |
| } | |
| def add_landmark_marker(self, map_object, landmark): | |
| """Add a marker for a landmark to the map.""" | |
| popup_content = f""" | |
| <h3>{landmark['title']}</h3> | |
| <p>{landmark['summary'][:200]}...</p> | |
| <a href="{landmark['url']}" target="_blank">Read more on Wikipedia</a> | |
| """ | |
| folium.Marker( | |
| location=[landmark['lat'], landmark['lon']], | |
| popup=folium.Popup(popup_content, max_width=300), | |
| tooltip=landmark['title'] | |
| ).add_to(map_object) | |
| def clear_markers(self, map_object): | |
| """Clear all markers from the map.""" | |
| for name in list(map_object._children.keys()): | |
| if name.startswith('marker_'): | |
| del map_object._children[name] | |