Advertisement
safwan092

Untitled

Nov 21st, 2023
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. import streamlit as st
  2. import folium
  3. from streamlit_folium import folium_static
  4. import pandas as pd
  5.  
  6. @st.cache_resource()
  7. def get_marker_df():
  8. return pd.DataFrame(columns=['Latitude', 'Longitude', 'Popup Content'])
  9.  
  10. # Create an empty DataFrame to store marker information
  11. marker_df = pd.DataFrame(columns=['Latitude', 'Longitude', 'Popup Content'])
  12.  
  13. st.title("Interactive Map with Streamlit and Folium")
  14.  
  15. m = folium.Map(location=[21.5028, 39.2472], zoom_start=18)
  16.  
  17. # Get user input as a string
  18. UserLocation = st.text_input("Set [Latitude, Longitude, Custom PopUp]:", '')
  19.  
  20. # Split the string into a list of values
  21. values = UserLocation.split(",")
  22.  
  23. # Ensure that three values are entered
  24. if len(values) == 3:
  25.  
  26. # Assign the values to separate variables
  27. UserLatitude = values[0].strip()
  28. UserLongitude = values[1].strip()
  29. UserPopUp = values[2].strip()
  30.  
  31. # Display the values
  32. st.write("setLatitude:", UserLatitude)
  33. st.write("setLongitude:", UserLongitude)
  34. m = folium.Map(location=[UserLatitude, UserLongitude], zoom_start=18)
  35.  
  36. # Create a marker with a custom popup
  37. marker = folium.Marker(
  38. location=[UserLatitude, UserLongitude],
  39. popup=folium.Popup(UserPopUp, max_width=300),
  40. )
  41.  
  42. # Add the marker to the map
  43. marker.add_to(m)
  44.  
  45. # Retrieve the marker DataFrame from the cache
  46. marker_df = get_marker_df()
  47.  
  48. # Append marker information to the DataFrame
  49. marker_df.loc[len(marker_df)] = [UserLatitude, UserLongitude, UserPopUp]
  50.  
  51.  
  52. else:
  53. st.write("Please enter three values separated by commas.")
  54.  
  55. # Add a click event handler to the map
  56. m.add_child(folium.ClickForMarker("${lat},${lng}<br><b>Altitude:</b> 10.00 m"))
  57.  
  58. # Display the map using folium_static
  59. folium_static(m,width=1000, height=800)
  60.  
  61. # Display the marker table
  62. st.write("Marker Table", marker_df)
  63.  
  64.  
  65.  
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement