mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
fix: honour custom labelKey in default popup template (#2271)
The default popup template expects a `name` key, so let's populate it.
This commit is contained in:
commit
d38d8e152c
2 changed files with 13 additions and 0 deletions
|
@ -35,6 +35,7 @@ class PopupTemplate {
|
||||||
feature.properties.description || '',
|
feature.properties.description || '',
|
||||||
properties
|
properties
|
||||||
)
|
)
|
||||||
|
properties.name = properties.name ?? feature.getDisplayName()
|
||||||
let content = Utils.greedyTemplate(template, properties)
|
let content = Utils.greedyTemplate(template, properties)
|
||||||
content = Utils.toHTML(content, { target: target })
|
content = Utils.toHTML(content, { target: target })
|
||||||
return Utils.loadTemplate(`<div class="umap-popup-container text">${content}</div>`)
|
return Utils.loadTemplate(`<div class="umap-popup-container text">${content}</div>`)
|
||||||
|
|
|
@ -57,6 +57,18 @@ def test_should_handle_locale_var_in_description(live_server, map, page):
|
||||||
expect(link).to_have_attribute("href", "https://domain.org/?locale=en")
|
expect(link).to_have_attribute("href", "https://domain.org/?locale=en")
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_use_custom_label_key_in_popup_default_template(live_server, map, page):
|
||||||
|
data = deepcopy(DATALAYER_DATA)
|
||||||
|
data["features"][0]["properties"] = {
|
||||||
|
"libellé": "my custom label",
|
||||||
|
}
|
||||||
|
data["_umap_options"] = {"labelKey": "libellé"}
|
||||||
|
DataLayerFactory(map=map, data=data)
|
||||||
|
page.goto(f"{live_server.url}{map.get_absolute_url()}")
|
||||||
|
page.locator(".leaflet-marker-icon").click()
|
||||||
|
expect(page.locator(".umap-popup h4")).to_have_text("my custom label")
|
||||||
|
|
||||||
|
|
||||||
def test_should_display_tooltip_with_variable(live_server, map, page, bootstrap):
|
def test_should_display_tooltip_with_variable(live_server, map, page, bootstrap):
|
||||||
map.settings["properties"]["showLabel"] = True
|
map.settings["properties"]["showLabel"] = True
|
||||||
map.settings["properties"]["labelKey"] = "Foo {name}"
|
map.settings["properties"]["labelKey"] = "Foo {name}"
|
||||||
|
|
Loading…
Reference in a new issue