update to new streamlit-version and using st_folium for map-display
This commit is contained in:
@@ -4,6 +4,7 @@ import streamlit as st
|
||||
import base64
|
||||
import tools
|
||||
import matplotlib.pyplot as plt
|
||||
from helper import show_map_folium
|
||||
|
||||
standard_output = ('#### Um den HILFE-Text zu einzelnen Funktionen aufzurufen bitte die Funktion mit leerem'
|
||||
' Eingabefeld aufrufen.')
|
||||
@@ -360,7 +361,8 @@ st.markdown(st.session_state.output_text)
|
||||
# Karte anzeigen, falls aktiviert
|
||||
if st.session_state.map_data is not None:
|
||||
st.subheader("Kartenansicht")
|
||||
st.map(st.session_state.map_data)
|
||||
show_map_folium(st.session_state.map_data)
|
||||
|
||||
|
||||
if st.session_state.graph_data is not None:
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
@@ -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]")
|
||||
@@ -2057,7 +2057,7 @@ def maptiles_kachelkoordinaten(eingabetext):
|
||||
try:
|
||||
la = float(text[0])
|
||||
lo = float(text[1])
|
||||
if not la < -85.05113 and not la > 85.05113 and not lo < -180 and not lo > 180:
|
||||
if not la < -83.0 and not la > 83.0 and not lo < -180 and not lo > 180:
|
||||
x, y = helper.dec_to_maptiles(la, lo, zoom)
|
||||
ausgabetext += f"|{zoom:>2}|{x:<10}|{y}|\n"
|
||||
except ValueError:
|
||||
@@ -2065,17 +2065,18 @@ def maptiles_kachelkoordinaten(eingabetext):
|
||||
return ausgabetext, None
|
||||
elif len(text) == 2:
|
||||
ausgabetext = ":violet[Maptiles->DEG,DEC] \n|:blue[Zoom]|:blue[DEG]|:blue[DEC]|\n|-|-|-|\n"
|
||||
lat_list, lon_list = [], []
|
||||
lat_list, lon_list, label_list = [], [], []
|
||||
for zoom in range(2, 26):
|
||||
try:
|
||||
la, lo = helper.maptiles_to_dec(int(text[0]), int(text[1]), zoom)
|
||||
if not la < -85.05113 and not la > 85.05113 and not lo < -180 and not lo > 180:
|
||||
if not la < -83.0 and not la > 83.0 and not lo < -180 and not lo > 180:
|
||||
ausgabetext += f"|{zoom:>2}|{helper.dec_to_deg(la, lo):<23}|{round(la, 5)} {round(lo, 5)}| \n"
|
||||
lat_list.append(la)
|
||||
lon_list.append(lo)
|
||||
label_list.append(zoom)
|
||||
except OverflowError:
|
||||
pass
|
||||
return ausgabetext, pd.DataFrame({'lat': lat_list, 'lon': lon_list})
|
||||
return ausgabetext, pd.DataFrame({'lat': lat_list, 'lon': lon_list, 'label': label_list})
|
||||
else:
|
||||
return ":red[Zahlen konnten nicht ermittelt werden!]", None
|
||||
|
||||
|
||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Reference in New Issue
Block a user