update to new streamlit-version and using st_folium for map-display

This commit is contained in:
2025-08-23 15:13:53 +02:00
parent 2be61aac72
commit fecce2fd8c
4 changed files with 42 additions and 5 deletions

View File

@@ -3,6 +3,9 @@
import math
from re import match # für unkennify
import streamlit as st
from streamlit_folium import st_folium
import folium
# ***recursive quersummenfunktion***
def q_sum(n):
@@ -337,3 +340,34 @@ def rail_decrypt(cipher: str, rails: int):
elif down is False:
y -= 1
return out
#from folium.map import DivIcon
def show_map_folium(df):
if not df.empty:
# Schritt 1: Bestimme die südwestliche und nordöstliche Ecke
sw = df[['lat', 'lon']].min().values.tolist() # Südwesten
ne = df[['lat', 'lon']].max().values.tolist() # Nordosten
# Schritt 2: Initialisiere Karte (Ort egal, wird überschrieben, zoom wird bei mehreren Koordinaten überschrieben)
m = folium.Map(location=df[["lat", "lon"]].mean().values.tolist(), zoom_start=15)
# Schritt 3: Marker hinzufügen
for _, row in df.iterrows():
if 'label' in row:
folium.Marker(
location=[row["lat"], row["lon"]],
popup=f"<b>{int(row['label'])}</b><br> Lat:{round(row['lat'], 5)}, Lon:{round(row['lon'], 5)}",
tooltip=f"<b>{int(row['label'])}</b><br> Lat:{round(row['lat'], 5)}, Lon:{round(row['lon'], 5)}",
icon = folium.Icon(color="red", icon="map-marker")
).add_to(m)
else:
folium.Marker(
location=[row["lat"], row["lon"]],
popup=f"Lat:{round(row['lat'], 5)}, Lon:{round(row['lon'], 5)}",
tooltip=f"Lat:{round(row['lat'], 5)}, Lon:{round(row['lon'], 5)}",
icon = folium.Icon(color="red", icon="map-marker")
).add_to(m)
if len(df) != 1:
# Schritt 4: Zoom anpassen bei mehr als einer Koordinate
m.fit_bounds([sw, ne])
# Schritt 5: In Streamlit anzeigen
st_folium(m, use_container_width=True)
else:
st.markdown(":red[Keine sinnvoll darstellbaren Koordinaten gefunden]")