Roxen.git
/
server
/
etc
/
modules
/
Map.pmod
version
»
Context lines:
10
20
40
80
file
none
3
Roxen.git/server/etc/modules/Map.pmod:7:
mapping(string:string) aliases = ([ "usa":"United States of America", "us":"United States of America", "russia":"Russian Federation", "united kingdom":"England", "uk":"England", "vietnam":"Viet Nam" ]); mapping(string:string) domain_to_country =
-
([
/*
132
elements
*/
+
([
+
"ac":"ascension island",
+
"ad":"andorra",
+
"ae":"united arab emirates",
"af":"afghanistan",
-
+
"ag":"antigua and barbuda",
+
"ai":"anguilla",
"al":"albania",
-
"
dz
":"
algeria
",
+
"
am
":"
armenia
",
+
"an":"netherlands antilles",
"ao":"angola",
-
+
"aq":"antarctica",
"ar":"argentina",
-
"
am
":"
armenia",
-
"
aw":"aruba"
,
-
"au":"australia",
+
"
as
":"
american
samoa
",
"at":"austria",
-
+
"au":"australia",
+
"aw":"aruba",
+
"ax":"åland islands",
"az":"azerbaijan",
-
"
bs
":"
bahamas
",
+
"
ba
":"
bosnia and herzegovina
",
+
"bb":"barbados",
"bd":"bangladesh", "be":"belgium",
-
+
"bf":"burkina faso",
+
"bg":"bulgaria",
+
"bh":"bahrain",
+
"bi":"burundi",
"bj":"benin", "bm":"bermuda",
-
"
bt
":"
bhutan
",
+
"
bn
":"
brunei darussalam
",
"bo":"bolivia",
-
"ba":"bosnia and herzegovina",
-
"burma":"burma",
-
"bw":"botswana",
+
"br":"brazil",
-
"
bg
":"
bulgaria
",
-
"
bf
":"
burkina
faso
",
-
"
bi
":"
burundi
",
-
"
cm
":"
cameroon
",
+
"
bs
":"
bahamas
",
+
"
bt
":"
bhutan",
+
"
bu":"burma"
,
+
"
bv
":"
bouvet island
",
+
"
bw
":"
botswana
",
+
"by":"belarus",
+
"bz":"belize",
"ca":"canada",
-
+
"cc":"cocos (keeling) islands",
+
"cd":"congo, the democratic republic of the",
"cf":"central african republic",
-
"
td
":"
chad
",
+
"
cg
":"
congo
",
+
"ch":"switzerland",
+
"ci":"côte d'ivoire",
+
"ck":"cook islands",
"cl":"chile",
-
+
"cm":"cameroon",
"cn":"china",
-
"hk":"china",
+
"co":"colombia",
-
"cg":"congo",
+
"cr":"costa rica",
-
"
ci
":"
côte
d'ivoire",
-
"
hr":"croatia"
,
+
"
cs
":"
serbia
and
montenegro
",
"cu":"cuba",
-
+
"cv":"cape verde",
+
"cx":"christmas island",
"cy":"cyprus",
-
"cz":"
czechoslovakia
",
+
"cz":"
czech republic
",
+
"de":"germany",
+
"dj":"djibouti",
"dk":"denmark",
-
"
djibouti
":"
djibouti
",
+
"
dm
":"
dominica
",
"do":"dominican republic",
-
"
eg
":"
egypt
",
-
"
sv
":"
el salvador
",
-
"vg":"england",
-
"gb":"england",
-
"uk":"england",
-
"gq":"equatorial guinea",
+
"
dz
":"
algeria
",
+
"
ec
":"
ecuador
",
"ee":"estonia",
-
+
"eg":"egypt",
+
"eh":"western sahara",
+
"er":"eritrea",
+
"es":"spain",
"et":"ethiopia", "fi":"finland",
-
+
"fj":"fiji",
+
"fk":"falkland islands (malvinas)",
+
"fm":"micronesia, federal state of",
+
"fo":"faroe islands",
"fr":"france", "fx":"france",
-
"nc":"france",
-
"gf":"french guiana",
+
"ga":"gabon",
-
"
gm
":"
gambia
",
+
"
gb
":"
england
",
+
"gd":"grenada",
"ge":"georgia",
-
"
de
":"
germany
",
+
"
gf
":"
french guiana
",
+
"gg":"guernsey",
"gh":"ghana",
-
"
gr
":"
greece
",
+
"
gi
":"
gibraltar
",
"gl":"greenland",
-
"
gt
":"
guatemala
",
+
"
gm
":"
gambia
",
"gn":"guinea",
-
+
"gp":"guadeloupe",
+
"gq":"equatorial guinea",
+
"gr":"greece",
+
"gs":"south georgia and the south sandwich islands",
+
"gt":"guatemala",
+
"gu":"guam",
"gw":"guinea-bissau", "gy":"guyana",
-
+
"hk":"hong kong",
+
"hm":"heard and mcdonald islands",
+
"hn":"honduras",
+
"hr":"croatia",
+
"ht":"haiti",
"hu":"hungary",
-
"
is
":"
iceland
",
-
"in":"india",
-
"ir":"iran",
-
"iq":"iraq",
+
"
id
":"
indonesia
",
"ie":"ireland", "il":"israel",
-
"
va
":"
italy
",
+
"
im
":"
isle of man
",
+
"in":"india",
+
"io":"british indian ocean territory",
+
"iq":"iraq",
+
"ir":"iran",
+
"is":"iceland",
"it":"italy",
-
+
"je":"jersey",
"jm":"jamaica",
-
"jp":"japan",
+
"jo":"jordan",
-
"
kh
":"
cambodia
",
-
"ec":"ecuador",
-
"ht":"haiti",
-
"kh":"kampuchea",
-
"kg":"kyrgyzstan",
-
"hn":"honduras",
-
"by":"belarus",
-
"kz":"kazakhstan",
+
"
jp
":"
japan
",
"ke":"kenya",
-
+
"kg":"kyrgyzstan",
+
"kh":"cambodia",
+
"ki":"kiribati",
+
"km":"comoros",
+
"kn":"saint kitts and nevis",
+
"kp":"north korea",
+
"kr":"south korea",
"kw":"kuwait",
-
+
"ky":"cayman islands",
+
"kz":"kazakhstan",
"la":"laos",
-
"lv":"latvia",
+
"lb":"lebanon",
-
"
ls
":"
lesotho
",
+
"
lc
":"
saint lucia
",
+
"li":"liechtenstein",
+
"lk":"sri lanka",
"lr":"liberia",
-
"
ly
":"
libya
",
+
"
ls
":"
lesotho
",
"lt":"lithuania",
-
+
"lu":"luxembourg",
+
"lv":"latvia",
+
"ly":"libya",
+
"ma":"morocco",
+
"mc":"monaco",
+
"md":"moldova",
"mg":"madagascar",
-
"
my
":"
malaysia
",
+
"
mh
":"
marshall islands
",
+
"mk":"macedonia, the former yugoslav republic of",
"ml":"mali",
-
+
"mm":"myanmar",
+
"mn":"mongolia",
+
"mo":"macao",
+
"mp":"northern mariana islands",
+
"mq":"martinique",
"mr":"mauritania",
-
+
"ms":"montserrat",
+
"mt":"malta",
+
"mu":"mauritius",
+
"mv":"maldives",
+
"mw":"malawi",
"mx":"mexico",
-
"
md
":"
moldavia
",
-
"mn":"mongolia",
-
"ma":"morocco",
+
"
my
":"
malaysia
",
"mz":"mozambique", "na":"namibia",
-
"
np
":"
nepal",
-
"nl":"netherlands",
-
"nz":"
new
zealand
",
-
"ni":"nicaragua",
+
"
nc
":"new
caledonia
",
"ne":"niger",
-
+
"nf":"norfolk island",
"ng":"nigeria",
-
"
kp
":"
north
korea
",
+
"
ni
":"
nicaragua",
+
"
nl":"netherlands"
,
"no":"norway",
-
+
"np":"nepal",
+
"nr":"nauru",
+
"nu":"niue",
+
"nz":"new zealand",
"om":"oman",
-
"pk":"pakistan",
+
"pa":"panama",
-
"pg":"papua new guinea",
-
"py":"paraguay",
+
"pe":"peru",
-
+
"pf":"french polynesia",
+
"pg":"papua new guinea",
"ph":"philippines",
-
+
"pk":"pakistan",
"pl":"poland",
-
+
"pm":"saint pierre and miquelon",
+
"pn":"pitcairn island",
+
"pr":"puerto rico",
+
"ps":"palestinian territory, occupied",
"pt":"portugal",
-
+
"pw":"palau",
+
"py":"paraguay",
"qa":"qatar",
-
+
"re":"reunion island",
"ro":"romania",
-
+
"ru":"russian federation",
"rw":"rwanda", "sa":"saudi arabia",
-
"
sn
":"
senegal
",
+
"
sb
":"
solomon islands
",
+
"sc":"seychelles",
+
"sd":"sudan",
+
"se":"sweden",
+
"sg":"singapore",
+
"sh":"saint helena",
+
"si":"slovenia",
+
"sj":"svalbard and jan mayen islands",
+
"sk":"slovakia",
"sl":"sierra leone",
-
+
"sm":"san marino",
+
"sn":"senegal",
"so":"somalia",
-
"za":"south africa",
-
"kr":"south korea",
-
"es":"spain",
-
"lk":"sri lanka",
-
"sd":"sudan",
+
"sr":"suriname",
-
"
sz
":"
swaziland
",
-
"
se
":"
sweden
",
-
"
ch
":"
switzerland
",
+
"
st
":"
sao tome and principe
",
+
"
su
":"
russian federation
",
+
"
sv
":"
el salvador
",
"sy":"syria",
-
"
tw
":"
taiwan
",
-
"
tj
":"
tajikistan
",
-
"
tz
":"
tanzania
",
-
"
th
":"
thailand
",
+
"
sz
":"
swaziland
",
+
"
tc
":"
turks and caicos islands
",
+
"
td
":"
chad
",
+
"
tf
":"
french southern territories
",
"tg":"togo",
-
"
tt
":"
trinidad
and
tobago
",
+
"
th
":"
thailand",
+
"
tj":"tajikistan"
,
+
"tk":"tokelau",
+
"tl":"timor-leste",
+
"tm":"turkmenistan",
"tn":"tunisia",
-
+
"to":"tonga",
+
"tp":"east timor",
"tr":"turkey",
-
"
tm
":"
turkmenistan
",
-
"
ug
":"
uganda
",
+
"
tt
":"
trinidad and tobago
",
+
"
tv
":"
tuvalu
",
+
"tw":"taiwan",
+
"tz":"tanzania",
"ua":"ukraine",
-
"
ae
":"
united arab emirates
",
-
"
uy
":"
uruguay
",
-
"
vi
":"united states
of
america
",
+
"
ug
":"
uganda
",
+
"
uk
":"
england
",
+
"
um
":"united states
minor
outlying islands
",
"us":"united states of america",
-
"
gu
":"
united states of america
",
-
"com":"united states of america",
-
"net":"united states of america",
-
"org":"united states of america",
-
"edu":"united states of america",
-
"gov":"united states of america",
-
"mil":"united states of america",
-
"nato":"united states of america",
-
"su":"russian federation",
-
"ru":"russian federation",
+
"
uy
":"
uruguay
",
"uz":"uzbekistan",
-
+
"va":"italy",
+
"vc":"saint vincent and the grenadines",
"ve":"venezuela",
-
+
"vg":"virgin islands, british",
+
"vi":"virgin islands, u.s.",
"vn":"viet nam",
-
"
eh
":"western
sahara
",
+
"
vu
":"
vanuatu",
+
"wf":"wallis and futuna islands",
+
"ws":"
western
samoa
",
"ye":"yemen",
-
+
"yt":"mayotte",
"yu":"yugoslavia",
-
"
zr
":"
zaire
",
+
"
za
":"
south africa
",
"zm":"zambia",
-
+
"zr":"zaire",
"zw":"zimbabwe",
-
+
+
"com":"united states of america",
+
"net":"united states of america",
+
"org":"united states of america",
+
"edu":"united states of america",
+
"gov":"united states of america",
+
"mil":"united states of america",
+
"nato":"united states of america",
]); class Legend {
-
static
private string state_color_scheme = "white-to-red";
+
private string state_color_scheme = "white-to-red";
-
static
private mapping color_schemes = ([ "white-to-red":
+
private mapping color_schemes = ([ "white-to-red":
([ 0:({ 0xff,0xff,0xff }), 1:({ 0xe0,0xc0,0x80 }), 2:({ 0xe0,0x80,0x40 }), 3:({ 0xd0,0x40,0x00 }), 4:({ 0x80,0x00,0x00 }) ]), "white-to-green": ([ 0:({ 0xff,0xff,0xff }), 1:({ 0xe0,0xe0,0x80 }), 2:({ 0x80,0xe0,0x40 }), 3:({ 0x40,0xd0,0x00 }),
Roxen.git/server/etc/modules/Map.pmod:272:
opt->titles = ({ "1" })+ (opt->titles || ({ "" })); object font = opt->font; // Image.font("default"); int nom = font->height(); int title_h = nom*sizeof(opt->title/"\n")+nom/2; int bar_h = 6*nom; int width = max(font->text_extents(@opt->title/"\n")[0], font->text_extents(@opt->titles)[0] + nom+nom/2); int height = title_h + bar_h + 2*nom + nom;
-
object
img = Image.
image
(width, height+100, @opt->background_color);
+
Image.Image
img = Image.
Image
(width, height+100, @opt->background_color);
img->paste_alpha_color(font->write(@(opt->title/"\n")), @opt->title_color, 0, 0); for(int i = 0; i < bar_h; i++) img->line(0, title_h+i, nom, title_h+i, @color_scale(1.0 - i/(float)(bar_h), opt->color_scheme)); img->box(0, title_h+bar_h+nom/2, nom, title_h+bar_h+nom/2+(int)(nom*0.8), @color_scale(0, opt->color_scheme)); img->paste_alpha_color(font->write("0")->scale(0.8),
Roxen.git/server/etc/modules/Map.pmod:300:
} img = img->autocrop()->setcolor(@opt->background_color); img = img->copy(-opt->border, -opt->border, img->xsize()+opt->border-1, img->ysize()+opt->border-1); return img->scale(min(min(fixed_width/(float)img->xsize(), 1.0), min(fixed_height/(float)img->ysize(), 1.0))); } }
-
static
private mapping map_of_the_earth =
+
private mapping map_of_the_earth =
decode_value(Stdio.read_bytes("etc/maps/worldmap")); class Earth {
-
static
string state_region;
-
static
string state_country;
+
protected
string state_region;
+
protected
string state_country;
// Aliases. mapping(string:array(string)) country_name_aliases = ([ "United States of America":({ "USA", "US" }), "Russian Federation":({ "Russia" }), "England":({ "United Kingdom", "UK" }), "Viet Nam":({ "Vietnam" }), ]); // Official names.
Roxen.git/server/etc/modules/Map.pmod:342:
{ return sort(({ "World", "Europe", "Asia", "Africa", "Arab States", "North America", "South America", "Oceania" })); } object country(string new_country) { return object_program(this_object())(state_region, new_country); }
-
static
private string capitalize_country(string s)
+
private string capitalize_country(string s)
{ return Array.map(s/" ", lambda(string w) { switch(w) { case "of": case "and": return w; default: return capitalize(w);
Roxen.git/server/etc/modules/Map.pmod:368:
{ return sort(Array.map(indices(map_of_the_earth), capitalize_country)); } mixed polygons() { if(state_country) return map_of_the_earth[state_country]; }
-
static
private array(float) transform(float x, float y, mapping opt)
+
private array(float) transform(float x, float y, mapping opt)
{ y = 1.0-y; switch(lower_case(opt->region||state_region||"")) { case "europe": x = (x-0.33)*3.0; y = (y-0.05)*3.0; break; case "africa": x = (x-0.20)*1.5;
Roxen.git/server/etc/modules/Map.pmod:393:
y = (y-0.20)*3.0; break; case "north america": x = (x-0.00)*2.0; y = (y-0.05)*2.0; break; case "south america": x = (x-0.00)*1.5; y = (y-0.40)*1.5; break;
-
case "
south east
asia":
+
case "asia":
x = (x-0.57)*2.0; y = (y-0.17)*2.0; break; case "oceania": x = (x-0.63)*2.0; y = (y-0.47)*2.0; break; default: } return ({ x, y }); }
-
object
image(int width, int height, mapping|void opt)
+
Image.Image
image(int width, int height, mapping|void opt)
{ opt = opt || ([]); opt->color_sea = opt->color_sea || ({ 0x10,0x10,0x40 }); opt->color_fu = opt->color_fu || lambda() { return ({ 0xff,0xff,0xff }); };
-
Image.
image
map = Image.
image
(width, height, @opt->color_sea);
+
Image.
Image
map = Image.
Image
(width, height, @opt->color_sea);
foreach(indices(map_of_the_earth), string cntry) { map->setcolor(@opt->color_fu(cntry, @(opt->fu_args||({})))); foreach(map_of_the_earth[cntry], array(float) original_vertices) { array(float) vertices = copy_value(original_vertices); for(int v = 0; v < sizeof(vertices); v += 2) { array(float) a = transform(vertices[v+0], vertices[v+1], opt); vertices[v+0] = a[0]*width; vertices[v+1] = a[1]*height; }
Roxen.git/server/etc/modules/Map.pmod:452:
map->setcolor(@marker->color); map->polyfill( ({ x1, marker->y, marker->x, y1, x2, marker->y, marker->x, y2 }) ); } } // Apply borders. if(opt->border)
-
map = Image.
image
(map->xsize()+2*opt->border,
+
map = Image.
Image
(map->xsize()+2*opt->border,
map->ysize()+2*opt->border, @opt->color_sea)->paste(map, opt->border, opt->border); return map; } void create(void|string _state_region, void|string _state_country) { state_region = _state_region; state_country = _state_country; } }