diff --git a/CHANGELOG.md b/CHANGELOG.md index efeed7a70..9911718d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ _Breaking developer changes, which may affect downstream projects or sites that #### :bug: Bugfixes * Fix hidden tooltips on map control toolbar ([#8781]) * Fix glitching out turn restriction minimap on narrow sidebars ([#8792]) +* Fix non-string properties of GeoJSON custom map data not being displayed correctly ([#8825], thanks [@k-yle]) * Fix a bug which made it impossible to switch to a custom TMS imagery layer after using a custom WMS source and vice versa ([#8057]) * Fix a bug where the validator might show wrong tagging suggestions for a preset if another preset has a partial match ([#8828], thanks [@bhousel]) * Show correct vintage and other metadata for "Esri World Imagery"'s higher zoom levels @@ -88,6 +89,7 @@ _Breaking developer changes, which may affect downstream projects or sites that [#8813]: https://github.com/openstreetmap/iD/issues/8813 [#8817]: https://github.com/openstreetmap/iD/pull/8817 [#8818]: https://github.com/openstreetmap/iD/issues/8818 +[#8825]: https://github.com/openstreetmap/iD/pull/8825 [#8828]: https://github.com/openstreetmap/iD/pull/8828 [#8831]: https://github.com/openstreetmap/iD/issues/8831 [#8836]: https://github.com/openstreetmap/iD/issues/8836 diff --git a/modules/svg/data.js b/modules/svg/data.js index 3ddea8c9e..a88e4b0ff 100644 --- a/modules/svg/data.js +++ b/modules/svg/data.js @@ -315,6 +315,21 @@ export function svgData(projection, context, dispatch) { } + function stringifyGeojsonProperties(feature) { + const properties = feature.properties; + for (const key in properties) { + const property = properties[key]; + if (typeof property === 'number' || typeof property === 'boolean' || Array.isArray(property)) { + properties[key] = property.toString(); + } else if (property === null) { + properties[key] = 'null'; + } else if (typeof property === 'object') { + properties[key] = JSON.stringify(property); + } + } + } + + drawData.setFile = function(extension, data) { _template = null; _fileList = null; @@ -332,6 +347,11 @@ export function svgData(projection, context, dispatch) { case '.geojson': case '.json': gj = JSON.parse(data); + if (gj.type === 'FeatureCollection') { + gj.features.forEach(stringifyGeojsonProperties); + } else if (gj.type === 'Feature') { + stringifyGeojsonProperties(gj); + } break; } diff --git a/modules/ui/sections/raw_tag_editor.js b/modules/ui/sections/raw_tag_editor.js index cc9776073..a4d558fac 100644 --- a/modules/ui/sections/raw_tag_editor.js +++ b/modules/ui/sections/raw_tag_editor.js @@ -11,6 +11,7 @@ import { t } from '../../core/localizer'; import { utilArrayDifference, utilArrayIdentical } from '../../util/array'; import { utilGetSetValue, utilNoAuto, utilRebind, utilTagDiff } from '../../util'; + export function uiSectionRawTagEditor(id, context) { var section = uiSection(id, context) diff --git a/test/spec/svg/data.js b/test/spec/svg/data.js index d064e1a77..6c2b70b2c 100644 --- a/test/spec/svg/data.js +++ b/test/spec/svg/data.js @@ -22,7 +22,11 @@ describe('iD.svgData', function () { ' "area": 19717.8,' + ' "name": "New Jersey",' + ' "name_en": "New Jersey",' + - ' "osm_id": 316973311' + + ' "osm_id": 316973311,' + + ' "flag": true,' + + ' "list": [1,2,3],' + + ' "null": null,' + + ' "object": {}' + ' },' + ' "id": 316973311' + ' }' + @@ -171,6 +175,11 @@ describe('iD.svgData', function () { path = surface.selectAll('path.stroke'); expect(path.nodes().length).to.eql(1); expect(path.attr('d')).to.match(/^M.*z$/); + expect(render.geojson().features[0].properties.osm_id).to.be.a('string'); + expect(render.geojson().features[0].properties.flag).to.be.a('string'); + expect(render.geojson().features[0].properties.list).to.be.a('string'); + expect(render.geojson().features[0].properties.null).to.be.a('string'); + expect(render.geojson().features[0].properties.object).to.be.a('string'); done(); }, 200); });