Spaces:
Sleeping
Sleeping
pjgerrits
commited on
Commit
·
5db2569
1
Parent(s):
c6fb31a
move control and add basemaps
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import folium
|
|
|
|
|
3 |
from streamlit_folium import st_folium
|
4 |
import psycopg2
|
5 |
|
@@ -52,7 +54,26 @@ def submit_data(age, gender, transport, multi_transport, time_of_day, day_of_wee
|
|
52 |
def create_map(points, center=None, zoom=10):
|
53 |
if center is None:
|
54 |
center = [51.5074, -0.1278]
|
55 |
-
m = folium.Map(location=center, zoom_start=zoom, control_scale=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
for point_type, coords in points.items():
|
57 |
if coords:
|
58 |
folium.Marker(
|
@@ -88,35 +109,36 @@ st.markdown(
|
|
88 |
)
|
89 |
|
90 |
st.sidebar.image("static/UoG_keyline.png")
|
91 |
-
st.
|
92 |
|
93 |
# Custom buttons for selecting point type
|
94 |
-
col1, col2, col3 = st.
|
95 |
|
96 |
with col1:
|
97 |
if st.button(":red[Start]", key="start-button", help="Place a marker on the corresponding map location", use_container_width=True):
|
98 |
st.session_state['point_type'] = 'start'
|
99 |
-
st.
|
100 |
|
101 |
with col2:
|
102 |
if st.button(":orange[Lost]", key="lost-button", help="Place a marker on the corresponding map location", use_container_width=True):
|
103 |
st.session_state['point_type'] = 'lost'
|
104 |
-
st.
|
105 |
|
106 |
with col3:
|
107 |
if st.button(":blue[End]", key="end-button", help="Place a marker on the corresponding map location", use_container_width=True):
|
108 |
st.session_state['point_type'] = 'end'
|
109 |
-
st.
|
110 |
|
111 |
-
st.sidebar.write(f"Selected Point Type: {st.session_state['point_type'].capitalize()}")
|
112 |
|
|
|
113 |
# Reset button
|
114 |
-
if st.
|
115 |
st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
|
116 |
st.rerun()
|
117 |
|
118 |
map_placeholder = st.empty()
|
119 |
|
|
|
120 |
with map_placeholder.container():
|
121 |
folium_map = create_map(st.session_state['points'], center=st.session_state['map_center'], zoom=st.session_state['map_zoom'])
|
122 |
map_output = st_folium(folium_map, width="100%", height=800)
|
@@ -136,11 +158,13 @@ if new_coords:
|
|
136 |
st_folium(folium_map, width="100%", height=800)
|
137 |
|
138 |
if all(st.session_state['points'].values()) and not st.session_state['survey']:
|
139 |
-
if st.sidebar.button("**Proceed to Survey** :question:", use_container_width=True):
|
|
|
|
|
140 |
st.session_state['survey'] = True
|
141 |
else:
|
142 |
st.sidebar.title("Step 2 - Survey Questions")
|
143 |
-
st.sidebar.warning("Please add start, lost, and end points before proceeding to the survey questions.")
|
144 |
|
145 |
|
146 |
if st.session_state['survey']:
|
|
|
1 |
import streamlit as st
|
2 |
import folium
|
3 |
+
from folium import LayerControl
|
4 |
+
from folium.plugins import Geocoder, MiniMap
|
5 |
from streamlit_folium import st_folium
|
6 |
import psycopg2
|
7 |
|
|
|
54 |
def create_map(points, center=None, zoom=10):
|
55 |
if center is None:
|
56 |
center = [51.5074, -0.1278]
|
57 |
+
m = folium.Map(location=center, zoom_start=zoom, control_scale=True,Tiles=None)
|
58 |
+
Geocoder().add_to(m)
|
59 |
+
MiniMap().add_to(m)
|
60 |
+
basemap_satellite_layer1 = folium.TileLayer(
|
61 |
+
tiles="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
|
62 |
+
attr="Esri",
|
63 |
+
name="ESRI Satellite",
|
64 |
+
overlay=False,
|
65 |
+
control=True
|
66 |
+
)
|
67 |
+
basemap_satellite_layer1.add_to(m)
|
68 |
+
OpenStreetMap_HOT = folium.TileLayer(
|
69 |
+
tiles="https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png",
|
70 |
+
attr="Humanitarian OpenStreetMap Team",
|
71 |
+
name="OpenStreetMap_HOT",
|
72 |
+
overlay=False,
|
73 |
+
control=True
|
74 |
+
)
|
75 |
+
OpenStreetMap_HOT.add_to(m)
|
76 |
+
LayerControl().add_to(m)
|
77 |
for point_type, coords in points.items():
|
78 |
if coords:
|
79 |
folium.Marker(
|
|
|
109 |
)
|
110 |
|
111 |
st.sidebar.image("static/UoG_keyline.png")
|
112 |
+
st.title("Step 1 - Add Your :red[Start], :orange[Lost] and :blue[End] Markers on the Map")
|
113 |
|
114 |
# Custom buttons for selecting point type
|
115 |
+
col1, col2, col3 = st.columns(3)
|
116 |
|
117 |
with col1:
|
118 |
if st.button(":red[Start]", key="start-button", help="Place a marker on the corresponding map location", use_container_width=True):
|
119 |
st.session_state['point_type'] = 'start'
|
120 |
+
st.markdown('<div class="start-button">Start Point</div>', unsafe_allow_html=True)
|
121 |
|
122 |
with col2:
|
123 |
if st.button(":orange[Lost]", key="lost-button", help="Place a marker on the corresponding map location", use_container_width=True):
|
124 |
st.session_state['point_type'] = 'lost'
|
125 |
+
st.markdown('<div class="lost-button">Lost Point</div>', unsafe_allow_html=True)
|
126 |
|
127 |
with col3:
|
128 |
if st.button(":blue[End]", key="end-button", help="Place a marker on the corresponding map location", use_container_width=True):
|
129 |
st.session_state['point_type'] = 'end'
|
130 |
+
st.markdown('<div class="end-button">End Point</div>', unsafe_allow_html=True)
|
131 |
|
|
|
132 |
|
133 |
+
# st.write(f"Selected Point Type: {st.session_state['point_type'].capitalize()}")
|
134 |
# Reset button
|
135 |
+
if st.button(":red-background[:x: **Clear Markers**]", key="reset-button", use_container_width=True):
|
136 |
st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
|
137 |
st.rerun()
|
138 |
|
139 |
map_placeholder = st.empty()
|
140 |
|
141 |
+
|
142 |
with map_placeholder.container():
|
143 |
folium_map = create_map(st.session_state['points'], center=st.session_state['map_center'], zoom=st.session_state['map_zoom'])
|
144 |
map_output = st_folium(folium_map, width="100%", height=800)
|
|
|
158 |
st_folium(folium_map, width="100%", height=800)
|
159 |
|
160 |
if all(st.session_state['points'].values()) and not st.session_state['survey']:
|
161 |
+
if st.sidebar.button("**Proceed to Survey** :question:", use_container_width=True, key="sidebar"):
|
162 |
+
st.session_state['survey'] = True
|
163 |
+
if st.button("**Proceed to Survey** :question:", use_container_width=True, key="main"):
|
164 |
st.session_state['survey'] = True
|
165 |
else:
|
166 |
st.sidebar.title("Step 2 - Survey Questions")
|
167 |
+
st.sidebar.warning("Please add your start, lost, and end points before proceeding to the survey questions.")
|
168 |
|
169 |
|
170 |
if st.session_state['survey']:
|