-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
64 lines (54 loc) · 1.82 KB
/
app.py
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
import time
import pydeck as pdk
import streamlit as st
from gtfsviewer.sidebar import generate_sidebar
from gtfsviewer.importer import GTFSFile
def run():
st.title("GTFS Viewer")
with st.spinner("Loading GTFS data..."):
gtfs_data = GTFSFile("data/gtfs.zip")
gtfs_data.extractall()
options = generate_sidebar(st.sidebar)
if options.uploaded_file is not None:
gtfs_data = GTFSFile(options.uploaded_file)
gtfs_data.extractall()
with st.spinner("Updating map..."):
map_layers = []
if options.display_stops:
map_layers.append(
pdk.Layer(
"ScatterplotLayer",
data=gtfs_data.stops,
get_position="[lon, lat]",
get_fill_color="[100, 30, 0, 160]",
get_radius=30,
pickable=True,
)
)
if options.display_routes:
map_layers.append(
pdk.Layer(
"PathLayer",
data=gtfs_data.shapes,
width_scale=20,
width_min_pixels=1,
get_path="path",
get_width=1,
get_color=(0, 0, 255, 255),
)
)
st.pydeck_chart(
pdk.Deck(
map_style="mapbox://styles/mapbox/light-v9",
initial_view_state=pdk.ViewState(
latitude=37.76, longitude=-122.4, zoom=11, bearing=0, pitch=0
),
layers=[map_layers],
tooltip={
"html": "<b>Stop:</b> {name} <br/>",
"style": {"backgroundColor": "steelblue", "color": "white"},
},
)
)
if __name__ == "__main__":
run()