geo/map bugfixes

This commit is contained in:
rolux 2011-11-24 19:38:10 +01:00
parent b6c74551fa
commit dfd2787438
14 changed files with 892 additions and 809 deletions

View file

@ -1,10 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>ox.js listmap demo</title
<title>OxJS ListMap Demo</title
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="../../build/Ox.js"></script>
<script type="text/javascript" src="../../source/_/ox.map.js"></script>
<script type="text/javascript" src="../../dev/Ox.js"></script>
<script type="text/javascript" src="js/listmap.js"></script>
</head>
<body>

View file

@ -1,52 +1,71 @@
Ox.load('UI', {
debug: true,
theme: 'modern'
}, function() {
Ox.load({UI: {}, Geo: {}}, function() {
Ox.load('Geo', function() {
var markerColor = {
'Northern America': [64, 64, 255],
'Central America': [0, 0, 255],
'Caribbean': [0, 0, 128],
'Southern America': [0, 255, 0],
'Northern Europe': [255, 255, 192],
'Western Europe': [255, 255, 0],
'Eastern Europe': [255, 128, 0],
'Southern Europe': [128, 128, 0],
'Northern Africa': [128, 128, 128],
'Western Africa': [64, 64, 128],
'Middle Africa': [64, 64, 64],
'Eastern Africa': [128, 64, 64],
'Southern Africa': [64, 128, 64],
'Western Asia': [255, 128, 128],
'Central Asia': [255, 0, 0],
'Eastern Asia': [128, 0, 0],
'Southern Asia': [255, 0, 255],
'South-Eastern Asia': [128, 0, 128],
'Australia and New Zealand': [0, 128, 128],
'Micronesia': [192, 255, 255],
'Melanesia': [0, 255, 255],
'Polynesia': [128, 128, 255],
'Antarctica': [192, 192, 192]
},
var listmap = new Ox.ListMap({
height: window.innerHeight,
places: Ox.map(Ox.COUNTRIES, function(place) {
return {
alternativeNames: place.googleName ? [place.googleName] : [],
area: place.area,
countryCode: place.code,
editable: true,
flag: place.code,
geoname: place.name,
id: place.code,
name: place.name,
type: 'country',
lat: place.lat,
lng: place.lng,
south: place.south,
west: place.west,
north: place.north,
east: place.east
};
}),
showTypes: true,
width: window.innerWidth
})
.bindEvent({
geocode: function(event, data) {
Ox.print(event)
Ox.print(JSON.stringify(data))
}
})
.appendTo(Ox.UI.$body);
$listmap = new Ox.ListMap({
height: window.innerHeight,
places: Ox.COUNTRIES.map(function(place) {
return {
alternativeNames: Ox.compact([place.google, place.imdb, place.wikipedia]),
area: place.area,
countryCode: place.code,
editable: true,
flag: place.code,
geoname: place.name,
id: place.code,
markerColor: markerColor[place.region] || [128,128,128],
name: place.name,
type: 'country',
lat: place.lat,
lng: place.lng,
south: place.south,
west: place.west,
north: place.north,
east: place.east
};
}),
width: window.innerWidth
})
.bindEvent({
geocode: function(event, data) {
Ox.print(event)
Ox.print(JSON.stringify(data))
}
})
.appendTo(Ox.UI.$body);
$(window).resize(function() {
Ox.print('RESIZE', window.innerHeight)
listmap.options({
height: window.innerHeight,
width: window.innerWidth
});
$(window).resize(function() {
Ox.print('RESIZE', window.innerHeight)
$listmap.options({
height: window.innerHeight,
width: window.innerWidth
});
window.listmap = listmap;
});
window.$listmap = $listmap;
});

View file

@ -1,36 +1,33 @@
Ox.load('UI', {
Ox.load({UI: {
debug: true,
hideScreen: true,
showScreen: true,
theme: 'modern'
}, function() {
Ox.load('Geo', function() {
}, Geo: {}}, function() {
Ox.getJSON('json/cities50000.json', function(cities) {
var places = cities.map(function(city, i) {
var countryCode = city.country_code == 'XK' ? 'RS-KO' : city.country_code,
marker = city.population > 10000000 ? {size: 24, color: [255, 0, 0]} :
city.population > 5000000 ? {size: 22, color: [255, 32, 0]} :
city.population > 2000000 ? {size: 20, color: [255, 64, 0]} :
city.population > 1000000 ? {size: 18, color: [255, 96, 0]} :
city.population > 500000 ? {size: 16, color: [255, 128, 0]} :
city.population > 200000 ? {size: 14, color: [255, 160, 0]} :
city.population > 100000 ? {size: 12, color: [255, 192, 0]} :
city.population > 50000 ? {size: 10, color: [255, 224, 0]} :
{size: 8, color: [255, 255, 0]},
area = Math.max(city.population, 1) * 100,
var area = Math.max(city.population, 1) * 100,
geoname = city.name + ', ' + Ox.getCountryByCode(city.country_code).name,
latSize = Math.sqrt(area) / Ox.EARTH_CIRCUMFERENCE * 360,
lngSize = Math.sqrt(area) * Ox.getDegreesPerMeter(city.latitude);
lngSize = Math.sqrt(area) * Ox.getDegreesPerMeter(city.latitude),
marker = city.population > 10000000 ? {size: 24, color: [255, 0, 0]}
: city.population > 5000000 ? {size: 22, color: [255, 32, 0]}
: city.population > 2000000 ? {size: 20, color: [255, 64, 0]}
: city.population > 1000000 ? {size: 18, color: [255, 96, 0]}
: city.population > 500000 ? {size: 16, color: [255, 128, 0]}
: city.population > 200000 ? {size: 14, color: [255, 160, 0]}
: city.population > 100000 ? {size: 12, color: [255, 192, 0]}
: city.population > 50000 ? {size: 10, color: [255, 224, 0]}
: {size: 8, color: [255, 255, 0]};
return {
alternativeNames: [],
area: area,
countryCode: countryCode,
countryCode: city.country_code,
editable: true,
flag: countryCode,
geoname: city.name + ', ' + Ox.getCountryByCode(countryCode).name,
geonameSort: getGeonameSort(city.name + ', ' + Ox.getCountryByCode(countryCode).name),
geoname: geoname,
geonameSort: getGeonameSort(geoname),
id: Ox.encodeBase32(Ox.uid()),
markerColor: marker.color,
markerSize: marker.size,
@ -206,6 +203,5 @@ Ox.load('Geo', function() {
}
});
});
});

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -58,7 +58,7 @@ Ox.ListMap = function(options, self) {
format: function(value, data) {
return $('<img>')
.attr({
src: Ox.getFlagByGeoname(data.name, 16)
src: Ox.getFlagByGeoname(data.geoname, 16)
})
.css({
width: '14px',

View file

@ -840,10 +840,10 @@ Ox.Map = function(options, self) {
self.places = [];
if (!self.isAsync) {
self.options.places.forEach(function(place, i) {
self.places[i] = new Ox.MapPlace(Ox.extend({
self.options.places.forEach(function(place) {
self.places.push(new Ox.MapPlace(Ox.extend({
map: that
}, place));
}, place)));
});
}
google.maps.event.trigger(self.map, 'resize');

View file

@ -206,15 +206,15 @@ Ox.MapMarker = function(options) {
//Ox.Log('Map', 'setOptions, that.map: ', that.map)
if (that.map.options('showTypes')) {
that.color = typeColor[that.place.type];
that.size = 8;
Ox.forEach(areaSize, function(size, area) {
if (that.place.area > area) {
that.size = size;
} else {
return false;
}
});
}
that.size = 8;
Ox.forEach(areaSize, function(size, area) {
if (that.place.area > area) {
that.size = size;
} else {
return false;
}
});
that.marker.setOptions({
// fixme: cursor remains pointer
cursor: that.place.editing ? 'move' : 'pointer',

View file

@ -1,44 +1,46 @@
Ox.load('UI', function() {
Ox.getJSONC('../jsonc/countries.jsonc', function(geo) {
var $map = $('<img>')
.attr({
id: 'map',
src: '../png/map.png'
}),
$bar = Ox.Bar({size: 24}),
$status = $('<div>')
.css({margin: '5px 0 0 8px'})
.appendTo($bar)
$panel = Ox.SplitPanel({
elements: [
{
element: $map
},
{
element: $bar,
size: 24
}
],
orientation: 'vertical'
})
.appendTo(Ox.UI.$body),
errors = [],
geocoder = new google.maps.Geocoder(),
json = [],
timeout = 2000;
Ox.getJSONC('../jsonc/countries.jsonc', function(data) {
Ox.getJSON('../json/countries.json', function(countries) {
var length = countries.length;
callGetData();
function callGetData() {
getData(countries.shift(), function(country) {
var $map = $('<img>')
.attr({
id: 'map',
src: '../png/map.png'
}),
$bar = Ox.Bar({size: 24}),
$status = $('<div>')
.css({margin: '5px 0 0 8px'})
.appendTo($bar),
$panel = Ox.SplitPanel({
elements: [
{
element: $map
},
{
element: $bar,
size: 24
}
],
orientation: 'vertical'
})
.appendTo(Ox.UI.$body),
errors = [],
geocoder = new google.maps.Geocoder(),
json = [],
length = countries.length,
timeout = 2000;
getNextCountry();
function getNextCountry() {
getCountryData(countries.shift(), function(country) {
addFlag(country);
json.push(country);
$status.html(json.length + '/' + length + ' ' + country.name);
if (countries.length) {
setTimeout(callGetData, timeout);
setTimeout(getNextCountry, timeout);
} else {
var $dialog = Ox.Dialog({
buttons: [
@ -58,200 +60,179 @@ Ox.load('UI', function() {
WebkitUserSelect: 'text'
})
.html(
'<code><pre>' + JSON.stringify(json, null, 4) + '</pre></code>'
'<code><pre>' + JSON.stringify(
errors.length ? {errors: errors, data: json} : json,
null, 4) + '</pre></code>'
),
height: window.innerHeight * 0.9 - 48,
title: 'Ox.Geo',
width: window.innerWidth * 0.9
}).open();
Ox.print('Errors:', errors);
$status.html(
errors.length
? 'Done, see console for errors.'
: 'Done, no errors.'
);
$status.html('');
}
});
}
});
function addFlag(country) {
var $div,
center = Ox.getXYByLatLng({lat: country.lat, lng: country.lng}),
crossesDateline = country.west > country.east,
height = $map.height(),
northEast = Ox.getXYByLatLng({lat: country.north, lng: country.east}),
southWest = Ox.getXYByLatLng({lat: country.south, lng: country.west}),
width = $map.width();
if (crossesDateline) {
$div = [
$('<div>')
.addClass('rect')
.css({
left: '-16px',
top: (height * northEast.y) + 'px',
right: (width - width * northEast.x) + 'px',
bottom: (height - height * southWest.y) + 'px',
})
.hide()
.appendTo(Ox.UI.$body),
$('<div>')
.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 = [
$('<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)
];
function addFlag(country) {
var $div,
center = Ox.getXYByLatLng({lat: country.lat, lng: country.lng}),
crossesDateline = country.west > country.east,
height = $map.height(),
northEast = Ox.getXYByLatLng({lat: country.north, lng: country.east}),
southWest = Ox.getXYByLatLng({lat: country.south, lng: country.west}),
width = $map.width();
if (crossesDateline) {
$div = [
$('<div>')
.addClass('rect')
.css({
left: '-16px',
top: (height * northEast.y) + 'px',
right: (width - width * northEast.x) + 'px',
bottom: (height - height * southWest.y) + 'px',
})
.hide()
.appendTo(Ox.UI.$body),
$('<div>')
.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 = [
$('<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)
];
}
$('<img>')
.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);
}
$('<img>')
.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));
}
});
});

View file

@ -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", "Kn 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": [

View file

@ -53,17 +53,14 @@ def get_countries():
html = read_wikipedia_url('ISO 3166-3')
matches = re.compile('<td id="([A-Z]{4})">.*?<a href="/wiki/(.*?)".*?>', 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('<tt>([A-Z]{2})</tt></td>\n<td><a href="/wiki/(.*?)"', re.DOTALL).findall(html)
countries += filter(lambda x: not exists(x), map(lambda x: parse(x), matches))
print sorted(map(lambda x: x['name'], countries))
# List of sovereign states
html = read_wikipedia_url('List of sovereign states')
matches = re.compile('>&#160;</span><a href="/wiki/(.*?)"', re.DOTALL).findall(html)
countries += filter(lambda x: not exists(x), map(lambda x: parse(x), matches))
print sorted(map(lambda x: x['name'], countries))
'''
for year in range(1970, 2020, 10):
html = read_wikipedia_url('List of sovereign states in the %ds' % year)
@ -119,7 +116,7 @@ def get_country_data(country):
for c, d in DATA['dependencies'].iteritems():
c = c.split(', ')
if name in c:
country['dependecies'] = d if not 'dependencies' in country else country['dependencies'] + d
country['dependencies'] = d if not 'dependencies' in country else country['dependencies'] + d
elif name in d:
country['dependency'] = c if not 'dependency' in country else country['dependency'] + c
# disputes
@ -152,10 +149,6 @@ def get_country_data(country):
country['languages'] = [language]
else:
country['languages'].append(language)
# location
if name in DATA['location']:
for key, value in DATA['location'][name].iteritems():
country[key] = value
return country
def get_flag(id):

View file

@ -1,6 +1,7 @@
import Image
import json
import os
import sys
svg_path = '../svg/icons/'
png_path = '../png/icons/4096/'
@ -21,16 +22,17 @@ for file in os.listdir(svg_path):
image = image.resize((size, size), Image.ANTIALIAS)
image.save(png_file.replace('/4096/', '/%d/' % size))
for file in os.listdir('../png/flags/'):
if file[-4:] == '.png':
country = file[:-4]
png_file = png_path + country + '.png'
print png_file
image = Image.open(png_file)
# include 4096 to overwrite manually generated image
for size in [4096, 1024, 256, 64, 16]:
image = image.resize((size, size), Image.ANTIALIAS)
image.save(png_file.replace('/4096/', '/%d/' % size))
if sys.argv[-1] == '-png':
for file in os.listdir('../png/flags/'):
if file[-4:] == '.png':
country = file[:-4]
png_file = png_path + country + '.png'
print png_file
image = Image.open(png_file)
# include 4096 to overwrite manually generated image
for size in [4096, 1024, 256, 64, 16]:
image = image.resize((size, size), Image.ANTIALIAS)
image.save(png_file.replace('/4096/', '/%d/' % size))
image = Image.new('RGB', (1152,1152))
f = open('../json/countries.json')