Skip to content

Commit

Permalink
Move layer specific settings to a dedicated fieldset
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanboniface committed Jan 3, 2024
1 parent fb6230d commit 00edf67
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 20 deletions.
14 changes: 8 additions & 6 deletions umap/static/umap/js/umap.forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,14 @@ L.FormBuilder.PopupContent = L.FormBuilder.Select.extend({
})

L.FormBuilder.LayerTypeChooser = L.FormBuilder.Select.extend({
selectOptions: [
['Default', L._('Default')],
['Cluster', L._('Clustered')],
['Heat', L._('Heatmap')],
['Choropleth', L._('Choropleth')],
],
getOptions: function () {
return [
[L.U.Layer.Default.TYPE, L.U.Layer.Default.NAME],
[L.U.Layer.Cluster.TYPE, L.U.Layer.Cluster.NAME],
[L.U.Layer.Heat.TYPE, L.U.Layer.Heat.NAME],
[L.U.Layer.Choropleth.TYPE, L.U.Layer.Choropleth.NAME],
]
},
})

L.FormBuilder.SlideshowDelay = L.FormBuilder.IntSelect.extend({
Expand Down
63 changes: 49 additions & 14 deletions umap/static/umap/js/umap.layer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
L.U.Layer = {
canBrowse: true,

getType: function () {
const proto = Object.getPrototypeOf(this)
return proto.constructor.TYPE
},

getName: function () {
const proto = Object.getPrototypeOf(this)
return proto.constructor.NAME
},

getFeatures: function () {
return this._layers
},
Expand All @@ -17,7 +27,10 @@ L.U.Layer = {
}

L.U.Layer.Default = L.FeatureGroup.extend({
_type: 'Default',
statics: {
NAME: L._('Default'),
TYPE: 'Default',
},
includes: [L.U.Layer],

initialize: function (datalayer) {
Expand All @@ -39,7 +52,10 @@ L.U.MarkerCluster = L.MarkerCluster.extend({
})

L.U.Layer.Cluster = L.MarkerClusterGroup.extend({
_type: 'Cluster',
statics: {
NAME: L._('Clustered'),
TYPE: 'Cluster',
},
includes: [L.U.Layer],

initialize: function (datalayer) {
Expand Down Expand Up @@ -117,7 +133,10 @@ L.U.Layer.Cluster = L.MarkerClusterGroup.extend({
})

L.U.Layer.Choropleth = L.FeatureGroup.extend({
_type: 'Choropleth',
statics: {
NAME: L._('Choropleth'),
TYPE: 'Choropleth',
},
includes: [L.U.Layer],
canBrowse: true,
// Have defaults that better suit the choropleth mode.
Expand Down Expand Up @@ -320,7 +339,10 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({
})

L.U.Layer.Heat = L.HeatLayer.extend({
_type: 'Heat',
statics: {
NAME: L._('Heatmap'),
TYPE: 'Heat',
},
includes: [L.U.Layer],
canBrowse: false,

Expand Down Expand Up @@ -615,7 +637,7 @@ L.U.DataLayer = L.Evented.extend({
// Only reset if type is defined (undefined is the default) and different from current type
if (
this.layer &&
(!this.options.type || this.options.type === this.layer._type) &&
(!this.options.type || this.options.type === this.layer.getType()) &&
!force
) {
return
Expand Down Expand Up @@ -1188,6 +1210,28 @@ L.U.DataLayer = L.Evented.extend({
})
container.appendChild(builder.build())

const redrawCallback = function (e) {
const field = e.helper.field,
builder = e.helper.builder
this.hide()
this.layer.onEdit(field, builder)
this.show()
}

const layerOptions = this.layer.getEditableOptions()

if (layerOptions.length) {
builder = new L.U.FormBuilder(this, layerOptions, {
id: 'datalayer-layer-properties',
callback: redrawCallback,
})
const layerProperties = L.DomUtil.createFieldset(
container,
`${this.layer.getName()}: ${L._('settings')}`
)
layerProperties.appendChild(builder.build())
}

let shapeOptions = [
'options.color',
'options.iconClass',
Expand All @@ -1201,13 +1245,6 @@ L.U.DataLayer = L.Evented.extend({
'options.fillOpacity',
]

const redrawCallback = function (e) {
const field = e.helper.field,
builder = e.helper.builder
this.hide()
this.layer.onEdit(field, builder)
this.show()
}
builder = new L.U.FormBuilder(this, shapeOptions, {
id: 'datalayer-advanced-properties',
callback: redrawCallback,
Expand All @@ -1224,8 +1261,6 @@ L.U.DataLayer = L.Evented.extend({
'options.labelKey',
]

optionsFields = optionsFields.concat(this.layer.getEditableOptions())

builder = new L.U.FormBuilder(this, optionsFields, {
id: 'datalayer-advanced-properties',
callback: redrawCallback,
Expand Down
45 changes: 45 additions & 0 deletions umap/tests/integration/test_edit_datalayer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from playwright.sync_api import expect


def test_should_have_fieldset_for_layer_type_properties(page, live_server, tilelayer):
page.goto(f"{live_server.url}/en/map/new/")

# Open DataLayers list
button = page.get_by_title("Manage Layers")
expect(button).to_be_visible()
button.click()

edit = page.locator("#umap-ui-container").get_by_title("Edit", exact=True)
expect(edit).to_be_visible()
edit.click()

select = page.locator("#umap-ui-container .umap-field-type select")
expect(select).to_be_visible()

choropleth_header = page.get_by_text("Choropleth: settings")
heat_header = page.get_by_text("Heatmap: settings")
cluster_header = page.get_by_text("Clustered: settings")
expect(choropleth_header).to_be_hidden()
expect(heat_header).to_be_hidden()
expect(cluster_header).to_be_hidden()

# Switching to Choropleth should add a dedicated fieldset
select.select_option("Choropleth")
expect(choropleth_header).to_be_visible()
expect(heat_header).to_be_hidden()
expect(cluster_header).to_be_hidden()

select.select_option("Heat")
expect(heat_header).to_be_visible()
expect(choropleth_header).to_be_hidden()
expect(cluster_header).to_be_hidden()

select.select_option("Cluster")
expect(cluster_header).to_be_visible()
expect(choropleth_header).to_be_hidden()
expect(heat_header).to_be_hidden()

select.select_option("Default")
expect(choropleth_header).to_be_hidden()
expect(heat_header).to_be_hidden()
expect(cluster_header).to_be_hidden()

0 comments on commit 00edf67

Please sign in to comment.