diff options
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Nearby.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 19 | ||||
-rw-r--r-- | web/js/map-OpenLayers.js | 26 |
4 files changed, 39 insertions, 12 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm index 91c44d5f4..06aca26db 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm @@ -5,7 +5,7 @@ use strict; use warnings; sub nearby { - my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval ) = @_; + my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval, $category ) = @_; my $params = { non_public => 0, @@ -19,6 +19,7 @@ sub nearby { %{ $c->cobrand->problems_clause }, %$params } if $c->cobrand->problems_clause; + $params->{category} = $category if $category; my $attrs = { prefetch => 'problem', diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 7a50a3146..affc6b177 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -131,7 +131,7 @@ sub _recent { # Problems around a location sub around_map { - my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit ) = @_; + my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit, $category ) = @_; my $attr = { order_by => { -desc => 'created' }, }; @@ -145,6 +145,7 @@ sub around_map { }; $q->{'current_timestamp - lastupdate'} = { '<', \"'$interval'::interval" } if $interval; + $q->{category} = $category if $category; my @problems = mySociety::Locale::in_gb_locale { $rs->search( $q, $attr )->all }; return \@problems; diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index 7d490fde3..2bc37ad0a 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -55,7 +55,7 @@ sub display_map { } sub map_features { - my ( $c, $lat, $lon, $interval ) = @_; + my ( $c, $lat, $lon, $interval, $category ) = @_; # 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 @@ -65,12 +65,12 @@ sub map_features { $c, $lat, $lon, $lon - $lon_delta, $lat - $lat_delta, $lon + $lon_delta, $lat + $lat_delta, - $interval + $interval, $category ); } sub map_features_bounds { - my ( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval ) = @_; + my ( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category ) = @_; my $lat = ( $max_lat + $min_lat ) / 2; my $lon = ( $max_lon + $min_lon ) / 2; @@ -78,20 +78,20 @@ sub map_features_bounds { $c, $lat, $lon, $min_lon, $min_lat, $max_lon, $max_lat, - $interval + $interval, $category ); } sub _map_features { - my ( $c, $lat, $lon, $min_lon, $min_lat, $max_lon, $max_lat, $interval ) = @_; + my ( $c, $lat, $lon, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category ) = @_; # 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->around_map( @around_args, undef ); + my $around_map = $c->cobrand->problems->around_map( @around_args, undef, $category ); my $around_map_list = $around_limit - ? $c->cobrand->problems->around_map( @around_args, $around_limit ) + ? $c->cobrand->problems->around_map( @around_args, $around_limit, $category ) : $around_map; my $dist; @@ -105,7 +105,7 @@ sub _map_features { my $limit = 20; my @ids = map { $_->id } @$around_map_list; my $nearby = $c->model('DB::Nearby')->nearby( - $c, $dist, \@ids, $limit, $lat, $lon, $interval + $c, $dist, \@ids, $limit, $lat, $lon, $interval, $category ); return ( $around_map, $around_map_list, $nearby, $dist ); @@ -116,9 +116,10 @@ sub map_pins { my $bbox = $c->req->param('bbox'); my ( $min_lon, $min_lat, $max_lon, $max_lat ) = split /,/, $bbox; + my $category = $c->req->param('category'); my ( $around_map, $around_map_list, $nearby, $dist ) = - FixMyStreet::Map::map_features_bounds( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval ); + FixMyStreet::Map::map_features_bounds( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category ); # create a list of all the pins my @pins = map { diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index c227a366e..f459459ec 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -196,7 +196,7 @@ function fixmystreet_onload() { if (fixmystreet.page == 'around') { fixmystreet.bbox_strategy = fixmystreet.bbox_strategy || new OpenLayers.Strategy.BBOX({ ratio: 1 }); pin_layer_options.strategies = [ fixmystreet.bbox_strategy ]; - pin_layer_options.protocol = new OpenLayers.Protocol.HTTP({ + pin_layer_options.protocol = new OpenLayers.Protocol.FixMyStreet({ url: '/ajax', params: fixmystreet.all_pins ? { all_pins: 1 } : { }, format: new OpenLayers.Format.FixMyStreet() @@ -490,6 +490,30 @@ OpenLayers.Control.PermalinkFMSz = OpenLayers.Class(OpenLayers.Control.Permalink } }); +/* Pan data request handler */ +// This class is used to get a JSON object from /ajax that contains +// pins for the map and HTML for the sidebar. It does a fetch whenever the map +// is dragged (modulo a buffer extending outside the viewport). +// This subclass is required so we can pass the 'category' and 'status' query +// params to /ajax if the user has filtered the map. +OpenLayers.Protocol.FixMyStreet = OpenLayers.Class(OpenLayers.Protocol.HTTP, { + read: function(options) { + // Pass the values of the category and status fields as query params + var category = $("#categories").val(); + if (category !== undefined) { + options.params = options.params || {}; + options.params.category = category; + } + var status = $("#statuses").val(); + if (status !== undefined) { + options.params = options.params || {}; + options.params.status = status; + } + return OpenLayers.Protocol.HTTP.prototype.read.apply(this, [options]); + }, + CLASS_NAME: "OpenLayers.Protocol.FixMyStreet" +}); + /* Pan data handler */ OpenLayers.Format.FixMyStreet = OpenLayers.Class(OpenLayers.Format.JSON, { read: function(json, filter) { |