File size: 2,226 Bytes
ed11779
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import streamlit as st
import folium
from streamlit_folium import folium_static
from map_handler import MapHandler
from wikipedia_handler import WikipediaHandler
from utils import get_current_location

def main():
    st.set_page_config(page_title="Local Landmarks Map", layout="wide")
    st.title("Discover Local Landmarks")

    # Initialize handlers
    map_handler = MapHandler()
    wiki_handler = WikipediaHandler()

    # Get user's current location (for initial map center)
    lat, lon = get_current_location()

    # Create a map centered on the user's location
    m = map_handler.create_map(lat, lon)

    # Create a container for the map
    map_container = st.empty()

    # Display the map
    with map_container:
        folium_static(m, width=1000, height=600)

    # Get the current map bounds
    bounds = map_handler.get_map_bounds(m)

    # Fetch landmarks within the current map bounds
    landmarks = wiki_handler.get_landmarks_in_area(bounds)

    # Debug logging
    st.write(f"Number of landmarks fetched: {len(landmarks)}")

    # Add markers for each landmark
    for landmark in landmarks:
        map_handler.add_landmark_marker(m, landmark)

    # Update the map display
    with map_container:
        folium_static(m, width=1000, height=600)

    # Add a button to refresh landmarks
    if st.button("Refresh Landmarks"):
        # Get updated bounds
        bounds = map_handler.get_map_bounds(m)
        # Fetch new landmarks
        landmarks = wiki_handler.get_landmarks_in_area(bounds)
        # Debug logging
        st.write(f"Number of landmarks fetched after refresh: {len(landmarks)}")
        # Clear existing markers
        map_handler.clear_markers(m)
        # Add new markers
        for landmark in landmarks:
            map_handler.add_landmark_marker(m, landmark)
        # Update the map display
        with map_container:
            folium_static(m, width=1000, height=600)

    st.sidebar.header("About")
    st.sidebar.info("This app displays local landmarks on an interactive map using data from Wikipedia. "
                    "Move around the map to discover new landmarks, and click on markers to learn more about them.")

if __name__ == "__main__":
    main()