Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,8 @@ class GeoJson(Layer):
parent.eachLayer(function (child) {
if (child.feature === undefined) { child.feature = feature; }
propagate(child);
})
})(layer)
});
})(layer);
{%- if this.on_each_feature %}
({{this.on_each_feature}})(feature, layer);
{%- endif %}
Expand Down
36 changes: 36 additions & 0 deletions tests/selenium/test_geojson_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,39 @@ def test_geojson(driver):
assert control_label.text == "geojson"
control_input = control_label.find_element(By.CSS_SELECTOR, value="input")
assert control_input.get_attribute("checked") is None


def test_geojson_on_each_feature(driver):
"""The on_each_feature callback must run without Javascript errors.

Regression test: a missing semicolon in the GeoJson template made the
browser call the result of the feature-propagation IIFE with the
callback as argument, so every map using on_each_feature failed.
"""
data = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {"name": "point"},
"geometry": {"type": "Point", "coordinates": [0.0, 0.0]},
}
],
}
m = folium.Map((0, 0), zoom_start=5)
folium.GeoJson(
data,
on_each_feature=folium.JsCode("""
function (feature, layer) {
layer.bindTooltip(feature.properties.name, {permanent: true});
}
"""),
).add_to(m)

html = m.get_root().render()
with temp_html_filepath(html) as filepath:
driver.get_file(filepath)
assert driver.wait_until(".folium-map")
driver.verify_js_logs()
tooltip = driver.wait_until(".leaflet-tooltip")
assert tooltip.text == "point"
Loading