diff options
Diffstat (limited to 'web/index.cgi')
-rwxr-xr-x | web/index.cgi | 89 |
1 files changed, 52 insertions, 37 deletions
diff --git a/web/index.cgi b/web/index.cgi index f3c0a8e64..33bf4b00b 100755 --- a/web/index.cgi +++ b/web/index.cgi @@ -6,7 +6,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # -# $Id: index.cgi,v 1.11 2006-09-20 16:12:06 matthew Exp $ +# $Id: index.cgi,v 1.12 2006-09-20 16:47:51 matthew Exp $ use strict; require 5.8.0; @@ -17,6 +17,8 @@ use lib "$FindBin::Bin/../perllib"; use lib "$FindBin::Bin/../../perllib"; use Error qw(:try); use HTML::Entities; +use LWP::Simple; +use RABX; use Page; use mySociety::Config; @@ -73,60 +75,72 @@ EOF return $out; } -# This should use postcode, not x/y! sub display { my $q = shift; my $pc = $q->param('pc'); + my $x = $q->param('x') || 0; + my $y = $q->param('y') || 0; + $x+=0; + $y+=0; - my $areas; - my $error; + my($error, $name, $lbo); try { + my $areas; $areas = mySociety::MaPit::get_voting_areas($pc); + + # Check for London Borough + throw RABX::Error("I'm afraid that postcode isn't in our covered area.", 123456) if (!$areas || !$areas->{LBO}); + + # Check for Lewisham or Newham + $lbo = $areas->{LBO}; + throw RABX::Error("I'm afraid that postcode isn't in our covered London boroughs.", 123457) unless ($lbo == 2510 || $lbo == 2492); + + my $area_info = mySociety::MaPit::get_voting_area_info($lbo); + $name = $area_info->{name}; + + if (!$x && !$y) { + my $location = mySociety::MaPit::get_location($pc); + my $northing = $location->{northing}; + my $easting = $location->{easting}; + $x = int($easting / (5000/31)); + $y = int($northing/ (5000/31)); + } } catch RABX::Error with { my $e = shift; if ($e->value() == mySociety::MaPit::BAD_POSTCODE - || $e->value() == mySociety::MaPit::POSTCODE_NOT_FOUND) { + || $e->value() == mySociety::MaPit::POSTCODE_NOT_FOUND) { $error = 'That postcode was not recognised, sorry.'; } else { - $e->throw(); + $error = $e; } }; return front_page($error) if ($error); - # Check for London Borough - return front_page('I\'m afraid that postcode isn\'t in our covered area.') if (!$areas || !$areas->{LBO}); - - # Check for Lewisham or Newham - my $lbo = $areas->{LBO}; - return front_page('I\'m afraid that postcode isn\'t in our covered London boroughs.') unless ($lbo == 2510 || $lbo == 2492); - - my $area_info = mySociety::MaPit::get_voting_area_info($lbo); - my $name = $area_info->{name}; - - my $location = mySociety::MaPit::get_location($pc); - my $out = <<EOF; <h2>$name</h2> <p>Now, please select the location of the problem on the map below. Use the arrows to the left of the map to scroll around.</p> EOF - my @ps = $q->param; - foreach (@ps) { - my $x = $q->param($_) if /\.x$/; - my $y = $q->param($_) if /\.y$/; - } + +# XXX: This is for when they click on the map +# my @ps = $q->param; +# foreach (@ps) { +# my $x = $q->param($_) if /\.x$/; +# my $y = $q->param($_) if /\.y$/; +# } - my $x = $q->param('x') || 628; - my $y = $q->param('y') || 1724; - my $dir = mySociety::Config::get('TILES_URL'); - my $tl = $x . '.' . $y; - my $tr = ($x+1) . '.' . $y; - my $bl = $x . '.' . ($y+1); - my $br = ($x+1) . '.' . ($y+1); - my $tl_src = $dir . $tl . '.png'; - my $tr_src = $dir . $tr . '.png'; - my $bl_src = $dir . $bl . '.png'; - my $br_src = $dir . $br . '.png'; + my $url = mySociety::Config::get('TILES_URL'); + my $tiles = $url . $x . '-' . ($x+1) . ',' . $y . '-' . ($y+1) . '/RABX'; + $tiles = LWP::Simple::get($tiles); + my $tileids = RABX::unserialise($tiles); + my $tl = $x . '.' . ($y+1); + my $tr = ($x+1) . '.' . ($y+1); + my $bl = $x . '.' . $y; + my $br = ($x+1) . '.' . $y; + my $tl_src = $url . $tileids->[0][0]; + my $tr_src = $url . $tileids->[0][1]; + my $bl_src = $url . $tileids->[1][0]; + my $br_src = $url . $tileids->[1][1]; $pc = encode_entities($pc); $out .= <<EOF; <form action"=./" method="get"> @@ -136,7 +150,7 @@ EOF <input type="hidden" name="y" value="$y"> <input type="hidden" name="pc" value="$pc"> <input type="hidden" name="lbo" value="$lbo"> - <input type="image" id="2.2" name="$tl" src="$tl_src" style="top:0px; left:0px;"><input type="image" id="3.2" name="$tr" src="$tr_src" style="top:0px; left:250px;"><br><input type="image" id="2.3" name="$bl" src="$bl_src" style="top:250px; left:0px;"><input type="image" id="3.3" name="$br" src="$br_src" style="top:250px; left:250px;"> + <input type="image" id="2.2" name="tile_$tl" src="$tl_src" style="top:0px; left:0px;"><input type="image" id="3.2" name="tile_$tr" src="$tr_src" style="top:0px; left:254px;"><br><input type="image" id="2.3" name="tile_$bl" src="$bl_src" style="top:254px; left:0px;"><input type="image" id="3.3" name="tile_$br" src="$br_src" style="top:254px; left:254px;"> </div> EOF $out .= Page::compass($pc, $x, $y); @@ -156,8 +170,8 @@ EOF 6 => 'Abandoned car', ); foreach (sort keys %current) { - my $px = int(rand(500)) - 6; - my $py = int(rand(500)) - 20; + my $px = int(rand(508)) - 6; + my $py = int(rand(508)) - 20; $out .= '<li><a href="/?id=' . $_ . '">'; $out .= '<img src="/i/pin_red.png" alt="Problem"'; $out .= ' style="top:'.$py.'px; right:'.$px.'px">'; @@ -189,3 +203,4 @@ to describe the location of your problem instead.</p> EOF return $out; } + |