randyzwitch / streamlit-folium

Streamlit Component for rendering Folium maps
https://folium.streamlit.app/
MIT License
480 stars 178 forks source link

Feature request: return map bounds to streamlit #12

Closed robmarkcole closed 2 years ago

robmarkcole commented 3 years ago

I have a pandas dataframe that contains the lat/lon location of a bunch of markers (plus other data) and am displaying that when a pin is clicked on via a popup, with the map generated by:

import folium
from folium import IFrame
import pandas as pd

df = pd.read_csv("my.csv")

location = df['latitude'].mean(), df['longitude'].mean()
m = folium.Map(location=location, zoom_start=15)

width = 900
height = 600 
fat_wh = 1 # border around image

for i in range(0, len(df)):
    html = pd.DataFrame(df[["latitude", "longitude", "time"]].iloc[i]).to_html()
    iframe = IFrame(html, width=width*fat_wh, height=height*fat_wh)
    popup  = folium.Popup(iframe, parse_html = True, max_width=2000)
    folium.Marker([df['latitude'].iloc[i], df['longitude'].iloc[i]], popup=popup).add_to(m)

folium_static(m)

Now this dataframe may in future get VERY large as it potentially covers the whole world, so I only want to return the markers that are in the current map view, and do some clever aggregation when the map is zoomed out. For this I need to get the extent of the map view coordinates, and use these to filter the dataframe (I probably also want to do some caching somewhere). Can you advise if this is possible/requires a new feature? Many thanks

randyzwitch commented 3 years ago

Yeah, that's generally the purpose of #9, though I haven't had the time to work on it

giswqs commented 3 years ago

@robmarkcole Does heat map suit your needs? Check out this example: https://share.streamlit.io/giswqs/leafmap-streamlit/app.py

blackary commented 2 years ago

This should be resolved once #28 is released using the new st_folium method

giswqs commented 2 years ago

@blackary Fantastic work! Can you provide a working example? I tried running interactive_app.py, but the following error

streamlit.errors.StreamlitAPIException: No such component directory: '~/.conda/envs/geo/lib/python3.9/site-packages/streamlit_folium/frontend/build'

image

randyzwitch commented 2 years ago

Please wait a little bit, I will provide instructions once we validate it is working properly :)

On Feb 11, 2022, at 11:14 AM, Qiusheng Wu @.***> wrote:

 @blackary Fantastic work! Can you provide a working example? I tried running interactive_app.py, but the following error

streamlit.errors.StreamlitAPIException: No such component directory: '~/.conda/envs/geo/lib/python3.9/site-packages/streamlit_folium/frontend/build'

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.

randyzwitch commented 2 years ago

Version 0.6.0 is now on PyPI. Use pip install -U streamlit-folium to get the latest version. Please also see the release notes on how this version is believed to solve this issue

https://github.com/randyzwitch/streamlit-folium/releases/tag/v0.6.0