update Geo module

This commit is contained in:
rolux 2012-04-03 00:20:18 +02:00
parent 9c39e0e2e6
commit 0bf4d5a0f5
5 changed files with 582 additions and 62 deletions

View file

@ -5,3 +5,383 @@
<p>foo: <code>// this is some code</code></p> <p>foo: <code>// this is some code</code></p>
<blockquote>blockquote</blockquote> <blockquote>blockquote</blockquote>
<p><pre class="code">
/*
*/
'use strict';
/*
We have to load the Geo module to get Ox.COUNTRIES
*/
Ox.load({UI: {}, Geo: {}}, function() {
var countries = Ox.COUNTRIES.filter(function(country) {
/*
We filter out some types of countries that we're not interested in.
*/
return !country.disputed
&& !country.dissolved
&& !country.exception
&& country.code.length == 2
}).map(function(country) {
/*
For independent countries, the dependency property is undefined. We
want an empty array though, so that the type of this column gets
correctly detected as array.
*/
country.dependency = country.dependency || [];
/*
When sorting the list by region, we want the regions to be grouped
by continent. To get this sort order, we set the value for region to
'Continent, Region'. Later, a format function for the region column
will remove the continent part again.
*/
country.region = country.continent + ', ' + country.region;
return country;
}),
api = Ox.api(countries, {sort: ['+name'], unique: 'code'}),
$list = Ox.TextList({
columns: [
{
/*
The format function of a column has a second argument
which contains the values of all columns. This allows us
to format a value dependent on other values. In this
case, we want to display a flag, and while our items
don't have a flag property, the Geo module allows us to
derive it from the name property. The flag image needs a
tooltip (which is why we can't use an $('<img>') here),
and gets some CSS adjustments.
*/
format: function(value, data) {
return Ox.Element({
element: '<img>',
tooltip:
'<div style="margin-top: 2px"><img src="'
+ Ox.getFlagByGeoname(data.name, 64)
+ '"/></div>'
})
.attr({
src: Ox.getFlagByGeoname(data.name, 16)
})
.css({
width: '14px',
height: '14px',
marginLeft: '-3px'
})
},
/*
As the actual key for the column, we use the country
code, not the country name, since we still want to
display the name in its own column.
*/
id: 'flagURL',
operator: '+',
removable: false,
/*
We want the column title to be a flag symbol, so we
specify this as the titleImage. We can pick anything
from the collection of symbols that comes with Ox.UI.
The column still needs a textual title that will be
displayed in the menu that allows to show or hide
specific columns.
*/
title: 'Flag',
titleImage: 'flag',
/*
The country code is the unique key of our country table.
In consequence, whenever the list fires a select event,
it will reference this value as the item's id.
*/
unique: true,
visible: true,
width: 16
},
{
id: 'code',
operator: '+',
title: 'Code',
unique: true,
visible: true,
width: 64
},
{
id: 'name',
/*
The operator indicates that we want the default sort
order of this column to be ascending.
*/
operator: '+',
/*
As it wouldn't make much sense to display the list
without the name column, we make it non-removable.
*/
removable: false,
title: 'Name',
visible: true,
width: 256
},
{
id: 'continent',
operator: '+',
title: 'Continent',
visible: true,
width: 96
},
{
/*
To tweak the sort order for this column, we had changed
the value for region to 'Continent, Region'. The format
function now reverts that change.
*/
format: function(value) {
return value.split(', ')[1];
},
id: 'region',
operator: '+',
title: 'Region',
visible: true,
width: 160
},
{
/*
As the value is a number, it should be right-aligned.
*/
align: 'right',
/*
To get from square meters to something human-readable,
we use one of the built-in format functions.
*/
format: function(value) {
return Ox.formatArea(value);
},
id: 'area',
operator: '-',
title: 'Area',
visible: true,
width: 112
},
{
format: function(value) {
return Ox.formatDegrees(value, 'lat');
},
align: 'right',
id: 'lat',
operator: '-',
title: 'Latitude',
visible: true,
width: 80
},
{
format: function(value) {
return Ox.formatDegrees(value, 'lng');
},
align: 'right',
id: 'lng',
operator: '+',
title: 'Longitude',
visible: true,
width: 80
},
/*
For the next four columns, which seem less important, we
omit the 'visible' option, which defaults to false. They can
still be made visible, they're just not visible by default.
*/
{
align: 'right',
format: function(value) {
return Ox.formatDegrees(value, 'lat');
},
id: 'south',
operator: '-',
title: 'South',
width: 80
},
{
align: 'right',
format: function(value) {
return Ox.formatDegrees(value, 'lat');
},
id: 'north',
operator: '-',
title: 'North',
width: 80
},
{
align: 'right',
format: function(value) {
return Ox.formatDegrees(value, 'lng');
},
id: 'west',
operator: '-',
title: 'West',
width: 80
},
{
align: 'right',
format: function(value) {
return Ox.formatDegrees(value, 'lng');
},
id: 'east',
operator: '-',
title: 'East',
width: 80
},
{
/*
The dependency property is an array of country names,
for each of which we want to display a flag. So we use a
similar constuction as above, and wrap the images in a
$('<div>') element.
*/
format: function(value) {
var ret = '';
if (value) {
var ret = $('<div>').css({marginLeft: '-4px'});
value.forEach(function(country) {
Ox.Element({
element: '<img>',
tooltip: country
})
.attr({
src: Ox.getFlagByGeoname(country, 16)
})
.css({
width: '14px',
height: '14px',
margin: '1px'
})
.appendTo(ret);
});
}
return ret;
},
id: 'dependency',
operator: '+',
title: 'Dependency of',
visible: true,
width: 112
}
],
/*
This allows the user to move the columns around
*/
columnsMovable: true,
/*
This enables the UI to show or hide specific columns
*/
columnsRemovable: true,
/*
This makes sure the column titles get displayed
*/
columnsVisible: true,
items: api,
/*
Pagination is useful when a list is so big that only parts of it
can be requested or displayed. Since this is not the case here,
we set the page length to a sufficiently large number.
*/
pageLength: Ox.COUNTRIES.length,
scrollbarVisible: true,
/*
We have to specify the default sort order.
*/
sort: [{key: 'name', operator: '+'}]
})
.bindEvent({
/*
The init event of a list fires when the items function has
returned the total number of items. If we're dealing with a
remote API, a complex query, a huge dataset or a range request
for paginated results according to a non-trivial sort order,
this may happen quite a bit before any items are returned. Here,
we simply display the number of items in the status bar.
*/
init: function(data) {
$status.html(
(data.items || 'No') + ' countr'
+ (data.items == 1 ? 'y' : 'ies')
);
}
}),
/*
We want the user to be able to pick if dependent countries are included
in the list or not. So we add a checkbox, and bind the find function to
its change event.
*/
$include = Ox.Checkbox({
title: 'Include Dependencies',
value: true
})
.css({float: 'left', margin: '4px'})
.bindEvent({
change: find
}),
/*
We want a search field with find-as-you-type, so we use an input element
and set its changeOnKeypress option to true.
*/
$find = Ox.Input({
changeOnKeypress: true,
placeholder: 'Find',
width: 192
})
.css({float: 'right', margin: '4px'})
.bindEvent({
change: find
}),
/*
...
*/
$toolbar = Ox.Bar({size: 24}).append($include).append($find),
$status = $('<div>').css({
marginTop: '2px',
fontSize: '9px',
textAlign: 'center'
}),
$statusbar = Ox.Bar({size: 16}).append($status),
$panel = Ox.SplitPanel({
elements: [
{element: $toolbar, size: 24},
{element: $list},
{element: $statusbar, size: 16}
],
orientation: 'vertical'
})
.appendTo(Ox.$body);
function find() {
/*
The find function is bound to the change events of the $include checkbox
and the $find input field. In both cases, the value will be passed, but
since we need both values, we disregard it and query both elements for
their value. If the $include box is not checked, we add a second
condition that matches only independent countries.
*/
var conditions = [
{key: 'name', operator: '=', value: $find.options('value')},
];
!$include.options('value') && conditions.push(
{key: 'dependency', operator: '=', value: void 0}
);
/*
...
*/
api({
keys: [],
query: {conditions: conditions, operator: '&'}
}, function(result) {
$list.options({
items: Ox.api(
result.data.items, {sort: '+name', unique: 'code'}
)
});
});
}
});
</pre></p>

