2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
Ox.load.Geo = function(options, callback) {
|
|
|
|
|
2012-06-17 09:31:19 +00:00
|
|
|
Ox.getJSON(Ox.PATH + 'Ox.Geo/json/Ox.Geo.json?' + Ox.VERSION, function(data) {
|
2011-04-27 19:24:33 +00:00
|
|
|
|
2012-06-24 15:33:13 +00:00
|
|
|
//@ Constants
|
2011-05-09 08:54:52 +00:00
|
|
|
|
|
|
|
/*@
|
|
|
|
Ox.COUNTRIES <[o]> Array of countries
|
2012-04-07 10:42:51 +00:00
|
|
|
A list of independent or de-facto independent countries and
|
2012-06-27 07:41:10 +00:00
|
|
|
dependencies since January 1, 1970 (see
|
|
|
|
<a href="http://en.wikipedia.org/wiki/List of sovereign states" target="_blank">Wikipedia</a>),
|
2012-04-07 10:42:51 +00:00
|
|
|
including other entities with
|
2012-06-27 07:41:10 +00:00
|
|
|
<a href="http://en.wikipedia.org/wiki/ISO 3166-1 alpha-2" target="_blank">ISO 3166-1 alpha-2</a>
|
2012-04-07 10:42:51 +00:00
|
|
|
country codes or country status at
|
2012-06-27 07:41:10 +00:00
|
|
|
<a href="http://www.imdb.com/country/" target="_blank">IMDb</a> or
|
|
|
|
<a href="http://www.fifa.com/worldranking/rankingtable/" target="_blank">FIFA</a>,
|
2012-04-07 10:42:51 +00:00
|
|
|
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
|
2012-06-27 07:41:10 +00:00
|
|
|
created <o|u> Present if the country was created since 1970
|
2012-04-07 10:42:51 +00:00
|
|
|
country <[s]> Preceding country or countries
|
|
|
|
created <s> "merged", "renamed" or "split"
|
|
|
|
date <s> Date of creation ("YYYY" or "YYYY-MM-DD")
|
2012-06-27 07:41:10 +00:00
|
|
|
dependencies <[s]|u> Array of dependencies of the country
|
|
|
|
dependency <[s]|u> Array of countries the country is a dependency of
|
|
|
|
disputed <[s]|u> Array of countries the country is disputed by
|
|
|
|
disputes <[s]|u> Array of countries the country disputes
|
|
|
|
dissolved <o|u> Present if the country was dissolved
|
2012-04-07 10:42:51 +00:00
|
|
|
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
|
2012-06-27 07:41:10 +00:00
|
|
|
independence <o|u> Present if the country became independent since 1970
|
2012-04-07 10:42:51 +00:00
|
|
|
country <[s]> Former country or countries
|
|
|
|
date <s> Date of independence ("YYYY" or "YYYY-MM-DD")
|
2012-06-27 07:41:10 +00:00
|
|
|
languages <[s]|u> Array of languages spoken in this country
|
2012-04-07 10:42:51 +00:00
|
|
|
To be precise: languages that are spoken in this country more
|
|
|
|
than in any other, i.e. each language only appears once. This
|
2012-05-27 19:38:02 +00:00
|
|
|
can be used to map languages to flag icons.
|
2012-04-07 10:42:51 +00:00
|
|
|
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
|
2012-06-27 07:41:10 +00:00
|
|
|
wikipediaName <s|u> The country's name according to Wikipedia
|
2012-04-07 10:42:51 +00:00
|
|
|
west <n> Longitude of the country's western boundary
|
2011-05-09 08:54:52 +00:00
|
|
|
<script>
|
|
|
|
Ox.test.array = [
|
2011-11-23 14:53:17 +00:00
|
|
|
// Current independent countries
|
2011-05-09 08:54:52 +00:00
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
2012-04-07 10:42:51 +00:00
|
|
|
return !c.dissolved && !c.dependency && !c.disputed && !c.exception
|
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) {
|
2012-04-07 10:42:51 +00:00
|
|
|
return !c.dissolved && c.dependency && !c.exception
|
2011-05-23 19:38:52 +00:00
|
|
|
}).length,
|
|
|
|
// Current disputed countries
|
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
2012-04-07 10:42:51 +00:00
|
|
|
return !c.dissolved && c.disputed && !c.exception
|
|
|
|
}).length,
|
|
|
|
// Current other entities
|
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
|
|
|
return !c.dissolved && c.exception
|
2011-05-09 08:54:52 +00:00
|
|
|
}).length,
|
2011-11-23 14:53:17 +00:00
|
|
|
// Dissolved independent countries
|
2011-05-09 08:54:52 +00:00
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
2012-04-07 10:42:51 +00:00
|
|
|
return c.dissolved && !c.dependency && !c.disputed && !c.exception
|
2011-05-23 19:38:52 +00:00
|
|
|
}).length,
|
2011-11-23 14:53:17 +00:00
|
|
|
// Dissolved dependent countries
|
2011-05-23 19:38:52 +00:00
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
2012-04-07 10:42:51 +00:00
|
|
|
return c.dissolved && c.dependency && !c.exception
|
2011-05-09 08:54:52 +00:00
|
|
|
}).length,
|
2011-11-23 14:53:17 +00:00
|
|
|
// Dissolved disputed countries
|
2011-05-09 08:54:52 +00:00
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
2012-04-07 10:42:51 +00:00
|
|
|
return c.dissolved && c.disputed && !c.exception
|
|
|
|
}).length,
|
|
|
|
// Dissolved other entities
|
|
|
|
Ox.COUNTRIES.filter(function(c) {
|
|
|
|
return c.dissolved && c.exception
|
2011-11-23 14:53:17 +00:00
|
|
|
}).length
|
2011-05-09 08:54:52 +00:00
|
|
|
];
|
|
|
|
</script>
|
|
|
|
> Ox.COUNTRIES.length
|
2012-04-07 10:42:51 +00:00
|
|
|
353
|
2011-05-09 08:54:52 +00:00
|
|
|
> Ox.sum(Ox.test.array)
|
2012-04-07 10:42:51 +00:00
|
|
|
353
|
2011-05-09 08:54:52 +00:00
|
|
|
> Ox.test.array
|
2012-04-07 10:42:51 +00:00
|
|
|
[196, 73, 9, 8, 28, 24, 14, 1]
|
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;
|
2012-03-26 19:26:28 +00:00
|
|
|
Ox.GEO_COLORS = {
|
2012-03-25 21:23:03 +00:00
|
|
|
|
|
|
|
'North America': [0, 0, 255],
|
|
|
|
'Northern America': [0, 0, 255],
|
|
|
|
|
|
|
|
'South America': [0, 255, 0],
|
|
|
|
'Southern America': [0, 255, 0],
|
|
|
|
'Caribbean': [192, 255, 192],
|
|
|
|
'Central America': [0, 128, 0],
|
|
|
|
|
|
|
|
'Europe': [255, 255, 0],
|
|
|
|
'Western Europe': [255, 255, 0],
|
|
|
|
'Northern Europe': [255, 255, 192],
|
|
|
|
'Southern Europe': [128, 128, 0],
|
|
|
|
'Eastern Europe': [255, 192, 0],
|
|
|
|
|
|
|
|
'Africa': [255, 0, 255],
|
|
|
|
'Northern Africa': [255, 0, 255],
|
|
|
|
'Southern Africa': [255, 128, 255],
|
|
|
|
'Middle Africa': [128, 0, 128],
|
|
|
|
'Western Africa': [128, 0, 255],
|
|
|
|
'Eastern Africa': [255, 0, 128],
|
|
|
|
|
|
|
|
'Asia': [255, 0, 0],
|
|
|
|
'Eastern Asia': [255, 0, 0],
|
|
|
|
'South-Eastern Asia': [255, 128, 128],
|
|
|
|
'Southern Asia': [128, 0, 0],
|
|
|
|
'Western Asia': [255, 128, 0],
|
|
|
|
'Central Asia': [128, 64, 0],
|
|
|
|
|
|
|
|
'Oceania': [0, 255, 255],
|
|
|
|
'Australia and New Zealand': [0, 255, 255],
|
|
|
|
'Micronesia': [192, 255, 255],
|
|
|
|
'Melanesia': [0, 128, 128],
|
|
|
|
'Polynesia': [128, 128, 255],
|
|
|
|
|
|
|
|
'Antarctica': [128, 128, 128]
|
|
|
|
|
|
|
|
};
|
2011-04-27 19:24:33 +00:00
|
|
|
|
2012-06-24 15:33:13 +00:00
|
|
|
//@ Functions
|
2011-05-09 08:54:52 +00:00
|
|
|
|
|
|
|
/*@
|
|
|
|
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'
|
|
|
|
@*/
|
2012-04-07 10:42:51 +00:00
|
|
|
Ox.getCountryByCode = Ox.getCountryByCountryCode = function(code) {
|
2011-04-27 19:24:33 +00:00
|
|
|
var country;
|
2012-03-26 09:58:42 +00:00
|
|
|
code = code.toUpperCase();
|
2011-04-27 19:24:33 +00:00
|
|
|
Ox.forEach(Ox.COUNTRIES, function(c) {
|
|
|
|
if (c.code == code) {
|
|
|
|
country = c;
|
2012-07-05 08:58:08 +00:00
|
|
|
return false; // break
|
2011-04-27 19:24:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
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'
|
2011-11-23 14:53:17 +00:00
|
|
|
> Ox.getCountryByGeoname('The Bottom, Saba, Bonaire, Sint Eustatius and Saba').code
|
2011-05-22 17:12:21 +00:00
|
|
|
'BQ'
|
|
|
|
@*/
|
|
|
|
Ox.getCountryByGeoname = function(geoname) {
|
2011-05-24 06:15:44 +00:00
|
|
|
// fixme: UAE correction doesn't belong here, fix in map
|
2012-03-26 11:07:57 +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()
|
2011-11-30 14:28:24 +00:00
|
|
|
.replace('Sint Eustatius and Saba', 'Bonaire, Sint Eustatius and Saba')
|
|
|
|
.replace('Ascension and Tristan da Cunha', 'Saint Helena, Ascension and Tristan da Cunha')
|
2011-05-22 17:12:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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;
|
2012-07-05 08:58:08 +00:00
|
|
|
return false; // break
|
2011-04-27 19:24:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return country;
|
|
|
|
};
|
|
|
|
|
2012-04-07 10:42:51 +00:00
|
|
|
/*@
|
|
|
|
Ox.getFlagByCountryCode <f> Returns an image URL for a given country code
|
2012-06-12 15:02:36 +00:00
|
|
|
(code[, size]) -> <s> Image URL
|
2012-04-07 10:42:51 +00:00
|
|
|
code <s> Country code (like 'FR')
|
|
|
|
size <n> Image size (16, 64 or 256)
|
|
|
|
@*/
|
2012-04-01 21:08:35 +00:00
|
|
|
Ox.getFlagByCountryCode = function(code, size) {
|
2012-04-07 10:42:51 +00:00
|
|
|
var country = Ox.getCountryByCode(code);
|
|
|
|
code = country ? country.code : 'NTHH';
|
2012-04-03 22:32:39 +00:00
|
|
|
size = size || 16;
|
2012-04-01 21:08:35 +00:00
|
|
|
return Ox.PATH + 'Ox.Geo/png/flags/' + size + '/' + code + '.png';
|
|
|
|
};
|
|
|
|
|
2011-10-02 13:17:04 +00:00
|
|
|
/*@
|
2012-04-07 10:42:51 +00:00
|
|
|
Ox.getFlagByGeoname <f> Returns an image URL for a given geoname
|
2012-06-12 15:02:36 +00:00
|
|
|
(geoname[, size]) -> <s> Image URL
|
2012-04-07 10:42:51 +00:00
|
|
|
geoname <s> Geoname (like 'France' or 'Paris, France')
|
|
|
|
size <n> Image size (16, 64 or 256)
|
2011-10-02 13:17:04 +00:00
|
|
|
@*/
|
2011-11-23 14:53:17 +00:00
|
|
|
Ox.getFlagByGeoname = function(geoname, size) {
|
2011-05-24 16:22:37 +00:00
|
|
|
var country = Ox.getCountryByGeoname(geoname),
|
2012-04-01 21:08:35 +00:00
|
|
|
code = country ? country.code : 'NTHH';
|
2012-04-03 22:32:39 +00:00
|
|
|
size = size || 16;
|
2011-11-23 14:53:17 +00:00
|
|
|
return Ox.PATH + 'Ox.Geo/png/flags/' + size + '/' + code + '.png';
|
2011-05-24 12:50:16 +00:00
|
|
|
};
|
|
|
|
|
2011-10-02 13:17:04 +00:00
|
|
|
/*@
|
2012-04-07 10:42:51 +00:00
|
|
|
Ox.getFlagByLanguage <f> Returns an image URL for a given language
|
2012-06-12 15:02:36 +00:00
|
|
|
(language[, size]) -> <s> Image URL
|
2012-04-07 10:42:51 +00:00
|
|
|
language <s> Language (like "French")
|
|
|
|
size <n> Image size (16, 64 or 256)
|
2011-10-02 13:17:04 +00:00
|
|
|
@*/
|
2011-11-23 14:53:17 +00:00
|
|
|
Ox.getFlagByLanguage = function(language, size) {
|
2011-11-23 15:25:07 +00:00
|
|
|
var country, code;
|
2012-04-07 10:42:51 +00:00
|
|
|
language = language.toLowerCase()
|
|
|
|
.replace(' languages', '')
|
|
|
|
.replace(' sign language', '');
|
2011-09-09 16:37:21 +00:00
|
|
|
Ox.COUNTRIES.forEach(function(c) {
|
2012-04-07 10:42:51 +00:00
|
|
|
if (c.languages && c.languages.map(function(language) {
|
|
|
|
return language.toLowerCase();
|
|
|
|
}).indexOf(language) > -1) {
|
2011-09-09 16:37:21 +00:00
|
|
|
country = c;
|
2012-07-05 08:58:08 +00:00
|
|
|
return false; // break
|
2011-09-09 16:37:21 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-23 14:53:17 +00:00
|
|
|
code = country ? country.flag || country.code : 'NTHH';
|
|
|
|
return Ox.PATH + 'Ox.Geo/png/flags/' + size + '/' + code + '.png';
|
2011-09-09 16:37:21 +00:00
|
|
|
};
|
|
|
|
|
2012-04-07 10:42:51 +00:00
|
|
|
/*@
|
|
|
|
Ox.getGeoColor <f> Returns a color for a continent or region
|
|
|
|
(str) -> <a> RGB
|
|
|
|
str <s> Continent or region
|
|
|
|
@*/
|
2012-03-25 21:23:03 +00:00
|
|
|
Ox.getGeoColor = function(str) {
|
2012-03-26 19:26:28 +00:00
|
|
|
return Ox.GEO_COLORS[str] || [128, 128, 128];
|
2012-03-25 21:23:03 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
callback(true);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-06-17 09:31:19 +00:00
|
|
|
}
|