Skip to content

Show the current geometry when clicking a drawn shape - #2374

Open
KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:draw-click-current-geometry
Open

KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:draw-click-current-geometry

Conversation

@KhadeerBasha1232

Copy link
Copy Markdown
Contributor

Show the current geometry when clicking a drawn shape

The problem

With Draw(show_geometry_on_click=True), which is the default, clicking a drawn shape alerts its GeoJSON. If the shape is changed with the edit toolbar first, the alert still shows the coordinates it had when it was drawn.

To reproduce:

import folium
from folium.plugins import Draw

m = folium.Map(location=(45.0, 3.0), zoom_start=5)
Draw().add_to(m)
m.save("map.html")
  1. Draw a rectangle.
  2. Click the edit button, drag one corner somewhere else, and click Save.
  3. Click the rectangle. The alert shows the old corner.

The export button isn't affected, because it calls toGeoJSON() when clicked. Only the click alert is out of date.

The cause

The GeoJSON is turned into a string once, inside the draw:created handler, and the click handler reuses that string:

var coords = JSON.stringify(layer.toGeoJSON());
layer.on('click', function() {
    alert(coords);
    console.log(coords);
});

The fix

Call layer.toGeoJSON() inside the click handler. The var coords line is left as it is, in case a user's on={...} handler, which is inlined into the same function, refers to it.

Before / after

The steps above in Chrome. To get the alert text into the screenshot, window.alert is replaced with a box at the bottom of the page. The rectangle was resized from about 7.5°E / 44.2°N to about 15.4°E / 40.0°N before clicking.

Before After
Resized rectangle; the alert still shows the original corner at 7.47, 44.18 Resized rectangle; the alert shows the new corner at 15.38, 40.01

Tests

Two new tests in tests/plugins/test_draw.py:

  • test_draw_click_shows_current_geometry checks that the click handler calls toGeoJSON() itself. It fails on main.
  • test_draw_no_click_alert checks that show_geometry_on_click=False still renders no alert.

With show_geometry_on_click, the alert used a GeoJSON string captured
when the shape was drawn, so a shape changed with the edit toolbar kept
showing its original coordinates. Read the geometry inside the click
handler instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@martinfleis

Copy link
Copy Markdown
Collaborator

Can you just stop? Do you think that you're going to flood a project with your LLM generated PRs and maintainers will now spend a week reviewing those? Have some decency...

@KhadeerBasha1232

Copy link
Copy Markdown
Contributor Author

Can you just stop? Do you think that you're going to flood a project with your LLM generated PRs and maintainers will now spend a week reviewing those? Have some decency...

I don't think "have some decency" is a fair way to talk to a contributor. Every PR I've opened targets a real bug or a real gap, has tests, and passes CI. Two have already been merged, including the fix that got pre-commit.ci working again on main.

To be clear: I don't expect everything to get merged. Close whatever you don't want. That's your call as a maintainer, and I'll respect it.

But judge the PRs on their content, not on what tools I used to write them. If there's a specific problem with a specific change, point it out and I'll fix it. If you'd rather I keep fewer open at once, just say how many.

@martinfleis

Copy link
Copy Markdown
Collaborator

I'm judging based on the fact that you're flooding the backlog and depleting maintainers capacity. I would complain about that if you were writing all that by hand, as I have done before.

@KhadeerBasha1232

Copy link
Copy Markdown
Contributor Author

I'm judging based on the fact that you're flooding the backlog and depleting maintainers capacity. I would complain about that if you were writing all that by hand, as I have done before.

Understood. I'll stop opening new PRs and leave the existing ones for you to review whenever you have time.

And thanks for clarifying the by-hand point. Good to know this is about volume, not about how the code was written.

This branch was previously deployed

1 inactive deployment
pypi — 730dec93 Deployed Nov 20, 2026 by KhadeerBasha1232 via packages #2131
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

Successfully merging this pull request may close these issues.

2 participants