Skip to content

Commit

Permalink
Add an overview map showing a limited number of features that need as…
Browse files Browse the repository at this point in the history
…sessing.
  • Loading branch information
gravitystorm committed Nov 7, 2012
1 parent 4107ab3 commit 88baa18
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
19 changes: 19 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,9 +70,28 @@ def all_snippets
@crossdomain_url = root_url + "crossdomain.xml" @crossdomain_url = root_url + "crossdomain.xml"
end end


def map
if params[:bbox]
bbox = bbox_from_string(params[:bbox], ProjectWay.rgeo_factory)
ways = @project.ways.status_unchanged.intersects(bbox.to_geometry).limit(100)
nodes = @project.nodes.status_unchanged.intersects(bbox.to_geometry).limit(100)
else
ways = @project.ways.status_unchanged.limit(100)
nodes = @project.nodes.status_unchanged.limit(100)
end
entities = [nodes, ways].flatten
factory = RGeo::GeoJSON::EntityFactory.new
collection = factory.feature_collection(entities.map { | entity | entity_feature(entity) })
@geojson = RGeo::GeoJSON.encode(collection).to_json
end

private private


def load_project def load_project
@project = Project.find(params[:id]) @project = Project.find(params[:id])
end end

def entity_feature(e)
e.loc_feature({url: view_context.url_for(e)})
end
end end
17 changes: 17 additions & 0 deletions app/views/projects/map.html.haml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,17 @@
%h1= t ".unprocessed_entities"

#map
:javascript
var map = new OpenLayers.Map('map', {projection : new OpenLayers.Projection("EPSG:900913"),displayProjection : new OpenLayers.Projection("EPSG:4326")});
map.addLayer(new OpenLayers.Layer.OSM("OpenStreetMap"));
map.addLayer(new OpenLayers.Layer.OSM("OpenCycleMap", ["http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
"http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
"http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png"]));
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
vectors = new OpenLayers.Layer.Vector("Vectors", {projection : new OpenLayers.Projection("EPSG:4326"), styleMap : MapStyle.displayStyle()});
var format = new OpenLayers.Format.GeoJSON({internalProjection : new OpenLayers.Projection("EPSG:900913"),externalProjection : new OpenLayers.Projection("EPSG:4326")});
var format_plain = new OpenLayers.Format.GeoJSON();
vectors.addFeatures(format.read(#{@geojson}));
map.addLayer(vectors);
map.zoomToExtent(vectors.getDataExtent());
2 changes: 1 addition & 1 deletion config/authorization_rules.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
has_permission_on :devise_sessions, :devise_registrations, :devise_confirmations, has_permission_on :devise_sessions, :devise_registrations, :devise_confirmations,
:devise_invitations, :devise_passwords, :to => :manage :devise_invitations, :devise_passwords, :to => :manage
has_permission_on :site, :to => :index has_permission_on :site, :to => :index
has_permission_on :projects, :to => [:view, :all_snippets, :tagged_nodes, :tagged_ways, :tagged_relations] has_permission_on :projects, :to => [:view, :all_snippets, :tagged_nodes, :tagged_ways, :tagged_relations, :map]
has_permission_on :api_maps, :to => :view has_permission_on :api_maps, :to => :view
has_permission_on :api_node, :to => [:view, :status] has_permission_on :api_node, :to => [:view, :status]
has_permission_on :api_way, :to => [:view, :status] has_permission_on :api_way, :to => [:view, :status]
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
get 'tagged_nodes', :on => :member get 'tagged_nodes', :on => :member
get 'tagged_ways', :on => :member get 'tagged_ways', :on => :member
get 'tagged_relations', :on => :member get 'tagged_relations', :on => :member
get 'map', :on => :member
resources :nodes resources :nodes
resources :ways resources :ways
resources :relations resources :relations
Expand Down
14 changes: 13 additions & 1 deletion lib/entity.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def status_changed
where("status is not null and status != ?", default_status) where("status is not null and status != ?", default_status)
end end


def status_unchanged
where("status is null or status = ?", default_status)
end

def percentage_status_changed def percentage_status_changed
if self.count > 0 && self.with_tags.count > 0 if self.count > 0 && self.with_tags.count > 0
((self.with_tags.status_changed.count.to_f / self.with_tags.count) * 100).to_i ((self.with_tags.status_changed.count.to_f / self.with_tags.count) * 100).to_i
Expand All @@ -41,4 +45,12 @@ def ordered_tags
def feature_geojson def feature_geojson
RGeo::GeoJSON.encode(geom).to_json RGeo::GeoJSON.encode(geom).to_json
end end
end
def loc_feature(properties = nil)
if properties
RGeo::GeoJSON::Feature.new(self.geom, self.id, properties)
else
RGeo::GeoJSON::Feature.new(self.geom)
end
end
end

0 comments on commit 88baa18

Please sign in to comment.