2011-04-27 19:24:33 +00:00
|
|
|
Ox.load.Geo = function(options, callback) {
|
|
|
|
|
2011-05-07 15:56:29 +00:00
|
|
|
Ox.getJSON(Ox.PATH + 'Ox.Geo/json/Ox.Geo.json', function(data) {
|
2011-04-27 19:24:33 +00:00
|
|
|
|
2011-05-09 08:54:52 +00:00
|
|
|
//@ Constants ----------------------------------------------------------
|
|
|
|
|
|
|
|
/*@
|
|
|
|
Ox.COUNTRIES <[o]> Array of countries
|
2011-05-11 16:33:19 +00:00
|
|
|
A list of independent (or de-facto independent) countries and
|
|
|
|
dependencies (see
|
|
|
|
<a href="http://en.wikipedia.org/wiki/List_of_sovereign_states">Wikipedia</a>),
|
|
|
|
other entities with
|
|
|
|
<a href="http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166-1 alpha-2</a>
|
|
|
|
country codes, and former countries according to <a href="http://en.wikipedia.org/wiki/ISO_3166-3">ISO 3166-3</a>
|
|
|
|
and <a href="http://www.imdb.com/country/">IMDb</a>.
|
2011-05-09 08:54:52 +00:00
|
|
|
area <n> Area of the country in square meters
|
2011-05-11 16:33:19 +00:00
|
|
|
code <s> ISO 3166-1 alpha-2 country code
|
2011-05-23 19:38:52 +00:00
|
|
|
dependencies <[s]> Array of dependencies of the country
|
|
|
|
dependency <[s]> Array of countries the country is a dependency of
|
|
|
|
disputed <[s]> Array of countries the country is disputed by
|
|
|
|
disputes <[s]> Array of countries the country disputes
|
|
|
|
dissolved <[s]> Array of countries the country has been dissolved (merged, renamed or split) into
|
2011-05-09 08:54:52 +00:00
|
|
|
east <n> Longitude of eastern boundary in deg
|
2011-05-23 19:38:52 +00:00
|
|
|
googleName <s|u> Google Maps country name
|
|
|
|
imdbCode <s|u> IMDb country code
|
|
|
|
imdbName <s|u> IMDb country name
|
2011-10-02 13:17:04 +00:00
|
|
|
languages <[s]> Array of languages that are spoken in this country more than in any other
|
2011-05-09 08:54:52 +00:00
|
|
|
lat <n> Latitude of the center in deg
|
|
|
|
lng <n> Longitude of the center in deg
|
|
|
|
name <s> Name
|
|
|
|
north <n> Latitude of northern boundary in deg
|
|
|
|
other <b> True if the country is an "other entity" (EU, FX, UK)
|
|
|
|
south <n> Latitude of southern boundary in deg
|
|
|
|
wikipediaURL <s> URL of the wikipedia article for the country
|
|
|
|
west <n> Longitude of western boundary in deg
|
|
|
|
<script>
|
|
|
|
Ox.test.array = [
|
|
|
|
// Current independent countries with dependencies
|
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
2011-05-23 19:38:52 +00:00
|
|
|
return c.dependencies.length && !c.dissolved.length && !c.other;
|
2011-05-09 08:54:52 +00:00
|
|
|
}).length,
|
2011-05-23 19:38:52 +00:00
|
|
|
// Current independent countries with (fixme: not necessarily current) disputes
|
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
|
|
|
return c.disputes.length && !c.dissolved.length && !c.other;
|
|
|
|
}).length,
|
|
|
|
// Current independent countries without dependencies or disputes
|
2011-05-09 08:54:52 +00:00
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
2011-10-01 02:21:55 +00:00
|
|
|
return !c.dependencies.length && !c.dependency.length
|
|
|
|
&& !c.disputes.length && !c.disputed.length
|
|
|
|
&& !c.dissolved.length && !c.other;
|
2011-05-09 08:54:52 +00:00
|
|
|
}).length,
|
2011-05-23 19:38:52 +00:00
|
|
|
// Current dependent countries
|
2011-05-09 08:54:52 +00:00
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
2011-05-23 19:38:52 +00:00
|
|
|
return c.dependency.length && !c.dissolved.length && !c.other;
|
|
|
|
}).length,
|
|
|
|
// Current disputed countries
|
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
|
|
|
return c.disputed.length && !c.dissolved.length && !c.other;
|
2011-05-09 08:54:52 +00:00
|
|
|
}).length,
|
|
|
|
// Former independent countries with dependencies
|
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
2011-05-23 19:38:52 +00:00
|
|
|
return c.dependencies.length && c.dissolved.length && !c.other;
|
|
|
|
}).length,
|
|
|
|
// Former independent countries with disputes
|
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
|
|
|
return c.disputes.length && c.dissolved.length && !c.other;
|
2011-05-09 08:54:52 +00:00
|
|
|
}).length,
|
2011-05-23 19:38:52 +00:00
|
|
|
// Former independent countries without dependencies or disputes
|
2011-05-09 08:54:52 +00:00
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
2011-10-01 02:21:55 +00:00
|
|
|
return !c.dependencies.length && !c.dependency.length
|
|
|
|
&& !c.disputes.length && !c.disputed.length
|
|
|
|
&& c.dissolved.length && !c.other;
|
2011-05-23 19:38:52 +00:00
|
|
|
}).length,
|
|
|
|
// Former dependect countries
|
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
|
|
|
return c.dependency.length && c.dissolved.length && !c.other;
|
2011-05-09 08:54:52 +00:00
|
|
|
}).length,
|
2011-05-23 19:38:52 +00:00
|
|
|
// Former disputed countries
|
2011-05-09 08:54:52 +00:00
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
2011-05-23 19:38:52 +00:00
|
|
|
return c.disputed.length && c.dissolved.length && !c.other;
|
2011-05-09 08:54:52 +00:00
|
|
|
}).length,
|
|
|
|
// Other entities
|
|
|
|
Ox.COUNTRIES.filter(function(c) { return c.other; }).length
|
|
|
|
];
|
|
|
|
</script>
|
|
|
|
> Ox.COUNTRIES.length
|
|
|
|
311
|
|
|
|
> Ox.sum(Ox.test.array)
|
|
|
|
311
|
|
|
|
> Ox.test.array
|
2011-05-23 19:38:52 +00:00
|
|
|
[13, 8, 176, 73, 7, 1, 0, 16, 13, 1, 3]
|
2011-05-09 08:54:52 +00:00
|
|
|
@*/
|
2011-05-23 19:38:52 +00:00
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
Ox.COUNTRIES = data;
|
|
|
|
|
2011-05-09 08:54:52 +00:00
|
|
|
//@ Functions ----------------------------------------------------------
|
|
|
|
|
|
|
|
/*@
|
|
|
|
Ox.getCountryByCode <f> Returns a country object for a given country code
|
|
|
|
(code) -> <o> Country object
|
|
|
|
code <s> ISO 3166 country code
|
|
|
|
> Ox.getCountryByCode('US').name
|
|
|
|
'United States'
|
|
|
|
@*/
|
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
Ox.getCountryByCode = function(code) {
|
|
|
|
var country;
|
|
|
|
Ox.forEach(Ox.COUNTRIES, function(c) {
|
|
|
|
if (c.code == code) {
|
|
|
|
country = c;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return country;
|
|
|
|
};
|
|
|
|
|
2011-05-22 17:12:21 +00:00
|
|
|
/*@
|
|
|
|
Ox.getCountryByGeoname <f> Returns a country object for a given geoname
|
|
|
|
(name) -> <o> Country object
|
|
|
|
name <s> Geoname
|
|
|
|
> Ox.getCountryByGeoname('Los Angeles, California, United States').code
|
|
|
|
'US'
|
|
|
|
> Ox.getCountryByGeoname('The Bottom, Saba, Bonaire, Saint Eustatius and Saba').code
|
|
|
|
'BQ'
|
|
|
|
@*/
|
|
|
|
|
|
|
|
Ox.getCountryByGeoname = function(geoname) {
|
2011-05-24 06:15:44 +00:00
|
|
|
// fixme: UAE correction doesn't belong here, fix in map
|
2011-05-23 19:38:52 +00:00
|
|
|
geoname = geoname.replace(' - United Arab Emirates', ', United Arab Emirates')
|
2011-05-22 17:12:21 +00:00
|
|
|
return Ox.getCountryByName(
|
|
|
|
geoname.split(', ').pop()
|
|
|
|
.replace('Saint Eustatius', 'Bonaire, Saint Eustatius')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-05-09 08:54:52 +00:00
|
|
|
/*@
|
|
|
|
Ox.getCountryByName <f> Returns a country object for a given country name
|
|
|
|
(name) -> <o> Country object
|
|
|
|
name <s> Country name
|
|
|
|
> Ox.getCountryByName('United States').code
|
|
|
|
'US'
|
2011-05-23 19:38:52 +00:00
|
|
|
> Ox.getCountryByName('USA').code
|
|
|
|
'US'
|
2011-05-09 08:54:52 +00:00
|
|
|
@*/
|
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
Ox.getCountryByName = function(name) {
|
|
|
|
var country;
|
|
|
|
Ox.forEach(Ox.COUNTRIES, function(c) {
|
2011-09-09 23:05:04 +00:00
|
|
|
if (name == c.name || name == c.googleName || name == c.imdbName) {
|
2011-04-27 19:24:33 +00:00
|
|
|
country = c;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return country;
|
|
|
|
};
|
|
|
|
|
2011-10-02 13:17:04 +00:00
|
|
|
/*@
|
|
|
|
Ox.getImageByGeoname <f> Returns an image URL for a given geoname
|
|
|
|
(type, size, geoname) -> <s> Image URL
|
|
|
|
type <s> Image type ('flag' or 'icon')
|
|
|
|
size <n> Image width (32, 256, 2048 (flag), 16, 256, 1024 (icon))
|
|
|
|
geoname <s> Geoname
|
|
|
|
@*/
|
|
|
|
|
2011-05-24 16:22:37 +00:00
|
|
|
Ox.getImageByGeoname = function(type, size, geoname) {
|
|
|
|
var country = Ox.getCountryByGeoname(geoname),
|
|
|
|
code = country ? country.code : 'NTHH';
|
|
|
|
return Ox.PATH + 'Ox.Geo/png/' + type + 's/' + size + '/' + code + '.png';
|
2011-05-24 12:50:16 +00:00
|
|
|
};
|
|
|
|
|
2011-10-02 13:17:04 +00:00
|
|
|
/*@
|
|
|
|
Ox.getImageByLanguage <f> Returns an image URL for a given language
|
|
|
|
(type, size, geoname) -> <s> Image URL
|
|
|
|
type <s> Image type ('flag' or 'icon')
|
|
|
|
size <n> Image width (32, 256, 2048 (flag), 16, 256, 1024 (icon))
|
|
|
|
language <s> Language
|
|
|
|
@*/
|
|
|
|
|
2011-09-09 16:37:21 +00:00
|
|
|
Ox.getImageByLanguage = function(type, size, language) {
|
|
|
|
language = language
|
|
|
|
.replace(' languages', '')
|
|
|
|
.replace(' Sign Language', '');
|
|
|
|
var country = '', code;
|
|
|
|
Ox.COUNTRIES.forEach(function(c) {
|
|
|
|
if (c.languages.indexOf(language) > -1) {
|
|
|
|
country = c;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
code = country ? country.code : 'NTHH';
|
|
|
|
return Ox.PATH + 'Ox.Geo/png/' + type + 's/' + size + '/' + code + '.png';
|
|
|
|
};
|
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
callback(true);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|