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> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>ox.js listmap demo</title <title>OxJS ListMap Demo</title
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <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="../../dev/Ox.js"></script>
<script type="text/javascript" src="../../source/_/ox.map.js"></script>
<script type="text/javascript" src="js/listmap.js"></script> <script type="text/javascript" src="js/listmap.js"></script>
</head> </head>
<body> <body>

View file

@ -1,52 +1,71 @@
Ox.load('UI', { Ox.load({UI: {}, Geo: {}}, function() {
debug: true,
theme: 'modern'
}, 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({ $listmap = new Ox.ListMap({
height: window.innerHeight, height: window.innerHeight,
places: Ox.map(Ox.COUNTRIES, function(place) { places: Ox.COUNTRIES.map(function(place) {
return { return {
alternativeNames: place.googleName ? [place.googleName] : [], alternativeNames: Ox.compact([place.google, place.imdb, place.wikipedia]),
area: place.area, area: place.area,
countryCode: place.code, countryCode: place.code,
editable: true, editable: true,
flag: place.code, flag: place.code,
geoname: place.name, geoname: place.name,
id: place.code, id: place.code,
name: place.name, markerColor: markerColor[place.region] || [128,128,128],
type: 'country', name: place.name,
lat: place.lat, type: 'country',
lng: place.lng, lat: place.lat,
south: place.south, lng: place.lng,
west: place.west, south: place.south,
north: place.north, west: place.west,
east: place.east north: place.north,
}; east: place.east
}), };
showTypes: true, }),
width: window.innerWidth width: window.innerWidth
}) })
.bindEvent({ .bindEvent({
geocode: function(event, data) { geocode: function(event, data) {
Ox.print(event) Ox.print(event)
Ox.print(JSON.stringify(data)) Ox.print(JSON.stringify(data))
} }
}) })
.appendTo(Ox.UI.$body); .appendTo(Ox.UI.$body);
$(window).resize(function() { $(window).resize(function() {
Ox.print('RESIZE', window.innerHeight) Ox.print('RESIZE', window.innerHeight)
listmap.options({ $listmap.options({
height: window.innerHeight, height: window.innerHeight,
width: window.innerWidth width: window.innerWidth
});
}); });
window.listmap = listmap;
}); });
window.$listmap = $listmap;
}); });

View file

