diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-04-15 11:25:42 +0100 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-04-15 11:25:42 +0100 |
commit | 5bb7634143bd320b20601c3d92efc0b6987a0d8d (patch) | |
tree | 43c8035bd7b0d96d5aeaedc4481b62b31bc9868b /perllib/FixMyStreet/App/Controller | |
parent | 7a366593576587a6b654ea967e8beefb2dba6b1c (diff) |
Handle (e,n) requests to '/'
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 50 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Root.pm | 2 |
2 files changed, 42 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 19b2dbaf7..4278c9bbb 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -8,6 +8,7 @@ use FixMyStreet::Map; use List::MoreUtils qw(any); use Encode; use FixMyStreet::Map; +use Utils; =head1 NAME @@ -32,15 +33,8 @@ If no search redirect back to the homepage. sub around_index : Path : Args(0) { my ( $self, $c ) = @_; - # check for x,y requests and redirect them to lat,lon - my $x = $c->req->param('x'); - my $y = $c->req->param('y'); - if ( $x || $y ) { - my ( $lat, $lon ) = FixMyStreet::Map::tile_xy_to_wgs84( $x, $y ); - my $ll_uri = $c->uri_for( '/around', { lat => $lat, lon => $lon } ); - $c->res->redirect( $ll_uri, 301 ); - return; - } + # handle old coord systems + $c->forward('redirect_en_or_xy'); # Check if we have a partial report my $partial_report = $c->forward('load_partial'); @@ -72,6 +66,44 @@ sub around_index : Path : Args(0) { $c->detach('display_location'); } +=head2 redirect_en_or_xy + + $c->forward('redirect_en_or_xy'); # does not return if there was rd + +Handle coord systems that are no longer in use. + +=cut + +sub redirect_en_or_xy : Private { + my ( $self, $c ) = @_; + my $req = $c->req; + + # check for x,y requests and redirect them to lat,lon + my $x = $req->param('x'); + my $y = $req->param('y'); + my $e = $req->param('e'); + my $n = $req->param('n'); + + # lat and lon - fill in below if we need to + my ( $lat, $lon ); + + if ( $x || $y ) { + ( $lat, $lon ) = FixMyStreet::Map::tile_xy_to_wgs84( $x, $y ); + } + + if ( $e || $n ) { + ( $lat, $lon ) = Utils::convert_en_to_latlon_truncated( $e, $n ); + } + + # return if nothing set + return unless $lat || $lon; + + # create a uri and redirect to it + my $ll_uri = $c->uri_for( '/around', { lat => $lat, lon => $lon } ); + $c->res->redirect( $ll_uri, 301 ); + $c->detach; +} + =head2 load_partial my $partial_report = $c->forward('load_partial'); diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm index 2dc770da5..3280d02b9 100644 --- a/perllib/FixMyStreet/App/Controller/Root.pm +++ b/perllib/FixMyStreet/App/Controller/Root.pm @@ -43,7 +43,7 @@ preserve old behaviour. sub index : Path : Args(0) { my ( $self, $c ) = @_; - my @old_param_keys = ( 'pc', 'x', 'y', 'lat', 'lon' ); + my @old_param_keys = ( 'pc', 'x', 'y', 'e', 'n', 'lat', 'lon' ); my %old_params = (); foreach my $key (@old_param_keys) { |