')
+ .addClass('rect')
+ .css({
+ left: (width * southWest.x) + 'px',
+ top: (height * northEast.y) + 'px',
+ right: '-16px',
+ bottom: (height - height * southWest.y) + 'px',
+ })
+ .hide()
+ .appendTo(Ox.UI.$body)
+ ];
+ } else {
+ $div = [
+ $('
')
+ .addClass('rect')
+ .css({
+ left: ($map.width() * southWest.x) + 'px',
+ top: ($map.height() * northEast.y) + 'px',
+ right: ($map.width() - $map.width() * northEast.x) + 'px',
+ bottom: ($map.height() - $map.height() * southWest.y) + 'px',
+ })
+ .hide()
+ .appendTo(Ox.UI.$body)
+ ];
+ }
+ $('
')
+ .attr({
+ src: '../png/icons/16/' + country.code + '.png',
+ title: country.name
+ })
+ .addClass('flag')
+ .css({
+ left: (center.x * 100) + '%',
+ top: (center.y * 100) + '%'
+ })
+ .mouseenter(function() {
+ $(this).css({
+ zIndex: Ox.uid()
+ });
+ $.each($div, function() {
+ $(this).show();
+ });
+ })
+ .mouseleave(function() {
+ $.each($div, function() {
+ $(this).hide();
+ });
+ })
+ .appendTo(Ox.UI.$body);
}
- $('
')
- .attr({
- src: '../png/icons/16/' + country.code + '.png',
- title: country.name + ' ((' + country.south + ", " + country.west + "), (" + country.north + ", " + country.east + "))"
- })
- .addClass('flag')
- .css({
- left: (center.x * 100) + '%',
- top: (center.y * 100) + '%'
- })
- .mouseenter(function() {
- $(this).css({
- zIndex: Ox.uid()
- });
- $.each($div, function() {
- $(this).show();
- });
- })
- .mouseleave(function() {
- $.each($div, function() {
- $(this).hide();
- });
- })
- .appendTo(Ox.UI.$body);
- }
- function geocode(address, country, callback) {
- var bounds;
- if (!Ox.isUndefined(country.north)) {
- bounds = new google.maps.LatLngBounds(
- new google.maps.LatLng(country.south, country.west),
- new google.maps.LatLng(country.north, country.east)
- );
- callback({
- bounds: bounds,
- location: bounds.getCenter()
- });
- } else {
- geocoder.geocode({
- language: 'en',
- address: address
- }, function(results, status) {
- if (results && results.length) {
- var result = results[0];
- callback({
- bounds: result.geometry.bounds || result.geometry.viewport,
- location: result.geometry.location
- })
- } else {
- errors.push([address, status])
- callback(null);
- }
- });
- }
- }
-
- function getData(country, callback) {
- if (country.lat) {
- callback(country);
- return;
- }
- var addresses = geo.geocode[country.name] || [country.name],
- length = addresses.length,
- union;
- getImageURLs(country, function(imageURLs) {
- // this might be too much data
- /*
- Ox.extend(country, {
- imageURLs: imageURLs
- });
- */
- callGeocode();
- });
- function callGeocode() {
- geocode(addresses.shift(), country, function(data) {
- var center, lat, lng,
- northEast, southWest,
- east, north, south, west;
- if (data) {
- union = !union ? data.bounds : union.union(data.bounds);
- if (addresses.length == 0) {
- if (length == 1) {
- lat = data.location.lat();
- lng = data.location.lng();
- } else {
- center = union.getCenter();
- lat = center.lat();
- lng = center.lng();
- }
- northEast = union.getNorthEast();
- southWest = union.getSouthWest();
- east = northEast.lng();
- north = northEast.lat();
- south = southWest.lat();
- west = southWest.lng();
- callback($.extend(country, {
- area: Ox.getArea(
- {lat: south, lng: west},
- {lat: north, lng: east}
- ),
- east: toFixed(east),
- lat: toFixed(lat),
- lng: toFixed(lng),
- north: toFixed(north),
- south: toFixed(south),
- west: toFixed(west)
- }));
+ function geocode(geoname, callback) {
+ var bounds, location = data.location[geoname];
+ if (location) {
+ bounds = new google.maps.LatLngBounds(
+ new google.maps.LatLng(location.south, location.west),
+ new google.maps.LatLng(location.north, location.east)
+ );
+ callback({
+ bounds: bounds,
+ location: bounds.getCenter()
+ });
+ } else {
+ geocoder.geocode({
+ language: 'en',
+ address: geoname
+ }, function(results, status) {
+ if (results && results.length) {
+ var result = results[0];
+ callback({
+ bounds: result.geometry.bounds || result.geometry.viewport,
+ location: result.geometry.location
+ })
+ } else {
+ errors.push({geoname: geoname, status: status});
+ Ox.print('remove this print statement', errors)
+ callback(null);
}
- } else {
- callback(country);
- }
- });
- if (addresses.length) {
- setTimeout(callGeocode, timeout);
+ });
}
}
- }
- function getImageURLs(country, callback) {
- var image = new Image();
- image.onload = function() {
- callback({
- icon16: Ox.canvas(image).canvas.toDataURL()
- });
- };
- image.src = '../png/icons/16/' + country.code + '.png';
- }
+ function getCountryData(country, callback) {
- function toFixed(num) {
- return parseFloat(num.toFixed(8));
- }
+ var geonames = Ox.clone(data.geocode[country.name]) || [country.name],
+ length = geonames.length,
+ union;
+ getNextGeoname();
+
+ function getNextGeoname() {
+ geocode(geonames.shift(), function(geodata) {
+ var center, lat, lng,
+ northEast, southWest,
+ east, north, south, west;
+ if (geodata) {
+ union = !union ? geodata.bounds : union.union(geodata.bounds);
+ }
+ if (geonames.length) {
+ setTimeout(getNextGeoname, timeout);
+ } else {
+ if (union) {
+ if (length == 1) {
+ lat = geodata.location.lat();
+ lng = geodata.location.lng();
+ } else {
+ center = union.getCenter();
+ lat = center.lat();
+ lng = center.lng();
+ }
+ northEast = union.getNorthEast();
+ southWest = union.getSouthWest();
+ east = northEast.lng();
+ north = northEast.lat();
+ south = southWest.lat();
+ west = southWest.lng();
+ country = Ox.extend(country, {
+ area: Ox.getArea(
+ {lat: south, lng: west},
+ {lat: north, lng: east}
+ ),
+ east: toFixed(east),
+ lat: toFixed(lat),
+ lng: toFixed(lng),
+ north: toFixed(north),
+ south: toFixed(south),
+ west: toFixed(west)
+ });
+ }
+ callback(country);
+ }
+ });
+ }
+
+ }
+
+ function toFixed(num) {
+ return parseFloat(num.toFixed(10));
+ }
+
+ });
});
diff --git a/tools/geo/jsonc/countries.jsonc b/tools/geo/jsonc/countries.jsonc
index c85890e7..c74a020e 100644
--- a/tools/geo/jsonc/countries.jsonc
+++ b/tools/geo/jsonc/countries.jsonc
@@ -380,27 +380,26 @@
],
"geocode": {
// construction of countries unknown to the google maps geocoder
+ "Abkhazia": ["Abkhazia, Georgia"],
"Akrotiri and Dhekelia": ["Akrotiri, Cyprus", "Dhekelia, Cyprus"],
- "Bonaire, Saint Eustatius and Saba": ["Bonaire", "Saba, Netherlands Antilles", "Saint Eustatius"],
+ "Bonaire, Sint Eustatius and Saba": ["Bonaire", "Saba", "Sint Eustatius"],
"Byelorussian Soviet Socialist Republic": ["Belarus"],
+ "Canary Islands": ["Ferro, Canary Islands", "Isla Alegranza, Canary Islands"],
"Canton and Enderbury Islands": ["Canton Island", "Enderbury Island"],
"Ceuta and Melilla": ["Ceuta", "Melilla"],
- "Curaçao": ["Banda Abou, Curaçao"],
"Czechoslovakia": ["Czech Republic", "Slovakia"],
- "East Germany": [
- "Mecklenburg Vorpommern", "Saxony", "Thuringia"
- ],
+ "East Germany": ["Mecklenburg Vorpommern", "Saxony", "Thuringia"],
"Dahomey": ["Benin"],
- "European Union": ["Europe"],
+ "European Union": ["Cyprus", "Finland", "Greece", "Portugal"],
"French Afar and Issas": ["Djibouti"],
// see http://en.wikipedia.org/wiki/French_Southern_and_Antarctic_Lands
// and http://en.wikipedia.org/wiki/Scattered_Islands_in_the_Indian_Ocean
- "French Southern and Antarctic Territories": ["Adélie Land", "Bassas da India", "Glorioso Islands", "Île Kerguelen"],
- "French Southern Territories": ["Bassas da India", "Glorioso Islands", "Île Kerguelen"],
+ "French Southern and Antarctic Territories": ["Adélie Land", "Bassas da India", "Glorioso Islands"],
+ "French Southern Territories": ["Amsterdam Island", "Bassas da India", "Glorioso Islands", "Kerguelen Island"],
"Georgia": ["Georgia, Asia"],
// see http://en.wikipedia.org/wiki/Gilbert_Islands
"Gilbert and Ellice Islands": ["Arorae, Kiribati", "Butaritari, Kiribati", "Makin, Kiribati", "Tuvalu"],
- "Jamaica": ["Clarendon Parish, Jamaica", "St. James Parish, Jamaica", "St. Thomas Parish, Jamaica", "Westmoreland Parish, Jamaica"], // in case results are us-biased
+ // "Jamaica": ["Clarendon Parish, Jamaica", "St. James Parish, Jamaica", "St. Thomas Parish, Jamaica", "Westmoreland Parish, Jamaica"], // in case results are us-biased
"Jammu and Kashmir": ["Jammu and Kashmir, India"],
"Johnston Island": ["Johnston Atoll"],
"Korea": ["North Korea", "South Korea"],
@@ -409,7 +408,7 @@
"Neutral Zone": ["39944, Saudi Arabia", "76611, Saudi Arabia"],
"New Hebrides": ["Vanuatu"],
"North Vietnam": ["Ha Giang Province, Vietnam", "Lai Chau Province, Vietnam", "Thua Thien-Hue Province, Vietnam"],
- "North Yemen": ["Al Jawf, Yemen", "Hajjah, Yemen", "Ta'izz, Yemen"],
+ "North Yemen": ["Al Jawf, Yemen", "Hajjah, Yemen", "Ta'izz Province, Yemen"],
"Northern Cyprus": ["Karpass, Cyprus", "Kokkina, Cyprus", "Lympia, Cyprus"],
"Pacific Islands": ["Marshall Islands", "Micronesia", "Northern Mariana Islands", "Palau"],
// "Palestine": ["71, Israel", "El-arish Rafah, Egypt"],
@@ -419,21 +418,21 @@
"San Marino": ["San Marino, Europe"], // in case results are us-biased
"Serbia and Montenegro": ["Montenegro", "Serbia"],
"Siam": ["Thailand"],
- "Sint Maarten": ["Sint Maarten, Netherlands Antilles"],
+ "Sint Maarten": ["Great Bay, Sint Maarten", "Oyster Pond, Sint Maarten", "Simpson Bay Lagoon, Sint Maarten"],
"South Ossetia": ["Shida Kartli"],
// see http://en.wikipedia.org/wiki/Sudan#States_and_regions
// "South Sudan": [
// "Central Equatoria, Sudan", "Eastern Equatoria, Sudan", "Jonglei, Sudan", "Lakes, Sudan", "Northern Bahr el Ghazal, Sudan",
// "Upper Nile, Sudan", "Unity, Sudan", "Warrap, Sudan", "Western Bahr el Ghazal, Sudan", "Western Equatoria, Sudan"
// ],
- "South Vietnam": ["Ca Mau Province, Vietnam", "Da Nang Province, Vietnam", "Kiên Giang Province, Vietnam"],
+ "South Vietnam": ["Ca Mau Province, Vietnam", "Da Nang Province, Vietnam", "Khanh Hoa Province, Vietnam", "Kien Giang Province, Vietnam"],
"South Yemen": ["Al-Mahrah, Yemen", "Lahij, Yemen"],
"Soviet Union": [
"Armenia", "Azerbaijan", "Belarus", "Estonia", "Georgia, Europe",
"Latvia", "Lithuania", "Kazakhstan", "Kyrgyzstan", "Moldova",
"Russia", "Tajikistan", "Turkmenistan", "Ukraine", "Uzbekistan"
],
- "United Kingdom": ["England", "Northern Ireland", "Scotland", "Wales, United Kingdom"],
+ "United Kingdom": ["England", "Northern Ireland", "Scotland"],
"United States Minor Outlying Islands": [
"Baker Island, UM", "Howland Island", "Jarvis Island", "Johnston Atoll", "Kingman Reef",
"Midway Islands", "Palmyra Atoll", "Wake Island"
@@ -442,9 +441,7 @@
"United States Miscellaneous Pacific Islands": [
"Baker Island, UM", "Howland Island", "Jarvis Island", "Kingman Reef", "Palmyra Atoll"
],
- "UK": ["England", "Northern Ireland", "Scotland", "Wales, United Kingdom"],
"Upper Volta": ["Burkina Faso"],
- "Wake Island": ["Wake Atoll"],
"Wales": ["Wales, United Kingdom"],
"West Germany": ["Schleswig Holstein", "Northrhine Westphalia", "Bavaria, Germany"],
"Yugoslavia": [
diff --git a/tools/geo/py/geo.py b/tools/geo/py/geo.py
index fe736aab..e0dfb3cc 100644
--- a/tools/geo/py/geo.py
+++ b/tools/geo/py/geo.py
@@ -53,17 +53,14 @@ def get_countries():
html = read_wikipedia_url('ISO 3166-3')
matches = re.compile('
.*?', re.DOTALL).findall(html)
countries += map(lambda x: parse(x), matches)
- print sorted(map(lambda x: x['name'], countries))
# ISO 3166-1 alpha-2
html = fix(read_wikipedia_url('ISO 3166-1 alpha-2'))
matches = re.compile('([A-Z]{2}) | \n
|