update documentation, and fix a few minor issues
This commit is contained in:
parent
14486398c2
commit
9b69d3d951
1 changed files with 88 additions and 49 deletions
|
@ -8,71 +8,94 @@ Ox.load.Geo = function(options, callback) {
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.COUNTRIES <[o]> Array of countries
|
Ox.COUNTRIES <[o]> Array of countries
|
||||||
A list of independent (or de-facto independent) countries and
|
A list of independent or de-facto independent countries and
|
||||||
dependencies (see
|
dependencies since January 1, 1970 (see
|
||||||
<a href="http://en.wikipedia.org/wiki/List_of_sovereign_states">Wikipedia</a>),
|
<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>
|
<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
|
country codes or country status at
|
||||||
<a href="http://en.wikipedia.org/wiki/ISO_3166-3">ISO 3166-3</a>
|
<a href="http://www.imdb.com/country/">IMDb</a> or
|
||||||
and <a href="http://www.imdb.com/country/">IMDb</a>.
|
<a href="http://www.fifa.com/worldranking/rankingtable/">FIFA</a>,
|
||||||
area <n> Area of the country in square meters
|
grouped by continents and regions (see
|
||||||
code <s> ISO 3166-1 alpha-2 country code
|
<a href="http://unstats.un.org/unsd/methods/m49/m49regin.htm">United Nations</a>).
|
||||||
created <o> FIXME: incomplete data
|
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
|
dependencies <[s]> Array of dependencies of the country
|
||||||
dependency <[s]> Array of countries the country is a dependency of
|
dependency <[s]> Array of countries the country is a dependency of
|
||||||
disputed <[s]> Array of countries the country is disputed by
|
disputed <[s]> Array of countries the country is disputed by
|
||||||
disputes <[s]> Array of countries the country disputes
|
disputes <[s]> Array of countries the country disputes
|
||||||
dissolved <o> Present if the country was dissolves
|
dissolved <o> Present if the country was dissolved
|
||||||
country <s|[s]> Succeeding country or countries
|
country <[s]> Succeeding country or countries
|
||||||
date <s> Date of dissolution
|
date <s> Date of dissolution ("YYYY" or "YYYY-MM-DD")
|
||||||
type <s> "joined", "merged", "renamed" or "split"
|
dissolved <s> "joined", "merged" or "renamed"
|
||||||
east <n> Longitude of eastern boundary in deg
|
east <n> Longitude of the country's eastern boundary
|
||||||
googleName <s|u> Google Maps country name
|
exception <b> True for exceptionally reserved ISO 3166-1 alpha-2 codes
|
||||||
imdbName <s|u> IMDb country name
|
(like "AC", "EU" or "UK")
|
||||||
languages <[s]> Array of languages that are spoken in this country more than in any other
|
flagURL <s> The country's flag (Wikipedia, SVG)
|
||||||
lat <n> Latitude of the center in deg
|
googleName <s|u> The country's name according to Google Maps
|
||||||
lng <n> Longitude of the center in deg
|
imdbName <s|u> The country's name according to IMDb
|
||||||
name <s> Name
|
independence <o> Present if the country became independent since 1970
|
||||||
north <n> Latitude of northern boundary in deg
|
country <[s]> Former country or countries
|
||||||
other <b> True if the country is an "other entity" (EU, FX, UK)
|
date <s> Date of independence ("YYYY" or "YYYY-MM-DD")
|
||||||
south <n> Latitude of southern boundary in deg
|
languages <[s]> Array of languages spoken in this country
|
||||||
wikipediaName <s> Wikipedia country name (http://en.wikipedia.org/wiki/$wikipediaName)
|
To be precise: languages that are spoken in this country more
|
||||||
west <n> Longitude of western boundary in deg
|
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>
|
<script>
|
||||||
Ox.test.array = [
|
Ox.test.array = [
|
||||||
// Current independent countries
|
// Current independent countries
|
||||||
Ox.COUNTRIES.filter(function(c) {
|
Ox.COUNTRIES.filter(function(c) {
|
||||||
return !c.dissolved && !c.dependency && !c.disputed
|
return !c.dissolved && !c.dependency && !c.disputed && !c.exception
|
||||||
}).length,
|
}).length,
|
||||||
// Current dependent countries
|
// Current dependent countries
|
||||||
Ox.COUNTRIES.filter(function(c) {
|
Ox.COUNTRIES.filter(function(c) {
|
||||||
return !c.dissolved && c.dependency
|
return !c.dissolved && c.dependency && !c.exception
|
||||||
}).length,
|
}).length,
|
||||||
// Current disputed countries
|
// Current disputed countries
|
||||||
Ox.COUNTRIES.filter(function(c) {
|
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,
|
}).length,
|
||||||
// Dissolved independent countries
|
// Dissolved independent countries
|
||||||
Ox.COUNTRIES.filter(function(c) {
|
Ox.COUNTRIES.filter(function(c) {
|
||||||
return c.dissolved && !c.dependency && !c.disputed
|
return c.dissolved && !c.dependency && !c.disputed && !c.exception
|
||||||
}).length,
|
}).length,
|
||||||
// Dissolved dependent countries
|
// Dissolved dependent countries
|
||||||
Ox.COUNTRIES.filter(function(c) {
|
Ox.COUNTRIES.filter(function(c) {
|
||||||
return c.dissolved && c.dependency
|
return c.dissolved && c.dependency && !c.exception
|
||||||
}).length,
|
}).length,
|
||||||
// Dissolved disputed countries
|
// Dissolved disputed countries
|
||||||
Ox.COUNTRIES.filter(function(c) {
|
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
|
}).length
|
||||||
];
|
];
|
||||||
</script>
|
</script>
|
||||||
> Ox.COUNTRIES.length
|
> Ox.COUNTRIES.length
|
||||||
319
|
353
|
||||||
> Ox.sum(Ox.test.array)
|
> Ox.sum(Ox.test.array)
|
||||||
319
|
353
|
||||||
> Ox.test.array
|
> Ox.test.array
|
||||||
[202, 77, 6, 22, 11, 1]
|
[196, 73, 9, 8, 28, 24, 14, 1]
|
||||||
@*/
|
@*/
|
||||||
|
|
||||||
Ox.COUNTRIES = data;
|
Ox.COUNTRIES = data;
|
||||||
|
@ -125,7 +148,7 @@ Ox.load.Geo = function(options, callback) {
|
||||||
> Ox.getCountryByCode('US').name
|
> Ox.getCountryByCode('US').name
|
||||||
'United States'
|
'United States'
|
||||||
@*/
|
@*/
|
||||||
Ox.getCountryByCode = function(code) {
|
Ox.getCountryByCode = Ox.getCountryByCountryCode = function(code) {
|
||||||
var country;
|
var country;
|
||||||
code = code.toUpperCase();
|
code = code.toUpperCase();
|
||||||
Ox.forEach(Ox.COUNTRIES, function(c) {
|
Ox.forEach(Ox.COUNTRIES, function(c) {
|
||||||
|
@ -176,17 +199,26 @@ Ox.load.Geo = function(options, callback) {
|
||||||
return country;
|
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) {
|
Ox.getFlagByCountryCode = function(code, size) {
|
||||||
|
var country = Ox.getCountryByCode(code);
|
||||||
|
code = country ? country.code : 'NTHH';
|
||||||
size = size || 16;
|
size = size || 16;
|
||||||
return Ox.PATH + 'Ox.Geo/png/flags/' + size + '/' + code + '.png';
|
return Ox.PATH + 'Ox.Geo/png/flags/' + size + '/' + code + '.png';
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.getImageByGeoname <f> Returns an image URL for a given geoname
|
Ox.getFlagByGeoname <f> Returns an image URL for a given geoname
|
||||||
(type, size, geoname) -> <s> Image URL
|
(geoname) -> <s> Image URL
|
||||||
type <s> Image type ('flag' or 'icon')
|
(geoname, size) -> Image URL
|
||||||
size <n> Image width (32, 256, 2048 (flag), 16, 256, 1024 (icon))
|
geoname <s> Geoname (like 'France' or 'Paris, France')
|
||||||
geoname <s> Geoname
|
size <n> Image size (16, 64 or 256)
|
||||||
@*/
|
@*/
|
||||||
Ox.getFlagByGeoname = function(geoname, size) {
|
Ox.getFlagByGeoname = function(geoname, size) {
|
||||||
var country = Ox.getCountryByGeoname(geoname),
|
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
|
Ox.getFlagByLanguage <f> Returns an image URL for a given language
|
||||||
(type, size, geoname) -> <s> Image URL
|
(language) -> <s> Image URL
|
||||||
type <s> Image type ('flag' or 'icon')
|
(language, size) -> Image URL
|
||||||
size <n> Image width (32, 256, 2048 (flag), 16, 256, 1024 (icon))
|
language <s> Language (like "French")
|
||||||
language <s> Language
|
size <n> Image size (16, 64 or 256)
|
||||||
@*/
|
@*/
|
||||||
Ox.getFlagByLanguage = function(language, size) {
|
Ox.getFlagByLanguage = function(language, size) {
|
||||||
language = language
|
|
||||||
.replace(' languages', '')
|
|
||||||
.replace(' Sign Language', '');
|
|
||||||
var country, code;
|
var country, code;
|
||||||
|
language = language.toLowerCase()
|
||||||
|
.replace(' languages', '')
|
||||||
|
.replace(' sign language', '');
|
||||||
Ox.COUNTRIES.forEach(function(c) {
|
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;
|
country = c;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -217,6 +251,11 @@ Ox.load.Geo = function(options, callback) {
|
||||||
return Ox.PATH + 'Ox.Geo/png/flags/' + size + '/' + code + '.png';
|
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) {
|
Ox.getGeoColor = function(str) {
|
||||||
return Ox.GEO_COLORS[str] || [128, 128, 128];
|
return Ox.GEO_COLORS[str] || [128, 128, 128];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue