zt1y14 commited on
Commit
4c09bc8
·
1 Parent(s): 44f2887

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -2
app.py CHANGED
@@ -1,4 +1,63 @@
1
  import streamlit as st
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import folium
3
+ import json
4
 
5
+ # Set the map center and zoom level
6
+ MAP_CENTER = [35.6895, 139.6917] # Tokyo
7
+ ZOOM_LEVEL = 10
8
+
9
+ # Create a folium map object
10
+ m = folium.Map(location=MAP_CENTER, zoom_start=ZOOM_LEVEL)
11
+
12
+ # Create a DrawControl object
13
+ dc = folium.plugins.DrawControl()
14
+
15
+ # Set the draw options to allow only polygons and rectangles
16
+ dc.draw_options = {
17
+ "polyline": False,
18
+ "circle": False,
19
+ "circlemarker": False,
20
+ "marker": False,
21
+ }
22
+
23
+ # Set the edit options to allow editing and deleting
24
+ dc.edit_options = {
25
+ "edit": True,
26
+ "remove": True,
27
+ }
28
+
29
+ # Add the DrawControl object to the map
30
+ m.add_child(dc)
31
+
32
+ # Define a JavaScript function to handle the draw events
33
+ draw_events = """
34
+ function handleDrawEvent(e) {
35
+ // Get the type and layer of the drawn or edited feature
36
+ var type = e.layerType;
37
+ var layer = e.layer;
38
+
39
+ // If the feature is a polygon or a rectangle, get its geojson data
40
+ if (type === 'polygon' || type === 'rectangle') {
41
+ var geojson = layer.toGeoJSON();
42
+
43
+ // Send the geojson data to Python via Streamlit
44
+ streamlit.setComponentValue(geojson);
45
+ }
46
+ }
47
+ """
48
+
49
+ # Add the JavaScript function to the HTML header of the map
50
+ m.get_root().header.add_child(folium.Element(draw_events))
51
+
52
+ # Register the JavaScript function to the draw:created and draw:edited events
53
+ m.add_child(folium.Element("map.on('draw:created', handleDrawEvent);"))
54
+ m.add_child(folium.Element("map.on('draw:edited', handleDrawEvent);"))
55
+
56
+ # Display the folium map using streamlit
57
+ st_folium(m)
58
+
59
+ # Get the geojson data from Streamlit
60
+ geojson = st_folium.get_value()
61
+
62
+ # Display the geojson data using streamlit
63
+ st.write(geojson)