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:
commit
31ea8d1a83
4 changed files with 36 additions and 3 deletions
|
@ -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),
|
||||
|
|
|
@ -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, {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import copy
|
||||
|
||||
import factory
|
||||
from django.contrib.auth import get_user_model
|
||||
|
@ -102,13 +103,16 @@ class DataLayerFactory(factory.django.DjangoModelFactory):
|
|||
name = "test datalayer"
|
||||
description = "test description"
|
||||
display_on_load = True
|
||||
settings = {"displayOnLoad": True, "browsable": True, "name": name}
|
||||
settings = factory.Dict({"displayOnLoad": True, "browsable": True, "name": name})
|
||||
|
||||
@classmethod
|
||||
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"]
|
||||
data["_umap_options"] = kwargs["settings"]
|
||||
data["_umap_options"] = {
|
||||
**DataLayerFactory.settings._defaults,
|
||||
**kwargs["settings"],
|
||||
}
|
||||
kwargs["geojson"] = ContentFile(json.dumps(data), "foo.json")
|
||||
return kwargs
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue