fix bug with numeric properties in custom map data

This commit is contained in:
Kyle Hensel
2021-11-23 20:22:15 +13:00
parent f91ae8902f
commit cc0ae0a714
+16 -1
View File
@@ -11,6 +11,21 @@ import { t } from '../../core/localizer';
import { utilArrayDifference, utilArrayIdentical } from '../../util/array';
import { utilGetSetValue, utilNoAuto, utilRebind, utilTagDiff } from '../../util';
/**
* This component is also used for custom map data,
* and geojson can contain numbers as values.
* We convert numbers to strings to avoid unexpected bugs.
* @param {{ [key: string]: any }} tags
*/
function stringifyNumbers(tags) {
for (const key in tags) {
if (typeof tags[key] === 'number') {
tags[key] = tags[key].toString();
}
}
return tags;
}
export function uiSectionRawTagEditor(id, context) {
var section = uiSection(id, context)
@@ -594,7 +609,7 @@ export function uiSectionRawTagEditor(id, context) {
section.tags = function(val) {
if (!arguments.length) return _tags;
_tags = val;
_tags = stringifyNumbers(val);
return section;
};