Spaces:
Sleeping
Sleeping
File size: 2,972 Bytes
eadf7ec 31c6562 24fe92f eadf7ec 2179d58 480a187 eadf7ec 0afb45b eadf7ec 98098ca eadf7ec 77ed066 691460d eadf7ec 29145b1 eadf7ec c186ff9 8aa4a13 33bbad8 8aa4a13 33bbad8 d87b1f4 8aa4a13 4948ae6 29145b1 4948ae6 d87b1f4 2179d58 0f99afe 480a187 0f99afe 1ff68fa eadf7ec |
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
import streamlit as st
import pandas as pd
import folium
import numpy as np
from streamlit_folium import folium_static
# Load data
data = {
'Name': ['Location_A', 'Location_B', 'Location_C', 'Location_D', 'Location_E',
'Location_A', 'Location_B', 'Location_C', 'Location_D', 'Location_E',
'Location_A', 'Location_B', 'Location_C', 'Location_D', 'Location_E',
'Location_A', 'Location_B', 'Location_C', 'Location_D', 'Location_E',
'Location_A', 'Location_B', 'Location_C', 'Location_D', 'Location_E',
],
'latitude': np.random.uniform(40.7, 40.8, size=25), # Assuming latitude range between 40.7 and 40.8
'longitude': np.random.uniform(-74.0, -73.9, size=25) # Assuming longitude range between -74.0 and -73.9
}
# Create DataFrame
df = pd.DataFrame(data)
# Sidebar for user input
st.sidebar.title('Filters')
selected_column = st.sidebar.selectbox('Select Column', df.columns)
# Filter data based on user selection
filtered_data = pd.DataFrame(data)
# Display the filtered data
st.write('Filtered Data:')
st.write(filtered_data)
# Create a map object
m = folium.Map(location=(filtered_data['latitude'].mean(), filtered_data['longitude'].mean()), zoom_start=10)
# Add markers to the map
all_markers = folium.FeatureGroup(name='All Markers')
active_markers = folium.FeatureGroup(name='Active Markers', show=False)
inactive_markers = folium.FeatureGroup(name='Inactive Markers', show=False)
for index, row in filtered_data.iterrows():
status_color = 'green' if index%2==0 else 'red'
html_content = f"""
<div style="
display: inline-block;
background-color: white;
border: 2px solid black;
border-radius: 50%;
width: 20px;
height: 20px;
text-align: center;
line-height: 20px;
font-size: 8pt;
color: {status_color};
">{index}</div>
"""
# Create a DivIcon with custom HTML content
icon = folium.DivIcon(html=html_content)
marker = folium.Marker([row['latitude'], row['longitude']], popup=row['Name'], icon=icon).add_to(m)
# #add to groups
# marker.add_to(all_markers)
# if index%2==0:
# marker.add_to(active_markers)
# else:
# marker.add_to(inactive_markers)
# # Add layers to the map
# all_markers.add_to(m)
# active_markers.add_to(m)
# inactive_markers.add_to(m)
# Add layer control to toggle marker visibility
folium.LayerControl().add_to(m)
polygon_coords = [ [np.random.uniform(40.7, 40.8, size=6)[i], np.random.uniform(-74.0, -73.9, size=6)[i]] for i in range(6)]
# Create a polygon object
polygon = folium.Polygon(locations=polygon_coords, color='blue', fill=True, fill_color='blue', fill_opacity=0.3)
# Add the tag to the polygon
popup_text = "This is my polygon"
popup = folium.Popup(popup_text, parse_html=True)
polygon.add_child(popup)
# Add the polygon to the map
m.add_child(polygon)
# Render the map
folium_static(m) |