X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/cfbdd3f7e1c688e2c875ded9fd847fcc1c3a4caf..bee38e63a3cf9083d5bf38e8bbfbac62f9a6a9d1:/app/controllers/api_controller.rb diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 6e8e77c2f..28d0f413b 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -1,6 +1,7 @@ class ApiController < ApplicationController session :off + before_filter :check_read_availability, :except => [:capabilities] after_filter :compress_output #COUNT is the number of map requests to allow before exiting and starting a new process @@ -137,7 +138,7 @@ class ApiController < ApplicationController end # get all the nodes - nodes = Node.find(:all, :conditions => ['latitude BETWEEN ? AND ? AND longitude BETWEEN ? AND ? AND visible = 1', min_lat, max_lat, min_lon, max_lon]) + nodes = Node.find_by_area(min_lat, min_lon, max_lat, max_lon, :conditions => "visible = 1") node_ids = nodes.collect {|node| node.id } @@ -160,7 +161,7 @@ class ApiController < ApplicationController ways = Array.new if node_ids.length > 0 way_nodes = WayNode.find_all_by_node_id(node_ids) - way_ids = way_nodes.collect {|way_node| way_node.id } + way_ids = way_nodes.collect {|way_node| way_node.id[0] } ways = Way.find(way_ids) list_of_way_nodes = ways.collect { |way| @@ -200,12 +201,17 @@ class ApiController < ApplicationController # collect relationships. currently done in one big block at the end; # may need to move this upwards if people want automatic completion of # relationships, i.e. deliver referenced objects like we do with ways... - relations = Relation.find_by_sql("select e.* from current_relations e,current_relation_members em where " + - "e.visible=1 and " + - "em.id = e.id and em.member_type='node' and em.member_id in (#{visible_nodes.keys.join(',')})") - relations += Relation.find_by_sql("select e.* from current_relations e,current_relation_members em where " + - "e.visible=1 and " + - "em.id = e.id and em.member_type='way' and em.member_id in (#{way_ids.join(',')})") + relations = Array.new + if visible_nodes.length > 0 + relations += Relation.find_by_sql("select e.* from current_relations e,current_relation_members em where " + + "e.visible=1 and " + + "em.id = e.id and em.member_type='node' and em.member_id in (#{visible_nodes.keys.join(',')})") + end + if way_ids.length > 0 + relations += Relation.find_by_sql("select e.* from current_relations e,current_relation_members em where " + + "e.visible=1 and " + + "em.id = e.id and em.member_type='way' and em.member_id in (#{way_ids.join(',')})") + end # we do not normally return the "other" partners referenced by an relation, # e.g. if we return a way A that is referenced by relation X, and there's # another way B also referenced, that is not returned. But we do make @@ -234,6 +240,51 @@ class ApiController < ApplicationController end end + def changes + zoom = (params[:zoom] || '12').to_i + + if params.include?(:start) and params.include?(:end) + starttime = Time.parse(params[:start]) + endtime = Time.parse(params[:end]) + else + hours = (params[:hours] || '1').to_i.hours + endtime = Time.now + starttime = endtime - hours + end + + if zoom >= 1 and zoom <= 16 and + endtime >= starttime and endtime - starttime <= 24.hours + mask = (1 << zoom) - 1 + + tiles = Node.count(:conditions => ["timestamp BETWEEN ? AND ?", starttime, endtime], + :group => "maptile_for_point(latitude, longitude, #{zoom})") + + doc = OSM::API.new.get_xml_doc + changes = XML::Node.new 'changes' + changes["starttime"] = starttime.xmlschema + changes["endtime"] = endtime.xmlschema + + tiles.each do |tile, count| + x = (tile.to_i >> zoom) & mask + y = tile.to_i & mask + + t = XML::Node.new 'tile' + t["x"] = x.to_s + t["y"] = y.to_s + t["z"] = zoom.to_s + t["changes"] = count.to_s + + changes << t + end + + doc.root << changes + + render :text => doc.to_s, :content_type => "text/xml" + else + render :nothing => true, :status => :bad_request + end + end + def capabilities doc = OSM::API.new.get_xml_doc