Szymon Woźniak commited on
Commit
1e2ccdb
1 Parent(s): 6779c90

center map better

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -1,33 +1,27 @@
1
- import streamlit as st
2
- import folium
3
  from folium.plugins import MarkerCluster
4
- import pandas as pd
5
- from streamlit_folium import folium_static
6
-
7
  from srai.regionalizers import geocode_to_region_gdf
 
 
 
 
8
 
9
- # Define the function to create a map with markers
10
  def create_map(points, color, marker_cluster):
11
  points.apply(lambda row: folium.Marker(location=[row.y, row.x], icon=folium.Icon(color=color)).add_to(marker_cluster))
12
 
13
- # Define the function to get the center of the region
14
  def get_center(region):
15
  boundary = geocode_to_region_gdf(region)
16
  return boundary.centroid.iloc[0]
17
 
18
- # Define the function to get the points of the region
19
  def get_points(region, size):
20
  boundary = geocode_to_region_gdf(region)
21
  return boundary["geometry"].sample_points(size=size).explode()
22
 
23
- # Set up the map
24
- map_center = (52.34260, 20.04503)
25
  poland_center = get_center("Poland")
26
- my_map = folium.Map(location = (poland_center.y, poland_center.x), zoom_start = 5)
 
27
 
28
  marker_cluster = MarkerCluster().add_to(my_map)
29
 
30
- # Set up the sliders
31
  poland_points_num = st.sidebar.slider('Number of points for Poland', 0, 500, 350)
32
  riga_points_num = st.sidebar.slider('Number of points for Riga, Latvia', 0, 25, 5)
33
  tallin_points_num = st.sidebar.slider('Number of points for Tallin, Estonia', 0, 25, 5)
@@ -38,11 +32,9 @@ pskov_points = get_points("Pskov", pskov_points_num)
38
  riga_points = get_points("Riga", riga_points_num)
39
  tallin_points = get_points("Tallin", tallin_points_num)
40
 
41
- # Create the map with markers
42
  create_map(poland_points, 'blue', marker_cluster)
43
  create_map(riga_points, 'blue', marker_cluster)
44
  create_map(tallin_points, 'blue', marker_cluster)
45
  create_map(pskov_points, 'red', marker_cluster)
46
 
47
- # Display the map
48
- st_data = folium_static(my_map)
 
 
 
1
  from folium.plugins import MarkerCluster
 
 
 
2
  from srai.regionalizers import geocode_to_region_gdf
3
+ from streamlit_folium import folium_static
4
+ import folium
5
+ import pandas as pd
6
+ import streamlit as st
7
 
 
8
  def create_map(points, color, marker_cluster):
9
  points.apply(lambda row: folium.Marker(location=[row.y, row.x], icon=folium.Icon(color=color)).add_to(marker_cluster))
10
 
 
11
  def get_center(region):
12
  boundary = geocode_to_region_gdf(region)
13
  return boundary.centroid.iloc[0]
14
 
 
15
  def get_points(region, size):
16
  boundary = geocode_to_region_gdf(region)
17
  return boundary["geometry"].sample_points(size=size).explode()
18
 
 
 
19
  poland_center = get_center("Poland")
20
+ my_map = folium.Map(location = (54.50272, 20.51721), zoom_start = 5)
21
+ st.set_page_config(layout="wide")
22
 
23
  marker_cluster = MarkerCluster().add_to(my_map)
24
 
 
25
  poland_points_num = st.sidebar.slider('Number of points for Poland', 0, 500, 350)
26
  riga_points_num = st.sidebar.slider('Number of points for Riga, Latvia', 0, 25, 5)
27
  tallin_points_num = st.sidebar.slider('Number of points for Tallin, Estonia', 0, 25, 5)
 
32
  riga_points = get_points("Riga", riga_points_num)
33
  tallin_points = get_points("Tallin", tallin_points_num)
34
 
 
35
  create_map(poland_points, 'blue', marker_cluster)
36
  create_map(riga_points, 'blue', marker_cluster)
37
  create_map(tallin_points, 'blue', marker_cluster)
38
  create_map(pskov_points, 'red', marker_cluster)
39
 
40
+ st_data = folium_static(my_map)