Vertdure commited on
Commit
6c147b4
1 Parent(s): eff42fb

Update pages/Vertbox.py

Browse files
Files changed (1) hide show
  1. pages/Vertbox.py +31 -15
pages/Vertbox.py CHANGED
@@ -4,6 +4,7 @@ from streamlit_folium import folium_static
4
  import pyproj
5
  from folium.plugins import Draw
6
  import json
 
7
 
8
  st.set_page_config(layout="wide")
9
 
@@ -38,12 +39,28 @@ st.markdown("""
38
  </style>
39
  """, unsafe_allow_html=True)
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  # Layout principal
42
  col1, col2 = st.columns([4, 1])
43
 
44
  with col1:
 
 
45
  # Carte
46
- m = folium.Map(location=[0, 0], zoom_start=2)
47
  draw = Draw(
48
  export=True,
49
  position='topleft',
@@ -53,11 +70,10 @@ with col1:
53
  draw.add_to(m)
54
 
55
  # Script JavaScript pour gérer le dessin et la mise à jour des coordonnées
56
- m.get_root().html.add_child(folium.Element("""
57
  <script>
58
  var drawnItems = new L.FeatureGroup();
59
  map.addLayer(drawnItems);
60
-
61
  map.on(L.Draw.Event.CREATED, function (event) {
62
  drawnItems.clearLayers();
63
  var layer = event.layer;
@@ -75,10 +91,10 @@ with col1:
75
  </script>
76
  """))
77
 
78
- folium_static(m, width=800, height=600)
79
 
80
  with col2:
81
- st.markdown("<h3 style='text-align: center;'>Coordonnées</h3>", unsafe_allow_html=True)
82
  bbox_coords = st.text_input("", key="bbox_coords", label_visibility="collapsed")
83
 
84
  if bbox_coords:
@@ -94,10 +110,10 @@ with col2:
94
  converted_bbox = convert_coordinates(bbox, "EPSG:4326", epsg)
95
  result = f"{converted_bbox[0]:.6f},{converted_bbox[1]:.6f},{converted_bbox[2]:.6f},{converted_bbox[3]:.6f}"
96
  st.code(result, language="plaintext")
97
- if st.button(f"Copier {epsg}", key=f"copy_{epsg}"):
98
- st.write(f"{epsg} copié!")
99
 
100
- # Formats supplémentaires
101
  st.markdown("<b>GeoJSON</b>", unsafe_allow_html=True)
102
  geojson = json.dumps({
103
  "type": "Feature",
@@ -114,19 +130,19 @@ with col2:
114
  }
115
  }, indent=2)
116
  st.code(geojson, language="json")
117
- if st.button("Copier GeoJSON"):
118
- st.write("GeoJSON copié!")
119
 
120
  st.markdown("<b>WKT</b>", unsafe_allow_html=True)
121
  wkt = f"POLYGON(({bbox[0]} {bbox[1]}, {bbox[2]} {bbox[1]}, {bbox[2]} {bbox[3]}, {bbox[0]} {bbox[3]}, {bbox[0]} {bbox[1]}))"
122
  st.code(wkt, language="plaintext")
123
- if st.button("Copier WKT"):
124
- st.write("WKT copié!")
125
 
126
  else:
127
- st.error("Veuillez entrer 4 coordonnées séparées par des virgules.")
128
  except ValueError:
129
- st.error("Veuillez entrer des coordonnées valides (nombres séparés par des virgules).")
130
 
131
  # Footer
132
- st.markdown("<div style='text-align: center; color: gray;'>Créé avec Streamlit - Inspiré par bboxfinder.com</div>", unsafe_allow_html=True)
 
4
  import pyproj
5
  from folium.plugins import Draw
6
  import json
7
+ import leafmap.foliumap as leafmap
8
 
9
  st.set_page_config(layout="wide")
10
 
 
39
  </style>
40
  """, unsafe_allow_html=True)
41
 
42
+ # Sidebar
43
+ st.sidebar.title("About")
44
+ st.sidebar.info(
45
+ "This app is an improved version of the BBox Finder, "
46
+ "inspired by bboxfinder.com and using Streamlit."
47
+ )
48
+
49
+ st.sidebar.title("Contact")
50
+ st.sidebar.info(
51
+ "Your Name\n"
52
+ "[GitHub](https://github.com/yourusername) | "
53
+ "[LinkedIn](https://www.linkedin.com/in/yourprofile)"
54
+ )
55
+
56
  # Layout principal
57
  col1, col2 = st.columns([4, 1])
58
 
59
  with col1:
60
+ st.title("Improved BBox Finder")
61
+
62
  # Carte
63
+ m = leafmap.Map(center=[0, 0], zoom=2)
64
  draw = Draw(
65
  export=True,
66
  position='topleft',
 
70
  draw.add_to(m)
71
 
72
  # Script JavaScript pour gérer le dessin et la mise à jour des coordonnées
73
+ m.add_child(folium.Element("""
74
  <script>
75
  var drawnItems = new L.FeatureGroup();
76
  map.addLayer(drawnItems);
 
77
  map.on(L.Draw.Event.CREATED, function (event) {
78
  drawnItems.clearLayers();
79
  var layer = event.layer;
 
91
  </script>
92
  """))
93
 
94
+ m.to_streamlit(height=600)
95
 
96
  with col2:
97
+ st.markdown("<h3 style='text-align: center;'>Coordinates</h3>", unsafe_allow_html=True)
98
  bbox_coords = st.text_input("", key="bbox_coords", label_visibility="collapsed")
99
 
100
  if bbox_coords:
 
110
  converted_bbox = convert_coordinates(bbox, "EPSG:4326", epsg)
111
  result = f"{converted_bbox[0]:.6f},{converted_bbox[1]:.6f},{converted_bbox[2]:.6f},{converted_bbox[3]:.6f}"
112
  st.code(result, language="plaintext")
113
+ if st.button(f"Copy {epsg}", key=f"copy_{epsg}"):
114
+ st.write(f"{epsg} copied!")
115
 
116
+ # Additional formats
117
  st.markdown("<b>GeoJSON</b>", unsafe_allow_html=True)
118
  geojson = json.dumps({
119
  "type": "Feature",
 
130
  }
131
  }, indent=2)
132
  st.code(geojson, language="json")
133
+ if st.button("Copy GeoJSON"):
134
+ st.write("GeoJSON copied!")
135
 
136
  st.markdown("<b>WKT</b>", unsafe_allow_html=True)
137
  wkt = f"POLYGON(({bbox[0]} {bbox[1]}, {bbox[2]} {bbox[1]}, {bbox[2]} {bbox[3]}, {bbox[0]} {bbox[3]}, {bbox[0]} {bbox[1]}))"
138
  st.code(wkt, language="plaintext")
139
+ if st.button("Copy WKT"):
140
+ st.write("WKT copied!")
141
 
142
  else:
143
+ st.error("Please enter 4 coordinates separated by commas.")
144
  except ValueError:
145
+ st.error("Please enter valid coordinates (numbers separated by commas).")
146
 
147
  # Footer
148
+ st.markdown("<div style='text-align: center; color: gray;'>Created with Streamlit - Inspired by bboxfinder.com</div>", unsafe_allow_html=True)