pjgerrits commited on
Commit
e0a4c5c
1 Parent(s): 7178fd2

add logo and change zoom level

Browse files
Files changed (2) hide show
  1. app.py +16 -5
  2. static/UoG_keyline.png +0 -0
app.py CHANGED
@@ -49,8 +49,10 @@ def submit_data(age, gender, transport, multi_transport, time_of_day, day_of_wee
49
  cursor.close()
50
  conn.close()
51
 
52
- def create_map(points):
53
- m = folium.Map(location=[51.5074, -0.1278], zoom_start=10, control_scale=True)
 
 
54
  for point_type, coords in points.items():
55
  if coords:
56
  folium.Marker(
@@ -79,7 +81,7 @@ st.markdown(
79
  """,
80
  unsafe_allow_html=True,
81
  )
82
-
83
  st.sidebar.title("Step 1 - Add Markers")
84
 
85
  # Custom buttons for selecting point type
@@ -107,21 +109,30 @@ if st.sidebar.button("Reset Markers", key="reset-button"):
107
  st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
108
  st.experimental_rerun()
109
 
 
 
 
 
 
 
110
  map_placeholder = st.empty()
111
 
112
  with map_placeholder.container():
113
- folium_map = create_map(st.session_state['points'])
114
  map_output = st_folium(folium_map, width="100%", height=800)
115
 
116
  new_coords = None
117
  if map_output and 'last_clicked' in map_output and map_output['last_clicked'] is not None:
118
  new_coords = (map_output['last_clicked']['lat'], map_output['last_clicked']['lng'])
 
 
 
119
 
120
  if new_coords:
121
  st.session_state['points'][st.session_state['point_type']] = new_coords
122
  map_placeholder.empty()
123
  with map_placeholder.container():
124
- folium_map = create_map(st.session_state['points'])
125
  st_folium(folium_map, width="100%", height=800)
126
 
127
  if all(st.session_state['points'].values()) and not st.session_state['survey']:
 
49
  cursor.close()
50
  conn.close()
51
 
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(
 
81
  """,
82
  unsafe_allow_html=True,
83
  )
84
+ st.sidebar.image("static/UoG_keyline.png")
85
  st.sidebar.title("Step 1 - Add Markers")
86
 
87
  # Custom buttons for selecting point type
 
109
  st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
110
  st.experimental_rerun()
111
 
112
+ # Initialize session state for map center and zoom level if not already done
113
+ if 'map_center' not in st.session_state:
114
+ st.session_state['map_center'] = [51.5074, -0.1278]
115
+ if 'map_zoom' not in st.session_state:
116
+ st.session_state['map_zoom'] = 10
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)
123
 
124
  new_coords = None
125
  if map_output and 'last_clicked' in map_output and map_output['last_clicked'] is not None:
126
  new_coords = (map_output['last_clicked']['lat'], map_output['last_clicked']['lng'])
127
+ # Update the map center to the last clicked location
128
+ st.session_state['map_center'] = [map_output['last_clicked']['lat'], map_output['last_clicked']['lng']]
129
+ st.session_state['map_zoom'] = map_output['zoom']
130
 
131
  if new_coords:
132
  st.session_state['points'][st.session_state['point_type']] = new_coords
133
  map_placeholder.empty()
134
  with map_placeholder.container():
135
+ folium_map = create_map(st.session_state['points'], center=st.session_state['map_center'], zoom=st.session_state['map_zoom'])
136
  st_folium(folium_map, width="100%", height=800)
137
 
138
  if all(st.session_state['points'].values()) and not st.session_state['survey']:
static/UoG_keyline.png ADDED