oxjs/tools/areas/areas.js
2010-01-07 21:21:07 +01:00

32 lines
No EOL
1 KiB
JavaScript

/*
http://download.geonames.org/export/dump/admin1Codes.txt
*/
$(function() {
var $body = $("body")
.css({
fontFamily: "Consolas",
fontSize: "12px"
});
$.get("admin1Codes.txt", function(data) {
var lines = data.split("\n"),
countries = {};
lines.pop();
$.each(lines, function(i, v) {
var split = v.split("\t"),
code = split[0].split(".");
if (!countries[code[0]]) {
countries[code[0]] = [];
}
countries[code[0]].push([code[1], split[1]])
});
console.log(countries);
$body.html(
$.map(Ox.keys(countries), function(v) {
return v + ": [<br/>" + Ox.repeat("&nbsp;", 4) + "[" + $.map(countries[v], function(v) {
return '"' + v.join('", "') + '"';
}).join("],<br/>" + Ox.repeat("&nbsp;", 4) + "[") + "]";
}).join("<br/>],<br/>") + "<br/>]"
);
});
});