import streamlit as st import leafmap.foliumap as leafmap def create_marker(bird): species = bird['species'] lat = bird['lat'] lon = bird['lon'] start_month = bird['start_month'] end_month = bird['end_month'] popup_msg = f"{species}: {start_month} - {end_month}" icon_text = f"{species} ({start_month} - {end_month})" marker = leafmap.Marker(location=[lat, lon], popup=popup_msg) marker.add_child(leafmap.Popup(icon_text)) return marker def create_map(center, zoom, markers): m = leafmap.Map(center=center, zoom=zoom) for marker in markers: marker.add_to(m) return m birds = [ {'species': 'Canada Goose', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'April'}, {'species': 'Mallard Duck', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'August', 'end_month': 'May'}, {'species': 'Wood Duck', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'March', 'end_month': 'November'}, {'species': 'Trumpeter Swan', 'lat': 45.0941, 'lon': -94.2392, 'start_month': 'October', 'end_month': 'April'}, {'species': 'Tundra Swan', 'lat': 44.9358, 'lon': -93.1553, 'start_month': 'November', 'end_month': 'April'}, {'species': 'Canvasback', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'September', 'end_month': 'May'}, {'species': 'Redhead', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'May'}, {'species': 'Greater Scaup', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'September', 'end_month': 'May'}, {'species': 'Lesser Scaup', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'May'}, {'species': 'Hooded Merganser', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'October', 'end_month': 'April'} ] # Create list of markers for each bird species markers = [create_marker(bird) for bird in birds] # Define the center and zoom of the map center = [44.9778, -93.2650] zoom = 8 # Create the Streamlit app st.title("Bird Migration Map") month = st.slider("Select a month", 1, 12, 1) # Filter the markers by the selected month selected_markers = [marker for marker in markers if month >= list(calendar.month_abbr).index(marker['start_month'][:3]) and month <= list(calendar.month_abbr).index(marker['end_month'][:3])] # Create the map with the filtered markers m = create_map(center, zoom, selected_markers) # Display the map on the Streamlit app st.write(m)