#!/usr/bin/perl use CGI; use Imager; use Imager::Fill; use Geo::Dymaxion; # available from CPAN, requires Inline.pm use strict; use warnings; my $image_file = "dymaxion.jpg"; my $cities_file = "cities.txt"; my $dot_color = "red"; my $dot_size = 3; $|++; my $cgi = CGI->new; my %var = $cgi->Vars; if ($var{img}) { my $map = Imager->new; $map->open( file => $image_file ); my $type = $map->type; print $cgi->header("image/jpeg"); my $dymax = Geo::Dymaxion->new( $map->getwidth, $map->getheight ); my ($x, $y) = $dymax->plot( $var{lat}, $var{long} ); $map->circle( color => "white", r => $dot_size + 1, x => $x, y => $y ); $map->circle( color => $dot_color, r => $dot_size, x => $x, y => $y ); $map->write( type => "jpeg", fd => fileno(STDOUT) ) or die $map->errstr; } else { my $this = $cgi->url; print $cgi->header; print qq{Population Centers across the Earth
}; print qq{Latitude: }, $cgi->textfield("lat"), qq{ }; print qq{Longitude: }, $cgi->textfield("long"), qq{ }; print $cgi->popup_menu(-name =>'city', -onChange => "updateCity(this)"); print qq{}; print " ", $cgi->submit( -value => "Plot" ), qq{

\n}; if (defined $var{lat} and defined $var{long}) { print qq{} } else { print qq{}; } print qq{}; }