diff options
Diffstat (limited to 'perllib/FixMyStreet/Map.pm')
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 86 |
1 files changed, 42 insertions, 44 deletions
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index 5305b360a..825e1cd19 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -13,18 +13,16 @@ use strict; use Module::Pluggable sub_name => 'maps', search_path => __PACKAGE__, - except => 'FixMyStreet::Map::Tilma::Original', require => 1; # Get the list of maps we want and load map classes at compile time my @ALL_MAP_CLASSES = allowed_maps(); -use Problems; -use Cobrand; use mySociety::Config; use mySociety::Gaze; use mySociety::Locale; use mySociety::Web qw(ent); +use Utils; =head2 allowed_maps @@ -63,55 +61,43 @@ sub display_map { return $map_class->display_map(@_); } -sub display_map_end { - my ($type) = @_; - my $out = '</div>'; - $out .= '</form>' if ($type); - return $out; -} - -sub header { - my ( $q, $type ) = @_; - return '' unless $type; - - my $cobrand = Page::get_cobrand($q); - my $cobrand_form_elements = - Cobrand::form_elements( $cobrand, 'mapForm', $q ); - my $form_action = Cobrand::url( $cobrand, '/', $q ); - my $encoding = ''; - $encoding = ' enctype="multipart/form-data"' if $type == 2; - my $pc = ent($q->param('pc') || ''); - my $map = ent($q->param('map') || ''); - return <<EOF; -<form action="$form_action" method="post" name="mapForm" id="mapForm"$encoding> -<input type="hidden" name="submit_map" value="1"> -<input type="hidden" name="map" value="$map"> -<input type="hidden" name="pc" value="$pc"> -$cobrand_form_elements -EOF -} - sub map_features { - my ( $q, $lat, $lon, $interval ) = @_; + my ( $c, $lat, $lon, $interval ) = @_; # TODO - be smarter about calculating the surrounding square # use deltas that are roughly 500m in the UK - so we get a 1 sq km search box my $lat_delta = 0.00438; my $lon_delta = 0.00736; + return _map_features( + $c, $lat, $lon, + $lon - $lon_delta, $lat - $lat_delta, + $lon + $lon_delta, $lat + $lat_delta, + $interval + ); +} - my $min_lat = $lat - $lat_delta; - my $max_lat = $lat + $lat_delta; +sub map_features_bounds { + my ( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval ) = @_; + + my $lat = ( $max_lat + $min_lat ) / 2; + my $lon = ( $max_lon + $min_lon ) / 2; + return _map_features( + $c, $lat, $lon, + $min_lon, $min_lat, + $max_lon, $max_lat, + $interval + ); +} - my $min_lon = $lon - $lon_delta; - my $max_lon = $lon + $lon_delta; +sub _map_features { + my ( $c, $lat, $lon, $min_lon, $min_lat, $max_lon, $max_lat, $interval ) = @_; # list of problems around map can be limited, but should show all pins - my $around_limit # - = Cobrand::on_map_list_limit( Page::get_cobrand($q) ) || undef; + my $around_limit = $c->cobrand->on_map_list_limit || undef; my @around_args = ( $min_lat, $max_lat, $min_lon, $max_lon, $interval ); - my $around_map_list = Problems::around_map( @around_args, $around_limit ); - my $around_map = Problems::around_map( @around_args, undef ); + my $around_map_list = $c->cobrand->problems->around_map( @around_args, $around_limit ); + my $around_map = $c->cobrand->problems->around_map( @around_args, undef ); my $dist; mySociety::Locale::in_gb_locale { @@ -122,9 +108,10 @@ sub map_features { $dist = int( $dist * 10 + 0.5 ) / 10; my $limit = 20; - my @ids = map { $_->{id} } @$around_map_list; - my $nearby = Problems::nearby( $dist, join( ',', @ids ), - $limit, $lat, $lon, $interval ); + my @ids = map { $_->id } @$around_map_list; + my $nearby = $c->model('DB::Nearby')->nearby( + $c, $dist, \@ids, $limit, $lat, $lon, $interval + ); return ( $around_map, $around_map_list, $nearby, $dist ); } @@ -137,8 +124,19 @@ sub click_to_wgs84 { return $map_class->click_to_wgs84(@_); } +=head2 tile_xy_to_wgs84 + +Takes the tile x,y and converts to lat, lon. Legacy to deal with old URLs, +hence hard-coded things. + +=cut + sub tile_xy_to_wgs84 { - return $map_class->tile_xy_to_wgs84(@_); + my ( $x, $y ) = @_; + my $easting = int( $x * (5000/31) + 0.5 ); + my $northing = int( $y * (5000/31) + 0.5 ); + my ( $lat, $lon ) = Utils::convert_en_to_latlon( $easting, $northing ); + return ( $lat, $lon ); } 1; |