<%args> $locs => '' $spots => '' $h => 148 $v => '0.2' # version of greasemap client script used by this user. Leave this set to 0.2 as default; that is the newest version we offered which didn't report its version number $big => 0 <%flags> inherit => undef <%init> use Unicode::String qw(latin1 utf8); $locs = utf8($locs); $spots = utf8($spots); $locs =~ s/
/,/g; my ($current_version) = '0.6'; my @points = (); my ($mnx,$mny) = (9999999,9999999); my ($mxx,$mxy) = (-9999,-9999); my ($debug) = 0; if ($r->get_remote_host() eq '63.204.12.250') { $debug = 1; } use Geo::Coder::US; Geo::Coder::US->set_db("/usr/local/mapping/geocoder.db"); my %seen = (); if ($locs) { $locs =~ s/(\d+) (\d+) /$2 /g; $locs =~ s/<.*?>/ /g; $locs =~ s/\n/ /mg; $locs =~ s/\b(north tower, )//ig; $locs =~ s/\b(room|floor|suite|no\.) (one|\d+)//ig; $locs =~ s/\b\d+(th|nd|st)\s+(floor|suite)//ig; $locs =~ s/\s+/ /g; foreach my $addr (split(/;/,$locs)) { next if ($seen{$addr}); $seen{$addr}=1; my ($g) = Geo::Coder::US->geocode($addr); if ($g and $g->{lat} and $g->{long}) { my $street = join(' ',grep(!/^$/,($g->{number},$g->{prefix},$g->{street},$g->{type},$g->{suffix}))); next if ($seen{"$street $g->{city} $g->{state} $g->{zip}"}); $seen{"$street $g->{city} $g->{state} $g->{zip}"}=1; push(@points,[$g->{lat},$g->{long},$street,"$g->{city}, $g->{state} $g->{zip}"]); } } } if ($spots) { my @spots = split(/;/,$spots); my ($x,$y); foreach my $spot (@spots) { if ($spot =~ m/(N|S)\s*([\d\.]+)..\s*([\d\.]+)?'?\s*(W|E)\s*([\d\.]+)..\s*([\d\.]+)?'?/) { my ($latd,$lat1,$lat2,$longd,$long1,$long2) = ($1,$2,$3,$4,$5,$6); $x = $lat1; if ($lat2) { $x += ($lat2/60.0); } if ($latd eq 'S') { $x = -$x; } $y = $long1; if ($long2) { $y += ($long2/60.0); } if ($longd eq 'W') { $y = -$y; } $x = sprintf("%.6f",$x); $y = sprintf("%.6f",$y); } elsif ($spot =~ m/([\d\.]+)(N|S)\s*([\d\.]+)(E|W)/) { my ($lat1,$latd,$long1,$longd) = ($1,$2,$3,$4); $x = $lat1; if ($latd eq 'S') { $x = -$x; } $y = $long1; if ($longd eq 'W') { $y = -$y; } $x = sprintf("%.6f",$x); $y = sprintf("%.6f",$y); } else { $spot =~ s/\s+//g; next if ($seen{$spot}); ($x,$y) = split(/[,;]/,$spot); } $seen{$spot}=1; push(@points,[$x,$y,"$x $y",'']); } } # Compute extent from these points foreach my $p (@points) { my ($a,$b) = ($p->[0],$p->[1]); if ($b < $mnx) { $mnx = $b; } if ($b > $mxx) { $mxx = $b; } if ($a < $mny) { $mny = $a; } if ($a > $mxy) { $mxy = $a; } } my @zl = (0.001,0.003,0.006,0.02,0.04,0.08,0.16,0.32,0.64,1.0,1.6,4,8,16); my $range = ($mxx - $mnx); my $rangey = ($mxy - $mny); my $cx = ($mxx + $mnx) / 2; my $cy = ($mxy + ($mny + ($rangey/6))) / 2; if ($rangey > $range) { $range = $rangey; } my ($thezl) = 0; foreach my $z (@zl) { $thezl++; last if ($range < $z); } if ($big) { # This is rough; we go to a more zoomed-in map if we're in "big" mode $thezl-=1; if ($thezl < 1) { $thezl = 1; } } % if (@points) { GreaseMap Locations % if ($big) { % }
Greasemap <% $v %> by VINQ
% if (not $big) { Big map in new window
% } % if ($v < $current_version) { <% $v %> < <% $current_version %>: Upgrade Greasemap
% } <% scalar(@points) %> Location<% @points > 1 ? 's' : '' %> found
% if ($big) {
Click a location to highlight it or for directions
% } % my $n=0; % foreach (@points) {
<% $_->[2] %>
<% $_->[3] %>
% $n++; % }
% if ($big) {
% } else {
% } % } else { Addresses were found on this page, but they could not be geocoded.
<% $locs %>
This is still a work in progress. % }