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
east <n> Longitude of eastern boundary in deg
googleName <s|u> Google Maps country name
imageURLs <o> Collection of dataURLs
marker <s> Map marker
imdbCode <s|u> IMDb country code
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
@ -155,12 +154,28 @@ Ox.load.Geo = function(options, callback) {
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) {
var country = Ox.getCountryByGeoname(geoname),
code = country ? country.code : 'NTHH';
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) {
language = language
.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(),
editable: self.options.editable,
fullGeoname: getFullGeoname(data.address_components),
geoname: data.formatted_address,
id: '_' + Ox.encodeBase32(Ox.uid()),
map: that,
name: data.formatted_address.split(', ')[0],
north: northEast.lat(),
south: southWest.lat(),
type: getType(data.address_components[0].types),
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) {
place.west = -179.99999999;
place.east = 179.99999999;

View file

@ -103,7 +103,7 @@
if (countries.length) {
setTimeout(callGetData, timeout);
} else {
//Ox.print(logs);
alert('Done');
}
});
}
@ -222,13 +222,13 @@
var addresses = geo.google_query[country.name] || [country.name],
length = addresses.length,
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) {
// this might be too much data
/*
Ox.extend(country, {
imageURLs: imageURLs
});
*/
callGeocode();
});
function callGeocode() {

View file

@ -9,7 +9,7 @@ import ox
import re
"""
run this, then html/geo.html, then fix JSON
run this, then html/geo.html, then py/fix_json.py
311 countries
-- sovereign, dependent and disputed countries according to
@ -245,6 +245,7 @@ geo = {
'Kosovo': 'Kosova (Kosovo)',
'Macedonia': 'Former Yugoslav Republic of Macedonia',
'Myanmar': 'Burma',
'Palestine': 'Palestinian Territories',
'Republic of the Congo': 'Congo',
'Sahrawi': 'Western Sahara',
'United Kingdom': 'UK',
@ -283,7 +284,7 @@ geo = {
'North Vietnam': ['Ha Giang, Vietnam', 'Lai Chau, Vietnam', 'Thua Thien-Hue, Vietnam'],
'Northern Cyprus': ['Karpass, Cyprus', 'Kokkina, Cyprus', 'Lympia, Cyprus'],
'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'],
'Sahrawi': ['Western Sahara'],
'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
if country['name'] in geo['google_name']:
country['googleName'] = geo['google_name'][country['name']]
else:
country['googleName'] = country['name']
# other
country['other'] = country['name'] in geo['other']
# imdb
@ -1097,23 +1100,28 @@ def get_country_flag(code, url):
# max width on wikipedia
width = 2048
img = read_url(url)
file = '../png/flags/' + str(width) + '/' + code + '.png'
png_file = '../png/flags/' + str(width) + '/' + code + '.png'
if url[-4:] == '.svg':
write_file('../svg/flags/' + code + '.svg', img)
# fixme: remove conditional later
# (wikipedia tended to time out)
if not os.path.exists(file):
svg_file = '../svg/flags/' + code + '.svg'
update_image = not os.path.exists(svg_file) or read_file(svg_file) != img
if update_image:
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')
write_file(file, png)
png = Image.open(file)
write_file(png_file, png)
png = Image.open(png_file)
else:
write_file(file, img)
png = Image.open(file)
png = png.resize((width, int(round(width / png.size[0] * png.size[1]))), Image.ANTIALIAS)
write_image(file, png)
update_image = not os.path.exists(png_file) or read_file(png_file) != img
if update_image:
write_file(png_file, img)
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]:
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)
write_image(file, png_)