@ -1,36 +1,33 @@
Ox.load('UI', { Ox.load({UI: {
debug: true, debug: true,
hideScreen: true, hideScreen: true,
showScreen: true, showScreen: true,
theme: 'modern' theme: 'modern'
}, function() { }, Geo: {}}, function() {
Ox.load('Geo', function() {
Ox.getJSON('json/cities50000.json', function(cities) { Ox.getJSON('json/cities50000.json', function(cities) {
var places = cities.map(function(city, i) { var places = cities.map(function(city, i) {
var countryCode = city.country_code == 'XK' ? 'RS-KO' : city.country_code, var area = Math.max(city.population, 1) * 100,
marker = city.population > 10000000 ? {size: 24, color: [255, 0, 0]} : geoname = city.name + ', ' + Ox.getCountryByCode(city.country_code).name,
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,
latSize = Math.sqrt(area) / Ox.EARTH_CIRCUMFERENCE * 360, 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 { return {
alternativeNames: [], alternativeNames: [],
area: area, area: area,
countryCode: countryCode, countryCode: city.country_code,
editable: true, editable: true,
flag: countryCode, geoname: geoname,
geoname: city.name + ', ' + Ox.getCountryByCode(countryCode).name, geonameSort: getGeonameSort(geoname),
geonameSort: getGeonameSort(city.name + ', ' + Ox.getCountryByCode(countryCode).name),
id: Ox.encodeBase32(Ox.uid()), id: Ox.encodeBase32(Ox.uid()),
markerColor: marker.color, markerColor: marker.color,
markerSize: marker.size, markerSize: marker.size,
@ -208,4 +205,3 @@ 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) { format: function(value, data) {
return $('<img>') return $('<img>')
.attr({ .attr({
src: Ox.getFlagByGeoname(data.name, 16) src: Ox.getFlagByGeoname(data.geoname, 16)
}) })
.css({ .css({
width: '14px', width: '14px',

View file

@ -840,10 +840,10 @@ Ox.Map = function(options, self) {
self.places = []; self.places = [];
if (!self.isAsync) { if (!self.isAsync) {
self.options.places.forEach(function(place, i) { self.options.places.forEach(function(place) {
self.places[i] = new Ox.MapPlace(Ox.extend({ self.places.push(new Ox.MapPlace(Ox.extend({
map: that map: that
}, place)); }, place)));
}); });
} }
google.maps.event.trigger(self.map, 'resize'); 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) //Ox.Log('Map', 'setOptions, that.map: ', that.map)
if (that.map.options('showTypes')) { if (that.map.options('showTypes')) {
that.color = typeColor[that.place.type]; 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({ that.marker.setOptions({
// fixme: cursor remains pointer // fixme: cursor remains pointer
cursor: that.place.editing ? 'move' : 'pointer', cursor: that.place.editing ? 'move' : 'pointer',

View file

@ -1,44 +1,46 @@
Ox.load('UI', function() { Ox.load('UI', function() {
Ox.getJSONC('../jsonc/countries.jsonc', function(geo) { Ox.getJSONC('../jsonc/countries.jsonc', function(data) {
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.getJSON('../json/countries.json', function(countries) { Ox.getJSON('../json/countries.json', function(countries) {
var length = countries.length;
callGetData(); var $map = $('<img>')
function callGetData() { .attr({
getData(countries.shift(), function(country) { 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); addFlag(country);
json.push(country); json.push(country);
$status.html(json.length + '/' + length + ' ' + country.name); $status.html(json.length + '/' + length + ' ' + country.name);
if (countries.length) { if (countries.length) {
setTimeout(callGetData, timeout); setTimeout(getNextCountry, timeout);
} else { } else {
var $dialog = Ox.Dialog({ var $dialog = Ox.Dialog({
buttons: [ buttons: [
@ -58,200 +60,179 @@ Ox.load('UI', function() {
WebkitUserSelect: 'text' WebkitUserSelect: 'text'
}) })
.html( .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, height: window.innerHeight * 0.9 - 48,
title: 'Ox.Geo', title: 'Ox.Geo',
width: window.innerWidth * 0.9 width: window.innerWidth * 0.9
}).open(); }).open();
Ox.print('Errors:', errors); $status.html('');
$status.html(
errors.length
? 'Done, see console for errors.'
: 'Done, no errors.'
);
} }
}); });
} }
});
function addFlag(country) { function addFlag(country) {
var $div, var $div,
center = Ox.getXYByLatLng({lat: country.lat, lng: country.lng}), center = Ox.getXYByLatLng({lat: country.lat, lng: country.lng}),
crossesDateline = country.west > country.east, crossesDateline = country.west > country.east,
height = $map.height(), height = $map.height(),
northEast = Ox.getXYByLatLng({lat: country.north, lng: country.east}), northEast = Ox.getXYByLatLng({lat: country.north, lng: country.east}),
southWest = Ox.getXYByLatLng({lat: country.south, lng: country.west}), southWest = Ox.getXYByLatLng({lat: country.south, lng: country.west}),
width = $map.width(); width = $map.width();
if (crossesDateline) { if (crossesDateline) {
$div = [ $div = [
$('<div>') $('<div>')
.addClass('rect') .addClass('rect')
.css({ .css({
left: '-16px', left: '-16px',
top: (height * northEast.y) + 'px', top: (height * northEast.y) + 'px',
right: (width - width * northEast.x) + 'px', right: (width - width * northEast.x) + 'px',
bottom: (height - height * southWest.y) + 'px', bottom: (height - height * southWest.y) + 'px',
}) })
.hide() .hide()
.appendTo(Ox.UI.$body), .appendTo(Ox.UI.$body),
$('<div>') $('<div>')
.addClass('rect') .addClass('rect')
.css({ .css({
left: (width * southWest.x) + 'px', left: (width * southWest.x) + 'px',
top: (height * northEast.y) + 'px', top: (height * northEast.y) + 'px',
right: '-16px', right: '-16px',
bottom: (height - height * southWest.y) + 'px', bottom: (height - height * southWest.y) + 'px',
}) })
.hide() .hide()
.appendTo(Ox.UI.$body), .appendTo(Ox.UI.$body)
];
]; } else {
} else { $div = [
$div = [ $('<div>')
$('<div>') .addClass('rect')
.addClass('rect') .css({
.css({ left: ($map.width() * southWest.x) + 'px',
left: ($map.width() * southWest.x) + 'px', top: ($map.height() * northEast.y) + 'px',
top: ($map.height() * northEast.y) + 'px', right: ($map.width() - $map.width() * northEast.x) + 'px',
right: ($map.width() - $map.width() * northEast.x) + 'px', bottom: ($map.height() - $map.height() * southWest.y) + 'px',
bottom: ($map.height() - $map.height() * southWest.y) + 'px', })
}) .hide()
.hide() .appendTo(Ox.UI.$body)
.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) { function geocode(geoname, callback) {
var bounds; var bounds, location = data.location[geoname];
if (!Ox.isUndefined(country.north)) { if (location) {
bounds = new google.maps.LatLngBounds( bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(country.south, country.west), new google.maps.LatLng(location.south, location.west),
new google.maps.LatLng(country.north, country.east) new google.maps.LatLng(location.north, location.east)
); );
callback({ callback({
bounds: bounds, bounds: bounds,
location: bounds.getCenter() location: bounds.getCenter()
}); });
} else { } else {
geocoder.geocode({ geocoder.geocode({
language: 'en', language: 'en',
address: address address: geoname
}, function(results, status) { }, function(results, status) {
if (results && results.length) { if (results && results.length) {
var result = results[0]; var result = results[0];
callback({ callback({
bounds: result.geometry.bounds || result.geometry.viewport, bounds: result.geometry.bounds || result.geometry.viewport,
location: result.geometry.location location: result.geometry.location
}) })
} else { } else {
errors.push([address, status]) errors.push({geoname: geoname, status: status});
callback(null); Ox.print('remove this print statement', errors)
} 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)
}));
} }
} else { });
callback(country);
}
});
if (addresses.length) {
setTimeout(callGeocode, timeout);
} }
} }
}
function getImageURLs(country, callback) { function getCountryData(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 toFixed(num) { var geonames = Ox.clone(data.geocode[country.name]) || [country.name],
return parseFloat(num.toFixed(8)); 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": { "geocode": {
// construction of countries unknown to the google maps geocoder // construction of countries unknown to the google maps geocoder
"Abkhazia": ["Abkhazia, Georgia"],
"Akrotiri and Dhekelia": ["Akrotiri, Cyprus", "Dhekelia, Cyprus"], "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"], "Byelorussian Soviet Socialist Republic": ["Belarus"],
"Canary Islands": ["Ferro, Canary Islands", "Isla Alegranza, Canary Islands"],
"Canton and Enderbury Islands": ["Canton Island", "Enderbury Island"], "Canton and Enderbury Islands": ["Canton Island", "Enderbury Island"],
"Ceuta and Melilla": ["Ceuta", "Melilla"], "Ceuta and Melilla": ["Ceuta", "Melilla"],
"Curaçao": ["Banda Abou, Curaçao"],
"Czechoslovakia": ["Czech Republic", "Slovakia"], "Czechoslovakia": ["Czech Republic", "Slovakia"],
"East Germany": [ "East Germany": ["Mecklenburg Vorpommern", "Saxony", "Thuringia"],
"Mecklenburg Vorpommern", "Saxony", "Thuringia"
],
"Dahomey": ["Benin"], "Dahomey": ["Benin"],
"European Union": ["Europe"], "European Union": ["Cyprus", "Finland", "Greece", "Portugal"],
"French Afar and Issas": ["Djibouti"], "French Afar and Issas": ["Djibouti"],
// see http://en.wikipedia.org/wiki/French_Southern_and_Antarctic_Lands // see http://en.wikipedia.org/wiki/French_Southern_and_Antarctic_Lands
// and http://en.wikipedia.org/wiki/Scattered_Islands_in_the_Indian_Ocean // 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 and Antarctic Territories": ["Adélie Land", "Bassas da India", "Glorioso Islands"],
"French Southern Territories": ["Bassas da India", "Glorioso Islands", "Île Kerguelen"], "French Southern Territories": ["Amsterdam Island", "Bassas da India", "Glorioso Islands", "Kerguelen Island"],
"Georgia": ["Georgia, Asia"], "Georgia": ["Georgia, Asia"],
// see http://en.wikipedia.org/wiki/Gilbert_Islands // see http://en.wikipedia.org/wiki/Gilbert_Islands
"Gilbert and Ellice Islands": ["Arorae, Kiribati", "Butaritari, Kiribati", "Makin, Kiribati", "Tuvalu"], "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"], "Jammu and Kashmir": ["Jammu and Kashmir, India"],
"Johnston Island": ["Johnston Atoll"], "Johnston Island": ["Johnston Atoll"],
"Korea": ["North Korea", "South Korea"], "Korea": ["North Korea", "South Korea"],
@ -409,7 +408,7 @@
"Neutral Zone": ["39944, Saudi Arabia", "76611, Saudi Arabia"], "Neutral Zone": ["39944, Saudi Arabia", "76611, Saudi Arabia"],
"New Hebrides": ["Vanuatu"], "New Hebrides": ["Vanuatu"],
"North Vietnam": ["Ha Giang Province, Vietnam", "Lai Chau Province, Vietnam", "Thua Thien-Hue Province, Vietnam"], "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"], "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"],
@ -419,21 +418,21 @@
"San Marino": ["San Marino, Europe"], // in case results are us-biased "San Marino": ["San Marino, Europe"], // in case results are us-biased
"Serbia and Montenegro": ["Montenegro", "Serbia"], "Serbia and Montenegro": ["Montenegro", "Serbia"],
"Siam": ["Thailand"], "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"], "South Ossetia": ["Shida Kartli"],
// see http://en.wikipedia.org/wiki/Sudan#States_and_regions // see http://en.wikipedia.org/wiki/Sudan#States_and_regions
// "South Sudan": [ // "South Sudan": [
// "Central Equatoria, Sudan", "Eastern Equatoria, Sudan", "Jonglei, Sudan", "Lakes, Sudan", "Northern Bahr el Ghazal, 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" // "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"], "South Yemen": ["Al-Mahrah, Yemen", "Lahij, Yemen"],
"Soviet Union": [ "Soviet Union": [
"Armenia", "Azerbaijan", "Belarus", "Estonia", "Georgia, Europe", "Armenia", "Azerbaijan", "Belarus", "Estonia", "Georgia, Europe",
"Latvia", "Lithuania", "Kazakhstan", "Kyrgyzstan", "Moldova", "Latvia", "Lithuania", "Kazakhstan", "Kyrgyzstan", "Moldova",
"Russia", "Tajikistan", "Turkmenistan", "Ukraine", "Uzbekistan" "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": [ "United States Minor Outlying Islands": [
"Baker Island, UM", "Howland Island", "Jarvis Island", "Johnston Atoll", "Kingman Reef", "Baker Island, UM", "Howland Island", "Jarvis Island", "Johnston Atoll", "Kingman Reef",
"Midway Islands", "Palmyra Atoll", "Wake Island" "Midway Islands", "Palmyra Atoll", "Wake Island"
@ -442,9 +441,7 @@
"United States Miscellaneous Pacific Islands": [ "United States Miscellaneous Pacific Islands": [
"Baker Island, UM", "Howland Island", "Jarvis Island", "Kingman Reef", "Palmyra Atoll" "Baker Island, UM", "Howland Island", "Jarvis Island", "Kingman Reef", "Palmyra Atoll"
], ],
"UK": ["England", "Northern Ireland", "Scotland", "Wales, United Kingdom"],
"Upper Volta": ["Burkina Faso"], "Upper Volta": ["Burkina Faso"],
"Wake Island": ["Wake Atoll"],
"Wales": ["Wales, United Kingdom"], "Wales": ["Wales, United Kingdom"],
"West Germany": ["Schleswig Holstein", "Northrhine Westphalia", "Bavaria, Germany"], "West Germany": ["Schleswig Holstein", "Northrhine Westphalia", "Bavaria, Germany"],
"Yugoslavia": [ "Yugoslavia": [

View file

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

View file

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