fix: polygon with interactive=false was still interactive (#2151)

This bug has been introduced when spliting features, as we now only set
the Leaflet Polygon options with setStyle, will the `interactive` option
is only used in the init by Leaflet.

See https://github.com/Leaflet/Leaflet/pull/9475
This commit is contained in:
Yohan Boniface 2024-10-04 16:36:21 +02:00 committed by GitHub
commit 91800d104d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 12 deletions

View file

@ -292,6 +292,10 @@ const PathMixin = {
} }
options.pointerEvents = options.interactive ? 'visiblePainted' : 'stroke' options.pointerEvents = options.interactive ? 'visiblePainted' : 'stroke'
this.parentClass.prototype.setStyle.call(this, options) this.parentClass.prototype.setStyle.call(this, options)
// TODO remove me when this gets merged and released:
// https://github.com/Leaflet/Leaflet/pull/9475
this._path.classList.toggle('leaflet-interactive', options.interactive)
}, },
_redraw: function () { _redraw: function () {

View file

@ -1,4 +1,5 @@
import re import re
from copy import deepcopy
import pytest import pytest
from playwright.sync_api import expect from playwright.sync_api import expect
@ -33,19 +34,9 @@ DATALAYER_DATA = {
} }
@pytest.fixture def test_should_open_popup_on_click(live_server, map, page):
def bootstrap(map, live_server):
map.settings["properties"]["zoom"] = 6
map.settings["geometry"] = {
"type": "Point",
"coordinates": [8.429, 53.239],
}
map.save()
DataLayerFactory(map=map, data=DATALAYER_DATA) DataLayerFactory(map=map, data=DATALAYER_DATA)
page.goto(f"{live_server.url}{map.get_absolute_url()}#6/53.239/8.429")
def test_should_open_popup_on_click(live_server, map, page, bootstrap):
page.goto(f"{live_server.url}{map.get_absolute_url()}")
polygon = page.locator("path").first polygon = page.locator("path").first
expect(polygon).to_have_attribute("fill-opacity", "0.3") expect(polygon).to_have_attribute("fill-opacity", "0.3")
polygon.click() polygon.click()
@ -57,3 +48,12 @@ def test_should_open_popup_on_click(live_server, map, page, bootstrap):
# Close popup # Close popup
page.locator("#map").click() page.locator("#map").click()
expect(polygon).to_have_attribute("fill-opacity", "0.3") expect(polygon).to_have_attribute("fill-opacity", "0.3")
def test_should_not_react_to_click_if_interactive_false(live_server, map, page):
data = deepcopy(DATALAYER_DATA)
data["features"][0]["properties"]["_umap_options"] = {"interactive": False}
DataLayerFactory(map=map, data=data)
page.goto(f"{live_server.url}{map.get_absolute_url()}#6/53.239/8.429")
polygon = page.locator("path").first
expect(polygon).to_have_css("pointer-events", "none")