Skip to content

Commit

Permalink
feat(aliases): support for mapping tags to name.default aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink committed Jun 26, 2018
1 parent bfb04c8 commit 9e6cab5
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"undef": true,
"unused": false,
"maxparams": 4,
"maxdepth": 4,
"maxdepth": 5,
"maxlen": 140
}
28 changes: 25 additions & 3 deletions schema/name_osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,43 @@
eg. tags['alt_name'] -> doc.name['alternative']
The value 'default' is special, it defines the name used by default
for elasticsearch queries, it has the unique ability to specify multiple
keys with a value of 'default'.
When multiple keys have the value 'default' then they are considered
as aliases of the default field.
The '_primary' property defined below defines which of those aliases
is considered the 'primary default name' for label generation.
No values other than 'default' should be specified more than once.
@ref: http://wiki.openstreetmap.org/wiki/Key:name
@ref: http://wiki.openstreetmap.org/wiki/Names
**/

var OSM_NAMING_SCHEMA = {
'name': 'default',
'loc_name': 'local',
'alt_name': 'alternative',
'loc_name': 'default',
'alt_name': 'default',
'int_name': 'international',
'nat_name': 'national',
'official_name': 'official',
'old_name': 'old',
'reg_name': 'regional',
'short_name': 'short',
'short_name': 'default',
'sorting_name': 'sorting'
};

// this property is considered the 'primary name'
// for label generation, the others are considered
// secondary or 'aliases'.
Object.defineProperty(OSM_NAMING_SCHEMA, '_primary', {
value: 'name',
enumerable: false,
configurable: false,
writable: false
});

module.exports = OSM_NAMING_SCHEMA;
8 changes: 7 additions & 1 deletion stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ module.exports = function(){
else if( tag in NAME_SCHEMA ){
var val2 = trim( tags[tag] );
if( val2 ){
doc.setName( NAME_SCHEMA[tag], val2 );
if( tag === NAME_SCHEMA._primary ){
doc.setName( NAME_SCHEMA[tag], val2 );
} else if ( 'default' === NAME_SCHEMA[tag] ) {
doc.setNameAlias( NAME_SCHEMA[tag], val2 );
} else {
doc.setName( NAME_SCHEMA[tag], val2 );
}
}
}

Expand Down
Loading

0 comments on commit 9e6cab5

Please sign in to comment.