Leser: 23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
#!/usr/bin/perl use strict; use warnings; use POSIX qw(floor); use GD::Image; # use GD::Simple; use Data::Dumper; my %map_data = ( border_left => 5.8, border_right => 17.2, border_bottom => 45.8, border_top => 55.1, ); my %img_data = ( max_x => 800.0, max_y => 1029.0, ); my %coords; sub as_pixel_coords { my $m = shift; my $i = shift; my $t = shift || [ 50.107368, 8.664651 ]; # ffm centralstation my $x_pixel = floor( ( $t->[1] - $m->{'border_left'} ) * ( $i->{'max_x'} / ( $m->{'border_right'} - $m->{'border_left'} ) ) ); my $y_pixel = floor( ( $t->[0] - $m->{'border_top'} ) * ( $i->{'max_y'} / ( $m->{'border_bottom'} - $m->{'border_top'} ) ) ); return $x_pixel, $y_pixel; } sub area_tag { my ( $y, $x, $radius, $url, $user, $uid ) = @_; $url ||= 'http://www.example.net/forum/member.php?u='; $user ||= 'john doe'; $uid ||= '0815'; return qq{ <area shape="circle" coords="$x,$y,$radius" href="$url$uid" title="$user" /> }; } open(my $db, '<', 'opengeodb.txt') or die $!; while (<$db>) { chomp; next if /^#/ or /^\s*$/; my $row = [ split /;/, $_ ]; $coords{$row->[-1]} = [ $row->[-2], $row->[-3] ]; } close $db or warn $!; my $img = GD::Image->new( 'au_ch_de.png' ); @img_data{'max_x', 'max_y'} = ( $img->width(), $img->height() ); my $red = $img->colorAllocate(255,0,0); print q{ <img src="map.png" alt="Karte" usemap="#usermap" /> <map name="usermap"> }; while(<DATA>) { chomp; next unless /^\w+;\d+;\d+$/; my ($user, $uid, $postcode) = split /;/; $img->filledEllipse( as_pixel_coords( \%map_data, \%img_data, $coords{$postcode} ), 7, 7, $red ); print area_tag( as_pixel_coords(\%map_data, \%img_data, $coords{$postcode}), 7, undef, $user, $uid ); } print q{ </map> }; open(MAP, '>', 'map.png') or die $!; print MAP $img->png; close MAP; __DATA__ tim;201;64287 tom;202;80331 joe;203;20095 bob;204;01067
2009-05-01T20:56:42 esskarwas stellt map_data genau da und wie hast du es berechnet?