Browse Source

Make street/number flipping configurable

pelias_config.api.localization.flipNumberAndStreetCountries can
define an array of ISO 3166-1 alpha-3 country codes, for which
the street number should come after street name.
pull/453/head
Vesa Meskanen 9 years ago
parent
commit
766b68ef7c
  1. 30
      middleware/localNamingConventions.js

30
middleware/localNamingConventions.js

@ -1,5 +1,20 @@
var check = require('check-types');
var flipNumberAndStreetCountries = ['DEU', 'FIN', 'SWE', 'NOR', 'DNK', 'ISL'];
function setup() { function setup() {
var api = require('pelias-config').generate().api;
var settings = api.localization;
if (settings && settings.flipNumberAndStreetCountries) {
var countries = settings.flipNumberAndStreetCountries;
for (var i=0; i<countries.length; i++) {
var country = countries[i];
if ( flipNumberAndStreetCountries.indexOf(country===-1) ) {
flipNumberAndStreetCountries.push(country);
}
}
}
return applyLocalNamingConventions; return applyLocalNamingConventions;
} }
@ -12,8 +27,17 @@ function applyLocalNamingConventions(req, res, next) {
// loop through data items and flip relevant number/street // loop through data items and flip relevant number/street
res.data.filter(function(place){ res.data.filter(function(place){
// only relevant for German addresses // relevant for some countries
if( place.parent.country_a.indexOf('DEU') === -1 ){ return false; } var flip = false;
for (var i=0; i<place.parent.country_a.length; i++) {
var country_a = place.parent.country_a[i];
if( flipNumberAndStreetCountries.indexOf(country_a) !== -1 ) {
flip = true;
break;
}
}
if (!flip){ return false; }
if( !place.hasOwnProperty('address') ){ return false; } if( !place.hasOwnProperty('address') ){ return false; }
if( !place.address.hasOwnProperty('number') ){ return false; } if( !place.address.hasOwnProperty('number') ){ return false; }
if( !place.address.hasOwnProperty('street') ){ return false; } if( !place.address.hasOwnProperty('street') ){ return false; }
@ -24,7 +48,7 @@ function applyLocalNamingConventions(req, res, next) {
next(); next();
} }
// DE address should have the housenumber and street name flipped // flip the housenumber and street name
// eg. '101 Grolmanstraße' -> 'Grolmanstraße 101' // eg. '101 Grolmanstraße' -> 'Grolmanstraße 101'
function flipNumberAndStreet(place) { function flipNumberAndStreet(place) {
var standard = ( place.address.number + ' ' + place.address.street ), var standard = ( place.address.number + ' ' + place.address.street ),

Loading…
Cancel
Save