fix: don't show default label if another is found in features edit

This commit is contained in:
Yohan Boniface 2024-11-22 10:37:00 +01:00
parent 78d6699a81
commit 1a88c11289

View file

@ -236,15 +236,23 @@ class Feature {
container.appendChild(builder.build())
const properties = []
let labelKeyFound = undefined
for (const property of this.datalayer._propertiesIndex) {
if ([U.DEFAULT_LABEL_KEY, 'description'].includes(property)) {
if (!labelKeyFound && U.LABEL_KEYS.includes(property)) {
labelKeyFound = property
continue
}
if (property === 'description') {
continue
}
properties.push([`properties.${property}`, { label: property }])
}
// We always want name and description for now (properties management to come)
properties.unshift('properties.description')
properties.unshift(`properties.${U.DEFAULT_LABEL_KEY}`)
if (!labelKeyFound) {
labelKeyFound = U.DEFAULT_LABEL_KEY
}
properties.unshift([`properties.${labelKeyFound}`, { label: labelKeyFound }])
builder = new U.FormBuilder(this, properties, {
id: 'umap-feature-properties',
})
@ -257,7 +265,7 @@ class Feature {
this.getAdvancedEditActions(advancedActions)
const onLoad = this._umap.editPanel.open({ content: container })
onLoad.then(() => {
builder.helpers['properties.name'].input.focus()
builder.helpers[`properties.${labelKeyFound}`].input.focus()
})
this._umap.editedFeature = this
if (!this.ui.isOnScreen(this._umap._leafletMap.getBounds())) this.zoomTo(event)
@ -330,7 +338,6 @@ class Feature {
}
for (const key of keys) {
const value = this.properties[key]
console.log(key, value)
if (value) return value
}
return this.datalayer.getName()