diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-07-13 10:58:07 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-07-21 17:37:47 +0100 |
commit | ef9850616c71d82980bdf77e001267a89337e1a8 (patch) | |
tree | 22ea4291b7f374589ba75a173027704f5bc0b599 /perllib/FixMyStreet/App/Controller/Around.pm | |
parent | 17ebb70ee0e1d0452b824d3d8daee7405f5edf5c (diff) |
Refactor map pin/feature functions.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Around.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 49 |
1 files changed, 30 insertions, 19 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); |