diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index a364b231..66c8849d 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -749,6 +749,7 @@ L.U.Map.include({ } const datalayerContainer = L.DomUtil.create('div', 'datalayer-container', container) this.eachVisibleDataLayer((datalayer) => { + if (!datalayer.options.inCaption) return const p = L.DomUtil.create('p', 'datalayer-legend', datalayerContainer), legend = L.DomUtil.create('span', '', p), headline = L.DomUtil.create('strong', '', p), diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 7f0b03fc..21d41b52 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -192,6 +192,7 @@ L.U.Layer.Heat = L.HeatLayer.extend({ L.U.DataLayer = L.Evented.extend({ options: { displayOnLoad: true, + inCaption: true, browsable: true, editMode: 'advanced', }, @@ -863,6 +864,13 @@ L.U.DataLayer = L.Evented.extend({ helpEntries: 'browsable', }, ], + [ + 'options.inCaption', + { + label: L._('Show this layer in the caption'), + handler: 'Switch', + }, + ], ] const title = L.DomUtil.add('h3', '', container, L._('Layer properties')) let builder = new L.U.FormBuilder(this, metadataFields, { diff --git a/umap/tests/integration/test_map.py b/umap/tests/integration/test_map.py index a5dd0dbc..fdc8dc79 100644 --- a/umap/tests/integration/test_map.py +++ b/umap/tests/integration/test_map.py @@ -3,6 +3,8 @@ from playwright.sync_api import expect from umap.models import Map +from ..base import DataLayerFactory + 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 # given the remote one cannot accept new features 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()