update geo and geo tools (fix for palestine, remove image urls)

This commit is contained in:
rlx 2011-10-02 13:17:04 +00:00
parent 3fa654a815
commit 8e490eca2e
5 changed files with 6944 additions and 7547 deletions

View file

@ -22,10 +22,9 @@ Ox.load.Geo = function(options, callback) {
dissolved <[s]> Array of countries the country has been dissolved (merged, renamed or split) into dissolved <[s]> Array of countries the country has been dissolved (merged, renamed or split) into
east <n> Longitude of eastern boundary in deg east <n> Longitude of eastern boundary in deg
googleName <s|u> Google Maps country name googleName <s|u> Google Maps country name
imageURLs <o> Collection of dataURLs
marker <s> Map marker
imdbCode <s|u> IMDb country code imdbCode <s|u> IMDb country code
imdbName <s|u> IMDb 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 lat <n> Latitude of the center in deg
lng <n> Longitude of the center in deg lng <n> Longitude of the center in deg
name <s> Name name <s> Name
@ -155,12 +154,28 @@ Ox.load.Geo = function(options, callback) {
return country; return country;
}; };
/*@
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.getImageByGeoname = function(type, size, geoname) { Ox.getImageByGeoname = function(type, size, geoname) {
var country = Ox.getCountryByGeoname(geoname), var country = Ox.getCountryByGeoname(geoname),
code = country ? country.code : 'NTHH'; code = country ? country.code : 'NTHH';
return Ox.PATH + 'Ox.Geo/png/' + type + 's/' + size + '/' + code + '.png'; return Ox.PATH + 'Ox.Geo/png/' + type + 's/' + size + '/' + code + '.png';
}; };
/*@
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.getImageByLanguage = function(type, size, language) { Ox.getImageByLanguage = function(type, size, language) {
language = language language = language
.replace(' languages', '') .replace(' languages', '')

File diff suppressed because it is too large Load diff

View file

@ -870,15 +870,15 @@ Ox.Map = function(options, self) {
east: northEast.lng(), east: northEast.lng(),
editable: self.options.editable, editable: self.options.editable,
fullGeoname: getFullGeoname(data.address_components), fullGeoname: getFullGeoname(data.address_components),
geoname: data.formatted_address,
id: '_' + Ox.encodeBase32(Ox.uid()), id: '_' + Ox.encodeBase32(Ox.uid()),
map: that, map: that,
name: data.formatted_address.split(', ')[0],
north: northEast.lat(), north: northEast.lat(),
south: southWest.lat(), south: southWest.lat(),
type: getType(data.address_components[0].types), type: getType(data.address_components[0].types),
west: southWest.lng() west: southWest.lng()
}; };
place.geoname = data.formatted_address || place.fullGeoname;
place.name = (place.geoname || place.fullGeoname).split(', ')[0];
if (Math.abs(place.west) == 180 && Math.abs(place.east) == 180) { if (Math.abs(place.west) == 180 && Math.abs(place.east) == 180) {
place.west = -179.99999999; place.west = -179.99999999;
place.east = 179.99999999; place.east = 179.99999999;

View file

@ -103,7 +103,7 @@
if (countries.length) { if (countries.length) {
setTimeout(callGetData, timeout); setTimeout(callGetData, timeout);
} else { } else {
//Ox.print(logs); alert('Done');
} }
}); });
} }
@ -222,13 +222,13 @@
var addresses = geo.google_query[country.name] || [country.name], var addresses = geo.google_query[country.name] || [country.name],
length = addresses.length, length = addresses.length,
union; union;
// fixme: this might be too much data
// check if map really needs this preloaded
// (and even if, country markers may not be necessary)
getImageURLs(country, function(imageURLs) { getImageURLs(country, function(imageURLs) {
// this might be too much data
/*
Ox.extend(country, { Ox.extend(country, {
imageURLs: imageURLs imageURLs: imageURLs
}); });
*/
callGeocode(); callGeocode();
}); });
function callGeocode() { function callGeocode() {

View file

@ -9,7 +9,7 @@ import ox
import re import re
""" """
run this, then html/geo.html, then fix JSON run this, then html/geo.html, then py/fix_json.py
311 countries 311 countries
-- sovereign, dependent and disputed countries according to -- sovereign, dependent and disputed countries according to
@ -245,6 +245,7 @@ geo = {
'Kosovo': 'Kosova (Kosovo)', 'Kosovo': 'Kosova (Kosovo)',
'Macedonia': 'Former Yugoslav Republic of Macedonia', 'Macedonia': 'Former Yugoslav Republic of Macedonia',
'Myanmar': 'Burma', 'Myanmar': 'Burma',
'Palestine': 'Palestinian Territories',
'Republic of the Congo': 'Congo', 'Republic of the Congo': 'Congo',
'Sahrawi': 'Western Sahara', 'Sahrawi': 'Western Sahara',
'United Kingdom': 'UK', 'United Kingdom': 'UK',
@ -283,7 +284,7 @@ geo = {
'North Vietnam': ['Ha Giang, Vietnam', 'Lai Chau, Vietnam', 'Thua Thien-Hue, Vietnam'], 'North Vietnam': ['Ha Giang, Vietnam', 'Lai Chau, Vietnam', 'Thua Thien-Hue, Vietnam'],
'Northern Cyprus': ['Karpass, Cyprus', 'Kokkina, Cyprus', 'Lympia, Cyprus'], 'Northern Cyprus': ['Karpass, Cyprus', 'Kokkina, Cyprus', 'Lympia, Cyprus'],
'Pacific Islands': ['Marshall Islands', 'Micronesia', 'Northern Mariana Islands', 'Palau'], 'Pacific Islands': ['Marshall Islands', 'Micronesia', 'Northern Mariana Islands', 'Palau'],
'Palestine': ['71, Israel', 'El-arish Rafah, Egypt'], # 'Palestine': ['71, Israel', 'El-arish Rafah, Egypt'],
'Panama Canal Zone': ['Amador, Panama', 'Fort Sherman, Panama'], 'Panama Canal Zone': ['Amador, Panama', 'Fort Sherman, Panama'],
'Sahrawi': ['Western Sahara'], 'Sahrawi': ['Western Sahara'],
'Saint Helena': ['Ascension Island', 'Longwood, Saint Helena', 'Tristan da Cunha'], # in case results are us-biased 'Saint Helena': ['Ascension Island', 'Longwood, Saint Helena', 'Tristan da Cunha'], # in case results are us-biased
@ -1071,6 +1072,8 @@ def get_countries():
# google name # google name
if country['name'] in geo['google_name']: if country['name'] in geo['google_name']:
country['googleName'] = geo['google_name'][country['name']] country['googleName'] = geo['google_name'][country['name']]
else:
country['googleName'] = country['name']
# other # other
country['other'] = country['name'] in geo['other'] country['other'] = country['name'] in geo['other']
# imdb # imdb
@ -1097,23 +1100,28 @@ def get_country_flag(code, url):
# max width on wikipedia # max width on wikipedia
width = 2048 width = 2048
img = read_url(url) img = read_url(url)
file = '../png/flags/' + str(width) + '/' + code + '.png' png_file = '../png/flags/' + str(width) + '/' + code + '.png'
if url[-4:] == '.svg': if url[-4:] == '.svg':
write_file('../svg/flags/' + code + '.svg', img) svg_file = '../svg/flags/' + code + '.svg'
# fixme: remove conditional later update_image = not os.path.exists(svg_file) or read_file(svg_file) != img
# (wikipedia tended to time out) if update_image:
if not os.path.exists(file): write_file('../svg/flags/' + code + '.svg', img)
if not os.path.exists(png_file) or update_image:
png = read_url(url.replace('/commons/', '/commons/thumb/') + '/' + str(width) + 'px-.png') png = read_url(url.replace('/commons/', '/commons/thumb/') + '/' + str(width) + 'px-.png')
write_file(file, png) write_file(png_file, png)
png = Image.open(file) png = Image.open(png_file)
else: else:
write_file(file, img) update_image = not os.path.exists(png_file) or read_file(png_file) != img
png = Image.open(file) if update_image:
png = png.resize((width, int(round(width / png.size[0] * png.size[1]))), Image.ANTIALIAS) write_file(png_file, img)
write_image(file, png) png = Image.open(png_file)
png = png.resize((width, int(round(width / png.size[0] * png.size[1]))), Image.ANTIALIAS)
write_image(png_file, png)
else:
png = Image.open(png_file)
for width in [256, 32]: for width in [256, 32]:
file = '../png/flags/' + str(width) + '/' + code + '.png' file = '../png/flags/' + str(width) + '/' + code + '.png'
if not os.path.exists(file) or True: if not os.path.exists(file) or update_image:
png_ = png.resize((width, int(round(width / png.size[0] * png.size[1]))), Image.ANTIALIAS) png_ = png.resize((width, int(round(width / png.size[0] * png.size[1]))), Image.ANTIALIAS)
write_image(file, png_) write_image(file, png_)