Skip to content

Commit

Permalink
Fix draw support for folium >= 0.15 (#162)
Browse files Browse the repository at this point in the history
* Fix draw support for folium >= 0.15

* Bump version
  • Loading branch information
blackary authored Dec 8, 2023
1 parent abb655e commit 884746d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="streamlit_folium",
version="0.17.2",
version="0.17.3",
author="Randy Zwitch",
author_email="[email protected]",
description="Render Folium objects in Streamlit",
Expand Down
3 changes: 3 additions & 0 deletions streamlit_folium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def _get_map_string(fig: folium.Map) -> str:
# Get rid of the annoying popup
leaflet = leaflet.replace("alert(coords);", "")

# Rename drawnItems
leaflet = leaflet.replace("drawnItems_draw_control_div_1", "drawnItems")

leaflet = dedent(leaflet)

if "drawnItems" not in leaflet:
Expand Down
2 changes: 1 addition & 1 deletion streamlit_folium/frontend/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Streamlit, RenderData } from "streamlit-component-lib"
import { RenderData, Streamlit } from "streamlit-component-lib"
import { debounce } from "underscore"
import { circleToPolygon } from "./circle-to-polygon"

Expand Down
16 changes: 16 additions & 0 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ def test_draw(page: Page):
'internal:attr=[title="streamlit_folium.st_folium"i]'
).get_by_role("link", name="Draw a polygon").click()

# Should be no drawings
expect(page.get_by_text('"all_drawings":NULL')).to_be_visible()

page.frame_locator('iframe[title="streamlit_folium\\.st_folium"]').get_by_role(
"link", name="Draw a marker"
).click()
page.frame_locator('iframe[title="streamlit_folium\\.st_folium"]').locator(
".leaflet-marker-icon"
).first.click()
page.frame_locator('iframe[title="streamlit_folium\\.st_folium"]').locator(
"#map_div"
).click()

# Should be one item in drawings after having placed a marker
expect(page.get_by_text('"all_drawings":NULL')).to_be_hidden()


def test_limit_data(page: Page):
# Test limit data support
Expand Down
4 changes: 2 additions & 2 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def test_draw_support():
map.render()
leaflet = _get_map_string(map)
assert "map_div.on(L.Draw.Event.CREATED, function(e) {" in leaflet
assert "drawnItems_draw_control_div_1.addLayer(layer);" in leaflet
assert "drawnItems.addLayer(layer);" in leaflet

assert (
"""map_div.on('draw:created', function(e) {
drawnItems_draw_control_div_1.addLayer(e.layer);
drawnItems.addLayer(e.layer);
});"""
in leaflet
)
Expand Down

0 comments on commit 884746d

Please sign in to comment.