Skip to content

Commit 46230f4

Browse files
Add locality resolution + selectbox
1 parent 03ffc6c commit 46230f4

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

hackyeah2024/server.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import folium
22
import streamlit as st
3-
from osmnx import distance, geocoder, graph_from_bbox, routing
3+
from osmnx import distance, geocoder, graph_from_bbox, routing, features_from_bbox
44
from streamlit_folium import st_folium
55

66
bounding_box = {'min_lat': 49.174522, 'max_lat': 50.526524, 'min_lon': 19.076385, 'max_lon': 21.432953}
@@ -31,27 +31,24 @@ def plot_route(map_, route_pts):
3131
def run_server():
3232
st.title('Rowerem przez Małopolskę')
3333

34+
localities = tuple(features_from_bbox(
35+
bbox=(bounding_box['max_lat'], bounding_box['min_lat'], bounding_box['min_lon'], bounding_box['max_lon']),
36+
tags={"place": ["town", "vilage"]})['name'].values
37+
)
38+
3439
cont1 = st.container()
3540

3641
with cont1:
3742
col1, col2 = st.columns(2)
3843

3944
with col1:
40-
st.text_input('Skąd')
45+
origin = st.selectbox("Skąd", localities)
4146

4247
with col2:
43-
st.text_input('Dokąd')
48+
destination = st.selectbox("Dokąd", localities)
4449

4550
cont2 = st.container()
4651

47-
map_bound_coordinates = [
48-
(50.526524, 19.076385),
49-
(50.526524, 21.432953),
50-
(49.174522, 21.432953),
51-
(49.174522, 19.076385),
52-
(50.526524, 19.076385),
53-
]
54-
5552
# center on Liberty Bell, add marker
5653
map_ = folium.Map(
5754
max_bounds=True,
@@ -66,9 +63,9 @@ def run_server():
6663
marker = folium.Marker([50.049683, 19.944544], popup='Kraków', tooltip='Kraków')
6764
map_.add_child(marker)
6865

69-
map_bounds = folium.PolyLine(locations=map_bound_coordinates, weight=5)
66+
route_pts = get_route_points(origin, destination)
7067

71-
map_.add_child(map_bounds)
68+
plot_route(map_, route_pts)
7269

7370
with cont2:
7471
# call to render Folium map in Streamlit

0 commit comments

Comments
 (0)