View file

@ -4,8 +4,7 @@
"code": "AC", "code": "AC",
"continent": "Africa", "continent": "Africa",
"dependency": [ "dependency": [
"Saint Helena", "Saint Helena, Ascension and Tristan da Cunha"
"Ascension and Tristan da Cunha"
], ],
"east": -14.2892647, "east": -14.2892647,
"exception": true, "exception": true,
@ -206,6 +205,13 @@
"created": "merged", "created": "merged",
"date": "1971-12-01" "date": "1971-12-01"
}, },
"dissolved": {
"country": [
"United Arab Emirates"
],
"date": "1972-02-11",
"dissolved": "joined"
},
"east": 56.297054, "east": 56.297054,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/6/6d/Flag_of_Sharjah.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/6/6d/Flag_of_Sharjah.svg",
"independence": { "independence": {
@ -448,6 +454,12 @@
], ],
"east": 24.0844444, "east": 24.0844444,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/9d/Flag_of_Angola.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/9d/Flag_of_Angola.svg",
"independence": {
"country": [
"Portugal"
],
"date": "1975-11-11"
},
"lat": -11.202692, "lat": -11.202692,
"lng": 17.873887, "lng": 17.873887,
"name": "Angola", "name": "Angola",
@ -460,9 +472,23 @@
"area": 18910547686.30963, "area": 18910547686.30963,
"code": "AO-CAB", "code": "AO-CAB",
"continent": "Africa", "continent": "Africa",
"created": {
"country": [
"Portugal"
],
"created": "split",
"date": "1975-08-01"
},
"disputed": [ "disputed": [
"Angola" "Angola"
], ],
"dissolved": {
"country": [
"Angola"
],
"date": "1975-11-11",
"dissolved": "joined"
},
"east": 13.109678, "east": 13.109678,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/2/22/Flag_of_Cabinda.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/2/22/Flag_of_Cabinda.svg",
"lat": -5.0248749, "lat": -5.0248749,
@ -578,12 +604,6 @@
], ],
"east": -173.0645, "east": -173.0645,
"flagURL": "http://upload.wikimedia.org/wikipedia/en/b/b9/Flag_of_Australia.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/en/b/b9/Flag_of_Australia.svg",
"independence": {
"country": [
"Papua New Guinea"
],
"date": "1975-09-16"
},
"languages": [ "languages": [
"Aboriginal", "Aboriginal",
"Australian", "Australian",
@ -653,6 +673,13 @@
"area": 558581877.6893722, "area": 558581877.6893722,
"code": "AW", "code": "AW",
"continent": "South America", "continent": "South America",
"created": {
"country": [
"Netherlands Antilles"
],
"created": "split",
"date": "1986-01-01"
},
"dependency": [ "dependency": [
"Netherlands" "Netherlands"
], ],
@ -854,6 +881,12 @@
"continent": "Asia", "continent": "Asia",
"east": 50.8509064, "east": 50.8509064,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/2/2c/Flag_of_Bahrain.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/2/2c/Flag_of_Bahrain.svg",
"independence": {
"country": [
"United Kingdom"
],
"date": "1971-12-16"
},
"lat": 25.930414, "lat": 25.930414,
"lng": 50.637772, "lng": 50.637772,
"name": "Bahrain", "name": "Bahrain",
@ -939,6 +972,12 @@
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/9c/Flag_of_Brunei.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/9c/Flag_of_Brunei.svg",
"googleName": "Brunei Darussalam", "googleName": "Brunei Darussalam",
"imdbName": "Brunei Darussalam", "imdbName": "Brunei Darussalam",
"independence": {
"country": [
"United Kingdom"
],
"date": "1984-01-01"
},
"lat": 4.535277, "lat": 4.535277,
"lng": 114.727669, "lng": 114.727669,
"name": "Brunei", "name": "Brunei",
@ -1031,6 +1070,12 @@
"east": -72.6196289, "east": -72.6196289,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/93/Flag_of_the_Bahamas.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/93/Flag_of_the_Bahamas.svg",
"googleName": "The Bahamas", "googleName": "The Bahamas",
"independence": {
"country": [
"United Kingdom"
],
"date": "1973-07-10"
},
"lat": 25.03428, "lat": 25.03428,
"lng": -77.39628, "lng": -77.39628,
"name": "Bahamas", "name": "Bahamas",
@ -1558,6 +1603,12 @@
"continent": "Africa", "continent": "Africa",
"east": -22.5933838, "east": -22.5933838,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/3/38/Flag_of_Cape_Verde.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/3/38/Flag_of_Cape_Verde.svg",
"independence": {
"country": [
"Portugal"
],
"date": "1975-07-05"
},
"languages": [ "languages": [
"Kabuverdianu", "Kabuverdianu",
"Kriolu" "Kriolu"
@ -1574,6 +1625,13 @@
"area": 5069459315.473289, "area": 5069459315.473289,
"code": "CW", "code": "CW",
"continent": "South America", "continent": "South America",
"created": {
"country": [
"Netherlands Antilles"
],
"created": "merged",
"date": "2010-10-10"
},
"dependency": [ "dependency": [
"Netherlands" "Netherlands"
], ],
@ -1804,6 +1862,12 @@
"continent": "South America", "continent": "South America",
"east": -61.2295532, "east": -61.2295532,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/c/c4/Flag_of_Dominica.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/c/c4/Flag_of_Dominica.svg",
"independence": {
"country": [
"United Kingdom"
],
"date": "1978-11-03"
},
"lat": 15.414999, "lat": 15.414999,
"lng": -61.370976, "lng": -61.370976,
"name": "Dominica", "name": "Dominica",
@ -2084,6 +2148,12 @@
"continent": "Oceania", "continent": "Oceania",
"east": -177.8686523, "east": -177.8686523,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/b/ba/Flag_of_Fiji.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/b/ba/Flag_of_Fiji.svg",
"independence": {
"country": [
"United Kingdom"
],
"date": "1970-10-10"
},
"lat": -17.713371, "lat": -17.713371,
"lng": 178.065032, "lng": 178.065032,
"name": "Fiji", "name": "Fiji",
@ -2205,17 +2275,11 @@
"Saint Martin", "Saint Martin",
"Saint Pierre and Miquelon", "Saint Pierre and Miquelon",
"Wallis and Futuna", "Wallis and Futuna",
"Antarctica", "New Hebrides",
"New Hebrides" "Antarctica"
], ],
"east": 9.6625, "east": 9.6625,
"flagURL": "http://upload.wikimedia.org/wikipedia/en/c/c3/Flag_of_France.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/en/c/c3/Flag_of_France.svg",
"independence": {
"country": [
"Comoros"
],
"date": "1975-07-06"
},
"languages": [ "languages": [
"French", "French",
"Breton", "Breton",
@ -2233,6 +2297,13 @@
"area": 568730876782.7081, "area": 568730876782.7081,
"code": "FR-AQ", "code": "FR-AQ",
"continent": "Antarctica", "continent": "Antarctica",
"created": {
"country": [
"French Southern and Antarctic Territories"
],
"created": "merged",
"date": "1979"
},
"dependency": [ "dependency": [
"France" "France"
], ],
@ -2287,9 +2358,8 @@
"code": "GB", "code": "GB",
"continent": "Europe", "continent": "Europe",
"dependencies": [ "dependencies": [
"Antarctica",
"New Hebrides",
"Canton and Enderbury Islands", "Canton and Enderbury Islands",
"New Hebrides",
"Akrotiri and Dhekelia", "Akrotiri and Dhekelia",
"Anguilla", "Anguilla",
"Bermuda", "Bermuda",
@ -2317,7 +2387,8 @@
"Southern Rhodesia", "Southern Rhodesia",
"Trucial States", "Trucial States",
"Turks and Caicos Islands", "Turks and Caicos Islands",
"Wales" "Wales",
"Antarctica"
], ],
"disputes": [ "disputes": [
"Sealand" "Sealand"
@ -2325,12 +2396,6 @@
"east": 1.768926, "east": 1.768926,
"flagURL": "http://upload.wikimedia.org/wikipedia/en/a/ae/Flag_of_the_United_Kingdom.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/en/a/ae/Flag_of_the_United_Kingdom.svg",
"googleName": "UK", "googleName": "UK",
"independence": {
"country": [
"Brunei"
],
"date": "1984-01-01"
},
"languages": [ "languages": [
"Cornish", "Cornish",
"English", "English",
@ -2538,6 +2603,12 @@
"continent": "South America", "continent": "South America",
"east": -61.3620758, "east": -61.3620758,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/b/bc/Flag_of_Grenada.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/b/bc/Flag_of_Grenada.svg",
"independence": {
"country": [
"United Kingdom"
],
"date": "1974-02-07"
},
"lat": 12.262776, "lat": 12.262776,
"lng": -61.604171, "lng": -61.604171,
"name": "Grenada", "name": "Grenada",
@ -2977,6 +3048,12 @@
"continent": "Africa", "continent": "Africa",
"east": -13.6430556, "east": -13.6430556,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/0/01/Flag_of_Guinea-Bissau.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/0/01/Flag_of_Guinea-Bissau.svg",
"independence": {
"country": [
"Portugal"
],
"date": "1974-09-10"
},
"lat": 11.803749, "lat": 11.803749,
"lng": -15.180413, "lng": -15.180413,
"name": "Guinea-Bissau", "name": "Guinea-Bissau",
@ -3605,6 +3682,12 @@
], ],
"east": 44.5646667, "east": 44.5646667,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/94/Flag_of_the_Comoros.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/94/Flag_of_the_Comoros.svg",
"independence": {
"country": [
"France"
],
"date": "1975-07-06"
},
"lat": -11.875001, "lat": -11.875001,
"lng": 43.872219, "lng": 43.872219,
"name": "Comoros", "name": "Comoros",
@ -3644,6 +3727,13 @@
"disputed": [ "disputed": [
"Comoros" "Comoros"
], ],
"dissolved": {
"country": [
"Comoros"
],
"date": "2002-03-10",
"dissolved": "joined"
},
"east": 43.8763046, "east": 43.8763046,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/3/32/Flag_of_Moh%C3%A9li.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/3/32/Flag_of_Moh%C3%A9li.svg",
"lat": -12.3377376, "lat": -12.3377376,
@ -3826,6 +3916,12 @@
"continent": "South America", "continent": "South America",
"east": -60.8597946, "east": -60.8597946,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/9f/Flag_of_Saint_Lucia.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/9f/Flag_of_Saint_Lucia.svg",
"independence": {
"country": [
"United Kingdom"
],
"date": "1979-02-22"
},
"lat": 13.909444, "lat": 13.909444,
"lng": -60.978893, "lng": -60.978893,
"name": "Saint Lucia", "name": "Saint Lucia",
@ -4467,6 +4563,12 @@
"continent": "Africa", "continent": "Africa",
"east": 41.3965, "east": 41.3965,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/d/d0/Flag_of_Mozambique.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/d/d0/Flag_of_Mozambique.svg",
"independence": {
"country": [
"Portugal"
],
"date": "1975-06-25"
},
"lat": -18.665695, "lat": -18.665695,
"lng": 35.529562, "lng": 35.529562,
"name": "Mozambique", "name": "Mozambique",
@ -4723,12 +4825,6 @@
], ],
"east": 7.2271405, "east": 7.2271405,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/2/20/Flag_of_the_Netherlands.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/2/20/Flag_of_the_Netherlands.svg",
"independence": {
"country": [
"Suriname"
],
"date": "1975-11-25"
},
"languages": [ "languages": [
"Dutch" "Dutch"
], ],
@ -5010,6 +5106,12 @@
], ],
"east": 159.9609, "east": 159.9609,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/e/e3/Flag_of_Papua_New_Guinea.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/e/e3/Flag_of_Papua_New_Guinea.svg",
"independence": {
"country": [
"Australia"
],
"date": "1975-09-16"
},
"languages": [ "languages": [
"Korowai" "Korowai"
], ],
@ -5213,12 +5315,6 @@
"continent": "Europe", "continent": "Europe",
"east": -6.1902091, "east": -6.1902091,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/5/5c/Flag_of_Portugal.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/5/5c/Flag_of_Portugal.svg",
"independence": {
"country": [
"Angola"
],
"date": "1975-11-11"
},
"languages": [ "languages": [
"Portuguese" "Portuguese"
], ],
@ -5328,6 +5424,12 @@
"continent": "Asia", "continent": "Asia",
"east": 51.6769, "east": 51.6769,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/6/65/Flag_of_Qatar.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/6/65/Flag_of_Qatar.svg",
"independence": {
"country": [
"United Kingdom"
],
"date": "1971-09-03"
},
"lat": 25.354826, "lat": 25.354826,
"lng": 51.183884, "lng": 51.183884,
"name": "Qatar", "name": "Qatar",
@ -5583,6 +5685,12 @@
"continent": "Oceania", "continent": "Oceania",
"east": 168.0249023, "east": 168.0249023,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/7/74/Flag_of_the_Solomon_Islands.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/7/74/Flag_of_the_Solomon_Islands.svg",
"independence": {
"country": [
"United Kingdom"
],
"date": "1978-07-07"
},
"lat": -9.64571, "lat": -9.64571,
"lng": 160.156194, "lng": 160.156194,
"name": "Solomon Islands", "name": "Solomon Islands",
@ -5597,6 +5705,12 @@
"continent": "Africa", "continent": "Africa",
"east": 56.3928223, "east": 56.3928223,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/f/fc/Flag_of_Seychelles.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/f/fc/Flag_of_Seychelles.svg",
"independence": {
"country": [
"United Kingdom"
],
"date": "1976-06-29"
},
"lat": -4.679574, "lat": -4.679574,
"lng": 55.491977, "lng": 55.491977,
"name": "Seychelles", "name": "Seychelles",
@ -5654,6 +5768,10 @@
"area": 2899291545265.023, "area": 2899291545265.023,
"code": "SH", "code": "SH",
"continent": "Africa", "continent": "Africa",
"dependencies": [
"Ascension",
"Tristan da Cunha"
],
"dependency": [ "dependency": [
"United Kingdom" "United Kingdom"
], ],
@ -5866,6 +5984,12 @@
"continent": "South America", "continent": "South America",
"east": -53.9429, "east": -53.9429,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/6/60/Flag_of_Suriname.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/6/60/Flag_of_Suriname.svg",
"independence": {
"country": [
"Netherlands"
],
"date": "1975-11-25"
},
"lat": 3.919305, "lat": 3.919305,
"lng": -56.027783, "lng": -56.027783,
"name": "Suriname", "name": "Suriname",
@ -5902,6 +6026,12 @@
"east": 7.658844, "east": 7.658844,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/4/4f/Flag_of_Sao_Tome_and_Principe.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/4/4f/Flag_of_Sao_Tome_and_Principe.svg",
"imdbName": "Sao Tome and Principe", "imdbName": "Sao Tome and Principe",
"independence": {
"country": [
"Portugal"
],
"date": "1975-07-12"
},
"lat": 0.18636, "lat": 0.18636,
"lng": 6.613081, "lng": 6.613081,
"name": "S\u00e3o Tom\u00e9 and Pr\u00edncipe", "name": "S\u00e3o Tom\u00e9 and Pr\u00edncipe",
@ -6009,8 +6139,7 @@
"code": "TA", "code": "TA",
"continent": "Africa", "continent": "Africa",
"dependency": [ "dependency": [
"Saint Helena", "Saint Helena, Ascension and Tristan da Cunha"
"Ascension and Tristan da Cunha"
], ],
"east": -12.2169685, "east": -12.2169685,
"exception": true, "exception": true,
@ -6162,6 +6291,13 @@
"area": 61551190637.092255, "area": 61551190637.092255,
"code": "TL", "code": "TL",
"continent": "Asia", "continent": "Asia",
"created": {
"country": [
"East Timor"
],
"created": "renamed",
"date": "2002-05-20"
},
"east": 127.4249, "east": 127.4249,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/2/26/Flag_of_East_Timor.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/2/26/Flag_of_East_Timor.svg",
"lat": -8.874217, "lat": -8.874217,
@ -6216,6 +6352,12 @@
"continent": "Oceania", "continent": "Oceania",
"east": -173.2543945, "east": -173.2543945,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/9a/Flag_of_Tonga.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/9/9a/Flag_of_Tonga.svg",
"independence": {
"country": [
"United Kingdom"
],
"date": "1970-06-04"
},
"languages": [ "languages": [
"Tonga (Tonga Islands)" "Tonga (Tonga Islands)"
], ],
@ -6236,7 +6378,7 @@
], ],
"dissolved": { "dissolved": {
"country": [ "country": [
"Timor Leste" "Timor-Leste"
], ],
"date": "2002-05-20", "date": "2002-05-20",
"dissolved": "renamed" "dissolved": "renamed"
@ -6439,9 +6581,8 @@
"code": "UK", "code": "UK",
"continent": "Europe", "continent": "Europe",
"dependencies": [ "dependencies": [
"Antarctica",
"New Hebrides",
"Canton and Enderbury Islands", "Canton and Enderbury Islands",
"New Hebrides",
"Akrotiri and Dhekelia", "Akrotiri and Dhekelia",
"Anguilla", "Anguilla",
"Bermuda", "Bermuda",
@ -6469,7 +6610,8 @@
"Southern Rhodesia", "Southern Rhodesia",
"Trucial States", "Trucial States",
"Turks and Caicos Islands", "Turks and Caicos Islands",
"Wales" "Wales",
"Antarctica"
], ],
"disputes": [ "disputes": [
"Sealand" "Sealand"
@ -6478,12 +6620,6 @@
"exception": true, "exception": true,
"flagURL": "http://upload.wikimedia.org/wikipedia/en/a/ae/Flag_of_the_United_Kingdom.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/en/a/ae/Flag_of_the_United_Kingdom.svg",
"googleName": "UK", "googleName": "UK",
"independence": {
"country": [
"Brunei"
],
"date": "1984-01-01"
},
"languages": [ "languages": [
"Cornish", "Cornish",
"English", "English",
@ -6529,6 +6665,7 @@
"code": "US", "code": "US",
"continent": "North America", "continent": "North America",
"dependencies": [ "dependencies": [
"Canton and Enderbury Islands",
"American Samoa", "American Samoa",
"Guam", "Guam",
"Northern Mariana Islands", "Northern Mariana Islands",
@ -6540,8 +6677,7 @@
"United States Minor Outlying Islands", "United States Minor Outlying Islands",
"United States Miscellaneous Pacific Islands", "United States Miscellaneous Pacific Islands",
"United States Virgin Islands", "United States Virgin Islands",
"Wake Island", "Wake Island"
"Canton and Enderbury Islands"
], ],
"east": -66.885417, "east": -66.885417,
"flagURL": "http://upload.wikimedia.org/wikipedia/commons/e/e2/Flag_of_the_United_States_%28Pantone%29.svg", "flagURL": "http://upload.wikimedia.org/wikipedia/commons/e/e2/Flag_of_the_United_States_%28Pantone%29.svg",

View file

@ -250,7 +250,7 @@
}, },
"dependencies": { "dependencies": {
"Argentina": ["Argentine Antarctica"], "Argentina": ["Argentine Antarctica"],
"Argentina, Australia, Chile, France, New Zealand, Norway, United Kingdom": ["Antarctica"], "Argentina; Australia; Chile; France; New Zealand; Norway; United Kingdom": ["Antarctica"],
"Australia": [ "Australia": [
"Ashmore and Cartier Islands", "Australian Antarctic Territory", "Christmas Island", "Cocos Islands", "Coral Sea Islands", "Ashmore and Cartier Islands", "Australian Antarctic Territory", "Christmas Island", "Cocos Islands", "Coral Sea Islands",
"Heard Island and McDonald Islands", "Norfolk Island" "Heard Island and McDonald Islands", "Norfolk Island"
@ -266,7 +266,7 @@
"New Caledonia", "Réunion", "Saint Barthélemy", "Saint Martin", "Saint Pierre and Miquelon", "New Caledonia", "Réunion", "Saint Barthélemy", "Saint Martin", "Saint Pierre and Miquelon",
"Wallis and Futuna" "Wallis and Futuna"
], ],
"France, United Kingdom": ["New Hebrides"], "France; United Kingdom": ["New Hebrides"],
"Guernsey": ["Alderney", "Herm", "Sark"], "Guernsey": ["Alderney", "Herm", "Sark"],
"India": ["Jammu and Kashmir"], "India": ["Jammu and Kashmir"],
"Netherlands": [ "Netherlands": [
@ -287,7 +287,7 @@
"Saint Christopher-Nevis-Anguilla", "Saint Helena, Ascension and Tristan da Cunha", "Scotland", "South Georgia and the South Sandwich Islands", "Southern Rhodesia", "Saint Christopher-Nevis-Anguilla", "Saint Helena, Ascension and Tristan da Cunha", "Scotland", "South Georgia and the South Sandwich Islands", "Southern Rhodesia",
"Trucial States", "Turks and Caicos Islands", "Wales" "Trucial States", "Turks and Caicos Islands", "Wales"
], ],
"United Kingdom, United States": ["Canton and Enderbury Islands"], "United Kingdom; United States": ["Canton and Enderbury Islands"],
"United States": [ "United States": [
"American Samoa", "Guam", "Northern Mariana Islands", "Johnston Island", "Midway Islands", "American Samoa", "Guam", "Northern Mariana Islands", "Johnston Island", "Midway Islands",
"Pacific Islands", "Panama Canal Zone", "Puerto Rico", "United States Minor Outlying Islands", "United States Miscellaneous Pacific Islands", "Pacific Islands", "Panama Canal Zone", "Puerto Rico", "United States Minor Outlying Islands", "United States Miscellaneous Pacific Islands",
@ -301,7 +301,7 @@
"Cyprus": ["Northern Cyprus"], "Cyprus": ["Northern Cyprus"],
"Georgia": ["Abkhazia", "South Ossetia"], "Georgia": ["Abkhazia", "South Ossetia"],
"Indonesia": ["East Timor"], "Indonesia": ["East Timor"],
"Iraq, Saudi Arabia": ["Neutral Zone"], "Iraq; Saudi Arabia": ["Neutral Zone"],
"Moldova": ["Transnistria"], "Moldova": ["Transnistria"],
"Morocco": ["Sahrawi"], "Morocco": ["Sahrawi"],
"New Hebrides": ["Tafea", "Tanna", "Vemerana"], "New Hebrides": ["Tafea", "Tanna", "Vemerana"],

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import codecs
import json import json
import os import os
import ox import ox
@ -96,7 +97,6 @@ def get_countries():
'country': data['dependency'], 'country': data['dependency'],
'date': country['created']['date'] 'date': country['created']['date']
} }
sys.exit()
# Flags # Flags
countries = sorted(countries, key=sort) countries = sorted(countries, key=sort)
flags = get_flags(countries) flags = get_flags(countries)
@ -126,14 +126,14 @@ def get_country_data(country):
country['created'] = DATA['created'][name] country['created'] = DATA['created'][name]
# dependencies # dependencies
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['dependencies'] = 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
for c, d in DATA['disputes'].iteritems(): for c, d in DATA['disputes'].iteritems():
c = c.split(', ') c = c.split('; ')
if name in c: if name in c:
country['disputes'] = d if not 'disputes' in country else country['disputes'] + d country['disputes'] = d if not 'disputes' in country else country['disputes'] + d
elif name in d: elif name in d:
@ -261,7 +261,7 @@ def parse_txt():
'dissolved': {}, 'dissolved': {},
'independence': {} 'independence': {}
} }
f = open('../txt/countries.txt') f = codecs.open('../txt/countries.txt', 'r', 'utf-8')
lines = map(lambda x: x.strip(), f.readlines()) lines = map(lambda x: x.strip(), f.readlines())
f.close() f.close()
for line in filter(lambda x: x[0] != '#', lines): for line in filter(lambda x: x[0] != '#', lines):

View file

@ -1,3 +1,4 @@
# FIXME: character encoding doesn't work!
# see http://en.wikipedia.org/wiki/List_of_sovereign_states_by_date_of_formation # see http://en.wikipedia.org/wiki/List_of_sovereign_states_by_date_of_formation
# a < b / c a splits into b and c # a < b / c a splits into b and c
# a / b > c a and b join as c # a / b > c a and b join as c
@ -16,7 +17,7 @@
1971-12-02 Abu Dhabi / Ajman / Dubai / Fujairah / Sharjah / Umm al-Quwain > United Arab Emirates 1971-12-02 Abu Dhabi / Ajman / Dubai / Fujairah / Sharjah / Umm al-Quwain > United Arab Emirates
1971-12-16 United Kingdom * Bahrain 1971-12-16 United Kingdom * Bahrain
1971-12-16 Pakistan - Bangladesh 1971-12-16 Pakistan - Bangladesh
1972-02-11 Ras al Khaimah + United Arab Emirates 1972-02-11 Ras al-Khaimah + United Arab Emirates
1972-05-22 Ceylon = Sri Lanka 1972-05-22 Ceylon = Sri Lanka
1973-06-01 British Honduras = Belize 1973-06-01 British Honduras = Belize
1973-07-10 United Kingdom * Bahamas 1973-07-10 United Kingdom * Bahamas
@ -30,7 +31,9 @@
1975-07-06 France * Comoros 1975-07-06 France * Comoros
1975-07-12 Portugal * São Tomé and Príncipe 1975-07-12 Portugal * São Tomé and Príncipe
1975-09-16 Australia * Papua New Guinea 1975-09-16 Australia * Papua New Guinea
1975-08-01 Portugal - Cabinda
1975-11-11 Portugal * Angola 1975-11-11 Portugal * Angola
1975-11-11 Cabinda + Angola
1975-11-25 Netherlands * Suriname 1975-11-25 Netherlands * Suriname
1975-11-30 Dahomey = Benin 1975-11-30 Dahomey = Benin
1976-01-01 Gilbert and Ellice Islands < Ellice Islands / Gilbert Islands 1976-01-01 Gilbert and Ellice Islands < Ellice Islands / Gilbert Islands
@ -56,6 +59,7 @@
1984-01-01 United Kingdom * Brunei 1984-01-01 United Kingdom * Brunei
1984-08-04 Upper Volta = Burkina Faso 1984-08-04 Upper Volta = Burkina Faso
1986 Johnston Island / Midway Islands / United States Miscellaneous Pacific Islands / Wake Island > United States Minor Outlying Islands 1986 Johnston Island / Midway Islands / United States Miscellaneous Pacific Islands / Wake Island > United States Minor Outlying Islands
1986-01-01 Netherlands Antilles - Aruba
1986-10-21 Pacific Islands - Marshall Islands 1986-10-21 Pacific Islands - Marshall Islands
1986-11-03 Pacific Islands - Micronesia 1986-11-03 Pacific Islands - Micronesia
1989-05-01 Kampuchea = Cambodia 1989-05-01 Kampuchea = Cambodia
@ -93,7 +97,7 @@
1998-12-24 Bougainville + Papua New Guinea 1998-12-24 Bougainville + Papua New Guinea
2000-02-06 Chechnia + Russia 2000-02-06 Chechnia + Russia
2002-03-10 Anjouan / Mohéli + Comoros 2002-03-10 Anjouan / Mohéli + Comoros
2002-05-20 East Timor = Timor Leste 2002-05-20 East Timor = Timor-Leste
2003-02-04 Yugoslavia = Serbia and Montenegro 2003-02-04 Yugoslavia = Serbia and Montenegro
2006-06-05 Serbia and Montenegro < Serbia / Montenegro 2006-06-05 Serbia and Montenegro < Serbia / Montenegro
2008-02-17 Serbia - Kosovo 2008-02-17 Serbia - Kosovo