File size: 1,320 Bytes
ed11779
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cdb7074
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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]