Geo module: add Ox.splitGeoname method
This commit is contained in:
parent
6937155dfc
commit
3c0e7e7bf5
1 changed files with 27 additions and 6 deletions
|
@ -172,12 +172,8 @@ Ox.load.Geo = function(options, callback) {
|
|||
Ox.getCountryByGeoname = function(geoname) {
|
||||
// fixme: UAE correction doesn't belong here, fix in map
|
||||
geoname = (geoname || '').replace(' - United Arab Emirates', ', United Arab Emirates')
|
||||
return Ox.getCountryByName(
|
||||
geoname.split(', ').pop()
|
||||
.replace('Sint Eustatius and Saba', 'Bonaire, Sint Eustatius and Saba')
|
||||
.replace('Ascension and Tristan da Cunha', 'Saint Helena, Ascension and Tristan da Cunha')
|
||||
);
|
||||
}
|
||||
return Ox.getCountryByName(Ox.splitGeoname(geoname).pop());
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.getCountryByName <f> Returns a country object for a given country name
|
||||
|
@ -257,6 +253,31 @@ Ox.load.Geo = function(options, callback) {
|
|||
return Ox.GEO_COLORS[str] || [128, 128, 128];
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.splitGeoname <f> Splits a geoname into its component parts
|
||||
(geoname) -> <[s]> Components
|
||||
geoname <s> Geoname
|
||||
@*/
|
||||
Ox.splitGeoname = function(geoname) {
|
||||
var countries = [
|
||||
'Bonaire, Sint Eustatius and Saba',
|
||||
'Saint Helena, Ascension and Tristan da Cunha'
|
||||
],
|
||||
split;
|
||||
countries.forEach(function(country) {
|
||||
if (Ox.endsWith(geoname, country)) {
|
||||
geoname = geoname.replace(country, country.replace(', ', '; '));
|
||||
}
|
||||
});
|
||||
split = geoname.split(', ');
|
||||
countries.forEach(function(country) {
|
||||
if (Ox.endsWith(Ox.last(split), country.replace(', ', '; '))) {
|
||||
Ox.last(split, country);
|
||||
}
|
||||
});
|
||||
return split;
|
||||
};
|
||||
|
||||
callback(true);
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue