update documentation, and fix a few minor issues

This commit is contained in:
rolux 2012-04-07 12:42:51 +02:00
parent 14486398c2
commit 9b69d3d951

View file

@ -8,71 +8,94 @@ Ox.load.Geo = function(options, callback) {
/*@
Ox.COUNTRIES <[o]> Array of countries
A list of independent (or de-facto independent) countries and
dependencies (see
A list of independent or de-facto independent countries and
dependencies since January 1, 1970 (see
<a href="http://en.wikipedia.org/wiki/List_of_sovereign_states">Wikipedia</a>),
other entities with
including 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>.
area <n> Area of the country in square meters
code <s> ISO 3166-1 alpha-2 country code
created <o> FIXME: incomplete data
country codes or country status at
<a href="http://www.imdb.com/country/">IMDb</a> or
<a href="http://www.fifa.com/worldranking/rankingtable/">FIFA</a>,
grouped by continents and regions (see
<a href="http://unstats.un.org/unsd/methods/m49/m49regin.htm">United Nations</a>).
area <n> Area of the country's bounding box in square meters
code <s> ISO 3166-1 alpha-2, ISO 3166-2 or ISO 3166-3 country code
continent <s> The country's continent
created <o> Present if the country was created since 1970
country <[s]> Preceding country or countries
created <s> "merged", "renamed" or "split"
date <s> Date of creation ("YYYY" or "YYYY-MM-DD")
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 <o> Present if the country was dissolves
country <s|[s]> Succeeding country or countries
date <s> Date of dissolution
type <s> "joined", "merged", "renamed" or "split"
east <n> Longitude of eastern boundary in deg
googleName <s|u> Google Maps country name
imdbName <s|u> IMDb country name
languages <[s]> Array of languages that are spoken in this country more than in any other
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
wikipediaName <s> Wikipedia country name (http://en.wikipedia.org/wiki/$wikipediaName)
west <n> Longitude of western boundary in deg
dissolved <o> Present if the country was dissolved
country <[s]> Succeeding country or countries
date <s> Date of dissolution ("YYYY" or "YYYY-MM-DD")
dissolved <s> "joined", "merged" or "renamed"
east <n> Longitude of the country's eastern boundary
exception <b> True for exceptionally reserved ISO 3166-1 alpha-2 codes
(like "AC", "EU" or "UK")
flagURL <s> The country's flag (Wikipedia, SVG)
googleName <s|u> The country's name according to Google Maps
imdbName <s|u> The country's name according to IMDb
independence <o> Present if the country became independent since 1970
country <[s]> Former country or countries
date <s> Date of independence ("YYYY" or "YYYY-MM-DD")
languages <[s]> Array of languages spoken in this country
To be precise: languages that are spoken in this country more
than in any other, i.e. each language only appears once. This
can be useful if you need flag icons for languages.
lat <n> Latitude of the center of the country's bounding box
lng <n> Longitude of the center of the country's bounding box
name <s> Name of the country
north <n> Latitude of the country's northern boundary
region <s> The country's region
south <n> Latitude of the country's southern boundary
wikipediaName <s> The country's name according to Wikipedia
west <n> Longitude of the country's western boundary
<script>
Ox.test.array = [
// Current independent countries
Ox.COUNTRIES.filter(function(c) {
return !c.dissolved && !c.dependency && !c.disputed
return !c.dissolved && !c.dependency && !c.disputed && !c.exception
}).length,
// Current dependent countries
Ox.COUNTRIES.filter(function(c) {
return !c.dissolved && c.dependency
return !c.dissolved && c.dependency && !c.exception
}).length,
// Current disputed countries
Ox.COUNTRIES.filter(function(c) {
return !c.dissolved && c.disputed
return !c.dissolved && c.disputed && !c.exception
}).length,
// Current other entities
Ox.COUNTRIES.filter(function(c) {
return !c.dissolved && c.exception
}).length,
// Dissolved independent countries
Ox.COUNTRIES.filter(function(c) {
return c.dissolved && !c.dependency && !c.disputed
return c.dissolved && !c.dependency && !c.disputed && !c.exception
}).length,
// Dissolved dependent countries
Ox.COUNTRIES.filter(function(c) {
return c.dissolved && c.dependency
return c.dissolved && c.dependency && !c.exception
}).length,
// Dissolved disputed countries
Ox.COUNTRIES.filter(function(c) {
return c.dissolved && c.disputed
return c.dissolved && c.disputed && !c.exception
}).length,
// Dissolved other entities
Ox.COUNTRIES.filter(function(c) {
return c.dissolved && c.exception
}).length
];
</script>
> Ox.COUNTRIES.length
319
353
> Ox.sum(Ox.test.array)
319
353
> Ox.test.array
[202, 77, 6, 22, 11, 1]
[196, 73, 9, 8, 28, 24, 14, 1]
@*/
Ox.COUNTRIES = data;
@ -125,7 +148,7 @@ Ox.load.Geo = function(options, callback) {
> Ox.getCountryByCode('US').name
'United States'
@*/
Ox.getCountryByCode = function(code) {
Ox.getCountryByCode = Ox.getCountryByCountryCode = function(code) {
var country;
code = code.toUpperCase();
Ox.forEach(Ox.COUNTRIES, function(c) {
@ -176,17 +199,26 @@ Ox.load.Geo = function(options, callback) {
return country;
};
/*@
Ox.getFlagByCountryCode <f> Returns an image URL for a given country code
(code) -> <s> Image URL
(code, size) -> Image URL
code <s> Country code (like 'FR')
size <n> Image size (16, 64 or 256)
@*/
Ox.getFlagByCountryCode = function(code, size) {
var country = Ox.getCountryByCode(code);
code = country ? country.code : 'NTHH';
size = size || 16;
return Ox.PATH + 'Ox.Geo/png/flags/' + size + '/' + code + '.png';
};
/*@
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
Ox.getFlagByGeoname <f> Returns an image URL for a given geoname
(geoname) -> <s> Image URL
(geoname, size) -> Image URL
geoname <s> Geoname (like 'France' or 'Paris, France')
size <n> Image size (16, 64 or 256)
@*/
Ox.getFlagByGeoname = function(geoname, size) {
var country = Ox.getCountryByGeoname(geoname),
@ -196,19 +228,21 @@ Ox.load.Geo = function(options, callback) {
};
/*@
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
Ox.getFlagByLanguage <f> Returns an image URL for a given language
(language) -> <s> Image URL
(language, size) -> Image URL
language <s> Language (like "French")
size <n> Image size (16, 64 or 256)
@*/
Ox.getFlagByLanguage = function(language, size) {
language = language
.replace(' languages', '')
.replace(' Sign Language', '');
var country, code;
language = language.toLowerCase()
.replace(' languages', '')
.replace(' sign language', '');
Ox.COUNTRIES.forEach(function(c) {
if (c.languages && c.languages.indexOf(language) > -1) {
if (c.languages && c.languages.map(function(language) {
return language.toLowerCase();
}).indexOf(language) > -1) {
country = c;
return false;
}
@ -217,6 +251,11 @@ Ox.load.Geo = function(options, callback) {
return Ox.PATH + 'Ox.Geo/png/flags/' + size + '/' + code + '.png';
};
/*@
Ox.getGeoColor <f> Returns a color for a continent or region
(str) -> <a> RGB
str <s> Continent or region
@*/
Ox.getGeoColor = function(str) {
return Ox.GEO_COLORS[str] || [128, 128, 128];
};