Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seemingly infinite drawing after dropping pin with geocoder plugin #248

Open
xnolandx opened this issue Mar 3, 2025 · 3 comments
Open

Comments

@xnolandx
Copy link

xnolandx commented Mar 3, 2025

Apologies if this issue has already been raised and addressed. I looked at the closed issues and didn't see this so I wanted to bring up a bug that I am currently facing. Additionally, this is the first issue I've raised on GitHub so if I leave out any pertinent information let me know and I'll include it.

I am simply trying to enable the dropping of a pin with the Geocoder plugin and then draw a rectangle with the Draw plugin. For the sake of troubleshooting I tried other shapes and the issue seems to exist with those as well. I also tried a handful of different Geocoder providers to no avail.

dependencies:

folium==0.19.5
streamlit_folium==0.24.0
streamlit==1.41.1

mvp to reproduce:

import folium 
from streamlit_folium import st_folium
from folium.plugins import Draw, Geocoder

def search_area():
    m = folium.Map()

    Draw().add_to(m)
    Geocoder().add_to(m)
    st_folium(m, 
              height=350, 
              use_container_width=True)

steps to reproduce:

  1. use the geocoder to drop a pin at the following coordinates: 43.089774, -76.209267
  2. select the rectangle in the draw tool bar
  3. try to draw a rectangle

On mouse release to end the drawing, the draw tool seems to be getting stuck in a loop where the mouse release triggers the beginning of a new drawing.

@randyzwitch
Copy link
Owner

Have you tried to do this without including this code inside a function?

def search_area():
    m = folium.Map()

    Draw().add_to(m)
    Geocoder().add_to(m)
    st_folium(m, 
              height=350, 
              use_container_width=True)

Because of the Streamlit execution model, I feel like this re-draws the map every time. Moving the map code outside of a function to the top-level would allow you to interact with the map and keep the various objects.

@xnolandx
Copy link
Author

xnolandx commented Mar 4, 2025

Hey Randy, I appreciate your response.
I tried your suggestion and the described behavior is still happening.

The updated code (in a brand new streamlit app):

`import folium
from streamlit_folium import st_folium
from folium.plugins import Draw, Geocoder

m = folium.Map()

Draw().add_to(m)
Geocoder().add_to(m)
st_folium(m,
height=350,
use_container_width=True)`

screen recording of unexpected behavior:
https://github.com/user-attachments/assets/cfd39d0c-262d-4728-8a12-359d421cb23e

@xnolandx
Copy link
Author

xnolandx commented Mar 6, 2025

@randyzwitch I wanted to provide some more context because after re-reading your reply, I feel like I might have not made it clear what the issue is.

So if you add either the Draw plugin OR the Geocoder plugin, they operate normally as you would expect. If you add both and DON'T drop a pin using the Geocoder, the Draw tool operates normally. The buggy interaction happens specifically AFTER a pin has been dropped with the Geocoder. I am not familiar enough with Leaflet or Folium but I assume there is some event handler that is not being processed correctly, likely involving the Geocoder.

The behavior can be seen in my previously linked video.

Thanks for your time, I'm sure you and the team are very busy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants