Permalink
Browse files

Merge branch 'staging'

  • Loading branch information...
2 parents b38a12b + b771840 commit da10b24986e04455fca4a994ec6193c56390c117 @gravitystorm gravitystorm committed Mar 23, 2012
Showing with 37 additions and 3 deletions.
  1. +2 −2 app/controllers/issues_controller.rb
  2. +1 −1 app/helpers/maps_helper.rb
  3. +5 −0 lib/locatable/locatable.rb
  4. +29 −0 spec/models/issue_spec.rb
@@ -33,7 +33,7 @@ def create
NewIssueNotifier.new_issue(@issue)
redirect_to @issue
else
- @start_location = index_start_location
+ @start_location = current_user.start_location
render :new
end
end
@@ -76,7 +76,7 @@ def geometry
def all_geometries
if params[:bbox]
bbox = bbox_from_string(params[:bbox], Issue.rgeo_factory)
- issues = Issue.intersects(bbox.to_geometry).order("created_at DESC").limit(50)
+ issues = Issue.intersects_not_covered(bbox.to_geometry).order("created_at DESC").limit(50)
else
issues = Issue.order("created_at DESC").limit(50)
end
@@ -43,7 +43,7 @@ def tiny_display_map(object, geometry_url, prefix, &block)
def display_bbox_map(start_location, geometry_bbox_url, &block)
map = basic_map do |map, page|
centre_map(start_location, map, page)
- add_location_layer("Issues", geometry_bbox_url, OpenLayers::Strategy::BBOX.new(), map, page)
+ add_location_layer("Issues", geometry_bbox_url, OpenLayers::Strategy::BBOX.new(resFactor: 3, ratio: 1.5), map, page)
page << 'MapPopup.init(map, locationlayer)'
yield(map, page) if block_given?
@@ -12,6 +12,11 @@ def intersects(l)
where("st_intersects(location, ?)", [l])
end
+ # define a variant of intersects that doesn't include entirely surrouding polygons
+ def intersects_not_covered(l)
+ intersects(l).where("not st_coveredby(?, location)", [l])
+ end
+
# This could be improved by actually using the factory from the location column, rather
# than creating a new one and hardcoding the srid.
# However, there's a bug in Rgeo::ActiveRecord 0.4.0 that prevents rgeo_factory_for_column from working
@@ -140,6 +140,35 @@
lambda { Issue.intersects(geom2).all }.should_not raise_error
end
end
+
+ context "different issue locations" do
+ let(:factory) { RGeo::Geos::Factory.new(srid: 4326) }
+ let(:polygon) { 'POLYGON ((1 1, 1 2, 2 2, 2 1, 1 1))' }
+ let!(:issue_entirely_surrounding) { FactoryGirl.create(:issue, location: 'POLYGON ((0 0, 0 3, 3 3, 3 0, 0 0))') }
+ let!(:issue_entirely_contained) { FactoryGirl.create(:issue, location: 'POLYGON ((1.2 1.2, 1.2 1.8, 1.8 1.8, 1.8 1.2, 1.2 1.2))') }
+ let!(:issue_not_intersecting) { FactoryGirl.create(:issue, location: 'POLYGON ((10 10, 10 20, 20 20, 20 10, 10 10))' ) }
+ let!(:issue_half_in_half_out) { FactoryGirl.create(:issue, location: 'POLYGON ((0 1.2, 0 1.8, 3 1.8, 3 1.2, 0 1.2))' ) }
+
+ it "should return intersecting issues" do
+ bbox = factory.parse_wkt(polygon)
+ issues = Issue.intersects(bbox).all
+ issues.length.should eql(3)
+ issues.should include(issue_entirely_surrounding)
+ issues.should include(issue_entirely_contained)
+ issues.should include(issue_half_in_half_out)
+ issues.should_not include(issue_not_intersecting)
+ end
+
+ it "should return intersecting but not covering issues" do
+ bbox = factory.parse_wkt(polygon)
+ issues = Issue.intersects_not_covered(bbox).all
+ issues.length.should eql(2)
+ issues.should include(issue_entirely_contained)
+ issues.should include(issue_half_in_half_out)
+ issues.should_not include(issue_entirely_surrounding)
+ issues.should_not include(issue_not_intersecting)
+ end
+ end
end
describe "find with index (search)" do

0 comments on commit da10b24

Please sign in to comment.