Replace with st_folium
Browse files- src/streamlit_app.py +20 -51
src/streamlit_app.py
CHANGED
|
@@ -611,59 +611,28 @@ if 'date' in df.columns:
|
|
| 611 |
if 'latitude' in df.columns and 'longitude' in df.columns:
|
| 612 |
st.markdown('🗺️ Observation Locations on Map')
|
| 613 |
try:
|
| 614 |
-
coords = (
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
.dropna()
|
| 618 |
-
.rename(columns={'latitude': 'lat', 'longitude': 'lon'})
|
| 619 |
-
)
|
| 620 |
-
coords = coords[
|
| 621 |
-
(coords['lat'].between(-90, 90)) &
|
| 622 |
-
(coords['lon'].between(-180, 180))
|
| 623 |
-
]
|
| 624 |
if len(coords) == 0:
|
| 625 |
-
|
| 626 |
else:
|
| 627 |
-
#
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
)
|
| 644 |
-
|
| 645 |
-
# ---------- ② 高亮层 ----------
|
| 646 |
-
layer = pdk.Layer(
|
| 647 |
-
'ScatterplotLayer',
|
| 648 |
-
data=coords,
|
| 649 |
-
get_position='[lon, lat]',
|
| 650 |
-
get_radius=50000,
|
| 651 |
-
get_fill_color=[0, 255, 0, 200],
|
| 652 |
-
get_line_color=[255, 255, 255],
|
| 653 |
-
line_width_units='pixels',
|
| 654 |
-
get_line_width=2,
|
| 655 |
-
pickable=True,
|
| 656 |
-
auto_highlight=True,
|
| 657 |
-
)
|
| 658 |
-
|
| 659 |
-
# ---------- ③ 组合 Deck ----------
|
| 660 |
-
deck = pdk.Deck(
|
| 661 |
-
layers=[layer],
|
| 662 |
-
initial_view_state=view_state,
|
| 663 |
-
map_style='mapbox://styles/mapbox/light-v11',
|
| 664 |
-
tooltip={'html': '<b>Lat:</b> {lat}<br/><b>Lon:</b> {lon}'},
|
| 665 |
-
)
|
| 666 |
-
st.pydeck_chart(deck)
|
| 667 |
except Exception as e:
|
| 668 |
st.warning(f'⚠️ Could not render map: {e}')
|
| 669 |
"""
|
|
|
|
| 611 |
if 'latitude' in df.columns and 'longitude' in df.columns:
|
| 612 |
st.markdown('🗺️ Observation Locations on Map')
|
| 613 |
try:
|
| 614 |
+
coords = df[['latitude', 'longitude']].dropna()
|
| 615 |
+
coords = coords[(coords['latitude'].between(-90, 90)) & (coords['longitude'].between(-180, 180))]
|
| 616 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 617 |
if len(coords) == 0:
|
| 618 |
+
raise Exception('⚠️ No valid coordinates to plot on the map.')
|
| 619 |
else:
|
| 620 |
+
# 计算中心点
|
| 621 |
+
center = [coords['latitude'].mean(), coords['longitude'].mean()]
|
| 622 |
+
m = folium.Map(location=center, zoom_start=5)
|
| 623 |
+
|
| 624 |
+
# 添加散点
|
| 625 |
+
for _, row in coords.iterrows():
|
| 626 |
+
folium.CircleMarker(
|
| 627 |
+
location=[row['latitude'], row['longitude']],
|
| 628 |
+
radius=5,
|
| 629 |
+
color='green',
|
| 630 |
+
fill=True,
|
| 631 |
+
fill_color='green',
|
| 632 |
+
fill_opacity=0.7,
|
| 633 |
+
).add_to(m)
|
| 634 |
+
|
| 635 |
+
st_folium(m, width=700, height=500)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 636 |
except Exception as e:
|
| 637 |
st.warning(f'⚠️ Could not render map: {e}')
|
| 638 |
"""
|