Merge pull request #1315 from umap-project/dot-in-property

Remove dot in property name
This commit is contained in:
Yohan Boniface 2023-09-19 07:35:10 +02:00 committed by GitHub
commit 038a1a3c4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View file

@ -193,8 +193,7 @@ L.U.FeatureMixin = {
if (fallback === undefined) fallback = this.datalayer.options.name if (fallback === undefined) fallback = this.datalayer.options.name
const key = this.getOption('labelKey') || 'name' const key = this.getOption('labelKey') || 'name'
// Variables mode. // Variables mode.
if (L.Util.hasVar(key)) if (L.Util.hasVar(key)) return L.Util.greedyTemplate(key, this.extendedProperties())
return L.Util.greedyTemplate(key, this.extendedProperties())
// Simple mode. // Simple mode.
return this.properties[key] || this.properties.title || fallback return this.properties[key] || this.properties.title || fallback
}, },
@ -244,8 +243,17 @@ L.U.FeatureMixin = {
} }
}, },
cleanProperty: function ([key, value]) {
// dot in key will break the dot based property access
// while editing the feature
key = key.replace('.', '_')
return [key, value]
},
populate: function (feature) { populate: function (feature) {
this.properties = L.extend({}, feature.properties) this.properties = Object.fromEntries(
Object.entries(feature.properties || {}).map(this.cleanProperty)
)
this.properties._umap_options = L.extend( this.properties._umap_options = L.extend(
{}, {},
this.properties._storage_options, this.properties._storage_options,

View file

@ -148,6 +148,18 @@ describe('L.U.Map', function () {
assert.equal(this.datalayer._index.length, 2) assert.equal(this.datalayer._index.length, 2)
}) })
it('should remove dot in property name', function () {
this.datalayer.empty()
assert.equal(this.datalayer._index.length, 0)
textarea.value =
'{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [6.922931671142578, 47.481161607175736]}, "type": "Feature", "properties": {"color": "", "name": "Chez R\u00e9my", "A . in the name": ""}}, {"geometry": {"type": "LineString", "coordinates": [[2.4609375, 48.88639177703194], [2.48291015625, 48.76343113791796], [2.164306640625, 48.719961222646276]]}, "type": "Feature", "properties": {"color": "", "name": "P\u00e9rif", "with a dot.": ""}}]}'
changeSelectValue(formatSelect, 'geojson')
happen.click(submit)
assert.equal(this.datalayer._index.length, 2)
assert.ok(this.datalayer._propertiesIndex.includes('A _ in the name'))
assert.ok(this.datalayer._propertiesIndex.includes('with a dot_'))
})
it('should import osm from textarea', function () { it('should import osm from textarea', function () {
this.datalayer.empty() this.datalayer.empty()
happen.click(qs('a.upload-data')) happen.click(qs('a.upload-data'))