aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm49
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm9
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm9
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm13
-rw-r--r--perllib/FixMyStreet/Map.pm94
-rw-r--r--t/map/tilma/original.t10
6 files changed, 78 insertions, 106 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index f8ea84d08..82a7a9e76 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -173,13 +173,15 @@ sub display_location : Private {
$c->forward('check_and_stash_category');
# get the map features
- my ( $on_map_all, $on_map, $around_map, $distance ) =
- FixMyStreet::Map::map_features( $c, $latitude, $longitude,
- $interval, $c->stash->{filter_category}, $c->stash->{filter_problem_states} );
+ my ( $on_map_all, $on_map, $nearby, $distance ) =
+ FixMyStreet::Map::map_features( $c,
+ latitude => $latitude, longitude => $longitude,
+ interval => $interval, category => $c->stash->{filter_category},
+ states => $c->stash->{filter_problem_states} );
# copy the found reports to the stash
$c->stash->{on_map} = $on_map;
- $c->stash->{around_map} = $around_map;
+ $c->stash->{around_map} = $nearby;
$c->stash->{distance} = $distance;
# create a list of all the pins
@@ -188,16 +190,8 @@ sub display_location : Private {
@pins = map {
# Here we might have a DB::Problem or a DB::Nearby, we always want the problem.
my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_;
- my $colour = $c->cobrand->pin_colour( $p, 'around' );
- {
- latitude => $p->latitude,
- longitude => $p->longitude,
- colour => $colour,
- id => $p->id,
- title => $p->title_safe,
- problem => $p,
- }
- } @$on_map_all, @$around_map;
+ $p->pin_data($c, 'around');
+ } @$on_map_all, @$nearby;
}
$c->stash->{page} = 'around'; # So the map knows to make clickable pins, update on pan
@@ -281,7 +275,8 @@ sub ajax : Path('/ajax') {
$c->res->content_type('application/json; charset=utf-8');
- unless ( $c->get_param('bbox') ) {
+ my $bbox = $c->get_param('bbox');
+ unless ($bbox) {
$c->res->status(404);
$c->res->body('');
return;
@@ -297,18 +292,34 @@ sub ajax : Path('/ajax') {
# Need to be the class that can handle it
FixMyStreet::Map::set_map_class( 'OSM' );
+ $c->forward( '/reports/stash_report_filter_status' );
+
# extract the data from the map
- my ( $pins, $on_map, $around_map, $dist ) =
- FixMyStreet::Map::map_pins( $c, $interval );
+ my ( $on_map_all, $on_map_list, $nearby, $dist ) =
+ FixMyStreet::Map::map_features($c,
+ bbox => $bbox, interval => $interval,
+ category => $c->get_param('filter_category'),
+ states => $c->stash->{filter_problem_states} );
+
+ # create a list of all the pins
+ my @pins = map {
+ # Here we might have a DB::Problem or a DB::Nearby, we always want the problem.
+ my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_;
+ my $colour = $c->cobrand->pin_colour( $p, 'around' );
+ [ $p->latitude, $p->longitude,
+ $colour,
+ $p->id, $p->title_safe
+ ]
+ } @$on_map_all, @$nearby;
# render templates to get the html
my $on_map_list_html = $c->render_fragment(
'around/on_map_list_items.html',
- { on_map => $on_map, around_map => $around_map }
+ { on_map => $on_map_list, around_map => $nearby }
);
# JSON encode the response
- my $json = { pins => $pins };
+ my $json = { pins => \@pins };
$json->{current} = $on_map_list_html if $on_map_list_html;
my $body = encode_json($json);
$c->res->body($body);
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index 659d62c0b..72391fee2 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -52,14 +52,7 @@ sub my : Path : Args(0) {
while ( my $problem = $rs->next ) {
$c->stash->{has_content}++;
- push @$pins, {
- latitude => $problem->latitude,
- longitude => $problem->longitude,
- colour => $c->cobrand->pin_colour( $problem, 'my' ),
- id => $problem->id,
- title => $problem->title,
- problem => $problem,
- };
+ push @$pins, $problem->pin_data($c, 'my', private => 1);
push @$problems, $problem;
}
$c->stash->{problems_pager} = $rs->pager;
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index eec180ba1..ddc75163a 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -485,14 +485,7 @@ sub stash_report_filter_status : Private {
sub add_row {
my ( $c, $problem, $body, $problems, $pins ) = @_;
push @{$problems->{$body}}, $problem;
- push @$pins, {
- latitude => $problem->latitude,
- longitude => $problem->longitude,
- colour => $c->cobrand->pin_colour( $problem, 'reports' ),
- id => $problem->id,
- title => $problem->title_safe,
- problem => $problem,
- };
+ push @$pins, $problem->pin_data($c, 'reports');
}
=head1 AUTHOR
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index bc72cf9da..2599f24ae 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -892,5 +892,18 @@ has get_cobrand_logged => (
},
);
+sub pin_data {
+ my ($self, $c, $page, %opts) = @_;
+ my $colour = $c->cobrand->pin_colour($self, $page);
+
+ {
+ latitude => $self->latitude,
+ longitude => $self->longitude,
+ colour => $colour,
+ id => $self->id,
+ title => $opts{private} ? $self->title : $self->title_safe,
+ problem => $self,
+ }
+}
1;
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm
index b8b128611..355fd8666 100644
--- a/perllib/FixMyStreet/Map.pm
+++ b/perllib/FixMyStreet/Map.pm
@@ -65,82 +65,44 @@ sub display_map {
}
sub map_features {
- my ( $c, $lat, $lon, $interval, $category, $states ) = @_;
-
- # 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, $category, $states
- );
-}
-
-sub map_features_bounds {
- my ( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category, $states ) = @_;
-
- 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, $category,
- $states
- );
-}
-
-sub _map_features {
- my ( $c, $lat, $lon, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category, $states ) = @_;
+ my ( $c, %p ) = @_;
+
+ if ($p{bbox}) {
+ @p{"min_lon", "min_lat", "max_lon", "max_lat"} = split /,/, $p{bbox};
+ }
+
+ if ($p{latitude} && $p{longitude}) {
+ # 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;
+ $p{min_lon} = $p{longitude} - $lon_delta;
+ $p{min_lat} = $p{latitude} - $lat_delta;
+ $p{max_lon} = $p{longitude} + $lon_delta;
+ $p{max_lat} = $p{latitude} + $lat_delta;
+ } else {
+ $p{longitude} = ($p{max_lon} + $p{min_lon} ) / 2;
+ $p{latitude} = ($p{max_lat} + $p{min_lat} ) / 2;
+ }
# list of problems around map can be limited, but should show all pins
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 = $c->cobrand->problems_on_map->around_map( @around_args, undef, $category, $states );
- my $around_map_list = $around_limit
- ? $c->cobrand->problems_on_map->around_map( @around_args, $around_limit, $category, $states )
- : $around_map;
+ my @around_args = @p{"min_lat", "max_lat", "min_lon", "max_lon", "interval"};
+ my $on_map_all = $c->cobrand->problems_on_map->around_map( @around_args, undef, $p{category}, $p{states} );
+ my $on_map_list = $around_limit
+ ? $c->cobrand->problems_on_map->around_map( @around_args, $around_limit, $p{category}, $p{states} )
+ : $on_map_all;
- my $dist = FixMyStreet::Gaze::get_radius_containing_population( $lat, $lon );
+ my $dist = FixMyStreet::Gaze::get_radius_containing_population( $p{latitude}, $p{longitude} );
my $limit = 20;
- my @ids = map { $_->id } @$around_map_list;
+ my @ids = map { $_->id } @$on_map_list;
my $nearby = $c->model('DB::Nearby')->nearby(
- $c, $dist, \@ids, $limit, $lat, $lon, $interval, $category, $states
+ $c, $dist, \@ids, $limit, @p{"latitude", "longitude", "interval", "category", "states"}
);
- return ( $around_map, $around_map_list, $nearby, $dist );
-}
-
-sub map_pins {
- my ($c, $interval) = @_;
-
- my $bbox = $c->get_param('bbox');
- my ( $min_lon, $min_lat, $max_lon, $max_lat ) = split /,/, $bbox;
- my $category = $c->get_param('filter_category');
-
- $c->forward( '/reports/stash_report_filter_status' );
- my $states = $c->stash->{filter_problem_states};
-
- my ( $around_map, $around_map_list, $nearby, $dist ) =
- FixMyStreet::Map::map_features_bounds( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category, $states );
-
- # create a list of all the pins
- my @pins = map {
- # Here we might have a DB::Problem or a DB::Nearby, we always want the problem.
- my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_;
- my $colour = $c->cobrand->pin_colour( $p, 'around' );
- [ $p->latitude, $p->longitude,
- $colour,
- $p->id, $p->title_safe
- ]
- } @$around_map, @$nearby;
-
- return (\@pins, $around_map_list, $nearby, $dist);
+ return ( $on_map_all, $on_map_list, $nearby, $dist );
}
sub click_to_wgs84 {
diff --git a/t/map/tilma/original.t b/t/map/tilma/original.t
index a1c6d83f4..f16f5b244 100644
--- a/t/map/tilma/original.t
+++ b/t/map/tilma/original.t
@@ -99,18 +99,18 @@ for my $test (
$report->state($test->{state});
$report->update;
- my ( $pins, $around_map_list, $nearby, $dist ) =
- FixMyStreet::Map::map_pins( $c, 0, 0, 0, 0 );
+ my ( $on_map_all, $on_map_list, $nearby, $dist ) =
+ FixMyStreet::Map::map_features($c, bbox => "0,0,0,0");
- ok $pins;
- ok $around_map_list;
+ ok $on_map_list;
ok $nearby;
ok $dist;
my $id = $report->id;
my $colour = $test->{colour};
- is $pins->[0][2], $colour, 'pin colour';
+ my $pin_colour = $c->cobrand->pin_colour($on_map_all->[0], 'around');
+ is $pin_colour, $colour, 'pin colour';
};
}