#!/usr/bin/perl -w -I/home/chris/projects/planning/lib # # position: # Select position, radius from a map. # # Copyright (c) 2003 Chris Lightfoot. All rights reserved. # Email: chris@ex-parrot.com; WWW: http://www.ex-parrot.com/~chris/ # my $rcsid = ''; $rcsid .= '$Id: position,v 1.3 2003/11/09 02:23:34 chris Exp $'; use strict; use Error qw(:try); use CGI qw(-no_xhtml -nosticky -compile); use CGI::Fast; use DBI; use HTML::Entities; use Planning; try { while (my $q = new CGI::Fast()) { # We interpret parameters gridn, gride, dist. my $mapurl = 'map'; my ($N, $E, $dist); my ($x, $y) = ($q->param('coords.x'), $q->param('coords.y')); if (defined($x) and $x !~ /[^\d]/ and defined($y) and $y !~ /[^\d]/) { ($N, $E) = Planning::Map::pixels_to_ordsvy($x, $y); $q->param('gridn', $N); $q->param('gride', $E); } $dist = $q->param('dist'); if (!$dist or $dist =~ /[^\d]/ or $dist < 100) { $q->param('dist', 805); } ($N, $E, $dist) = map { $q->param($_) } qw(gridn gride dist); if ($N and $N !~ /[^\d]/ and $E and $E !~ /[^\d]/ and $dist and $dist !~ /[^\d]/) { # If we have all three, and the user hit `Finish', go back to the # search page. if ($q->param('Finish')) { $q->delete('Finish'); print $q->redirect('search?' . $q->query_string()); next; } $mapurl = sprintf('map?circle=%d,%d,%d', $N, $E, $dist); } print $q->header(-type => 'text/html', -charset => 'iso-8859-1', -expires => '+1d'), $q->start_html(-title => "Select map position", -style => { -src => '../std.css' }), $q->h1("Select position"), $q->p(q(Select a distance and click on a map below to search for planning applications within that distance of the point you select. Click "finish" when you're done.)), $q->start_form(-method => 'GET'), $q->hidden(-name => 'gridn'), $q->hidden(-name => 'gride'), $q->p(q(Distance: ), $q->popup_menu(-name => 'dist', -values => [402, 805, 1610, 2415, 3220, 4025, 4830], -labels => { 402 => '¼ mile', 805 => '½ mile', 1207 => '¾ mile', 1610 => '1 mile', 2415 => '1½ mile', 3220 => '2 miles', 4025 => '2½ miles', 4830 => '3 miles' }), $q->submit(-name => 'Change distance'), $q->submit(-name => 'Finish')), $q->image_button(-name => 'coords', -alt => 'Map', -src => $mapurl, -width => $Planning::Map::mapimg_width, -height => $Planning::Map::mapimg_height), $q->p({-class => 'smallprint'}, q(Image produced from the Ordnance Survey Get-a-map service. Image reproduced with kind permission of Ordnance Survey and Ordnance Survey of Northern Ireland.)), $q->end_form(), Planning::copyright_blurb($q), $q->end_html(); } } catch Error::Simple with { my $E = shift; my $msg = sprintf('%s:%d: %s', $E->file(), $E->line(), $E->text()); warn "caught fatal exception: $msg"; warn "aborting"; encode_entities($msg); print "Status: 500\nContent-Type: text/html; charset=iso-8859-1\n\n", CGI::start_html(-title => "Cambridge Planning: error", -style => { -src => '../std.css' }), CGI::h1("Error"), q(
Unfortunately, something went wrong. The text of the error was:
), qq($msg), q(
Please try again later.), CGI::end_html(); };