diff --git a/stream/tag_mapper.js b/stream/tag_mapper.js index a670f315..dbec0974 100644 --- a/stream/tag_mapper.js +++ b/stream/tag_mapper.js @@ -50,7 +50,16 @@ module.exports = function(){ if( key === NAME_SCHEMA._primary ){ doc.setName( NAME_SCHEMA[key], val2 ); } else if ( 'default' === NAME_SCHEMA[key] ) { - doc.setNameAlias( NAME_SCHEMA[key], val2 ); + // `alt_name` may contain multiple names separated by semicolons + // (see https://wiki.openstreetmap.org/wiki/Key:alt_name#Examples) + if (key === 'alt_name') { + const altNames = val2.split(';'); + altNames.forEach((altName) => { + doc.setNameAlias( NAME_SCHEMA[key], altName ); + }); + } else { + doc.setNameAlias( NAME_SCHEMA[key], val2 ); + } } else { doc.setName( NAME_SCHEMA[key], val2 ); } diff --git a/test/stream/tag_mapper.js b/test/stream/tag_mapper.js index 6e896089..67dde09f 100644 --- a/test/stream/tag_mapper.js +++ b/test/stream/tag_mapper.js @@ -108,6 +108,33 @@ module.exports.tests.osm_names = function(test, common) { t.end(); // test will fail if not called (or called twice). next(); })); + + stream.write(doc); + }); + + test('maps - name aliases - multiple alt_names', function(t) { + var doc = new Document('a','b',1); + doc.setMeta('tags', { + loc_name: 'loc_name', + nat_name: 'nat_name', + int_name: 'int_name', + name: 'name', + alt_name: 'alt_name;alt_name2;alt_name3', + official_name: 'official_name', + old_name: 'old_name', + reg_name: 'reg_name', + short_name: 'short_name', + sorting_name: 'sorting_name' + }); + var stream = mapper(); + stream.pipe( through.obj( function( doc, enc, next ){ + t.equal(doc.getName('default'), 'name', 'correctly mapped'); + t.deepEqual(doc.getNameAliases('default'), ['loc_name','alt_name','alt_name2','alt_name3','short_name'], 'correctly mapped'); + + t.end(); // test will fail if not called (or called twice). + next(); + })); + stream.write(doc); }); };