Merge pull request #1362 from umap-project/hide-datalayer-in-caption

Allow to hide a datalayer from the caption list
This commit is contained in:
Yohan Boniface 2023-10-10 21:06:09 +02:00 committed by GitHub
commit 31ea8d1a83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 3 deletions

View file

@ -749,6 +749,7 @@ L.U.Map.include({
} }
const datalayerContainer = L.DomUtil.create('div', 'datalayer-container', container) const datalayerContainer = L.DomUtil.create('div', 'datalayer-container', container)
this.eachVisibleDataLayer((datalayer) => { this.eachVisibleDataLayer((datalayer) => {
if (!datalayer.options.inCaption) return
const p = L.DomUtil.create('p', 'datalayer-legend', datalayerContainer), const p = L.DomUtil.create('p', 'datalayer-legend', datalayerContainer),
legend = L.DomUtil.create('span', '', p), legend = L.DomUtil.create('span', '', p),
headline = L.DomUtil.create('strong', '', p), headline = L.DomUtil.create('strong', '', p),

View file

@ -192,6 +192,7 @@ L.U.Layer.Heat = L.HeatLayer.extend({
L.U.DataLayer = L.Evented.extend({ L.U.DataLayer = L.Evented.extend({
options: { options: {
displayOnLoad: true, displayOnLoad: true,
inCaption: true,
browsable: true, browsable: true,
editMode: 'advanced', editMode: 'advanced',
}, },
@ -863,6 +864,13 @@ L.U.DataLayer = L.Evented.extend({
helpEntries: 'browsable', helpEntries: 'browsable',
}, },
], ],
[
'options.inCaption',
{
label: L._('Show this layer in the caption'),
handler: 'Switch',
},
],
] ]
const title = L.DomUtil.add('h3', '', container, L._('Layer properties')) const title = L.DomUtil.add('h3', '', container, L._('Layer properties'))
let builder = new L.U.FormBuilder(this, metadataFields, { let builder = new L.U.FormBuilder(this, metadataFields, {

View file

@ -1,4 +1,5 @@
import json import json
import copy
import factory import factory
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
@ -102,13 +103,16 @@ class DataLayerFactory(factory.django.DjangoModelFactory):
name = "test datalayer" name = "test datalayer"
description = "test description" description = "test description"
display_on_load = True display_on_load = True
settings = {"displayOnLoad": True, "browsable": True, "name": name} settings = factory.Dict({"displayOnLoad": True, "browsable": True, "name": name})
@classmethod @classmethod
def _adjust_kwargs(cls, **kwargs): def _adjust_kwargs(cls, **kwargs):
data = kwargs.pop("data", DATALAYER_DATA).copy() data = kwargs.pop("data", copy.deepcopy(DATALAYER_DATA))
kwargs["settings"]["name"] = kwargs["name"] kwargs["settings"]["name"] = kwargs["name"]
data["_umap_options"] = kwargs["settings"] data["_umap_options"] = {
**DataLayerFactory.settings._defaults,
**kwargs["settings"],
}
kwargs["geojson"] = ContentFile(json.dumps(data), "foo.json") kwargs["geojson"] = ContentFile(json.dumps(data), "foo.json")
return kwargs return kwargs

View file

@ -3,6 +3,8 @@ from playwright.sync_api import expect
from umap.models import Map from umap.models import Map
from ..base import DataLayerFactory
pytestmark = pytest.mark.django_db pytestmark = pytest.mark.django_db
@ -35,3 +37,21 @@ def test_remote_layer_should_not_be_used_as_datalayer_for_created_features(
# A new datalayer has been created to host this created feature # A new datalayer has been created to host this created feature
# given the remote one cannot accept new features # given the remote one cannot accept new features
expect(layers).to_have_count(2) expect(layers).to_have_count(2)
def test_can_hide_datalayer_from_caption(map, live_server, datalayer, page):
# Faster than doing a login
map.edit_status = Map.ANONYMOUS
map.save()
# Add another DataLayer
other = DataLayerFactory(map=map, name="Hidden", settings={"inCaption": False})
page.goto(f"{live_server.url}{map.get_absolute_url()}")
toggle = page.get_by_text("About").first
expect(toggle).to_be_visible()
toggle.click()
layers = page.locator(".umap-caption .datalayer-legend")
expect(layers).to_have_count(1)
found = page.locator("#umap-ui-container").get_by_text(datalayer.name)
expect(found).to_be_visible()
hidden = page.locator("#umap-ui-container").get_by_text(other.name)
expect(hidden).to_be_hidden()