module Api
- class MapController < ApplicationController
- skip_before_action :verify_authenticity_token
- before_action :api_deny_access_handler
-
+ class MapController < ApiController
authorize_resource :class => false
before_action :check_api_readable
return
end
- nodes = Node.bbox(bbox).where(:visible => true).includes(:node_tags).limit(MAX_NUMBER_OF_NODES + 1)
+ nodes = Node.bbox(bbox).where(:visible => true).includes(:node_tags).limit(Settings.max_number_of_nodes + 1)
node_ids = nodes.collect(&:id)
- if node_ids.length > MAX_NUMBER_OF_NODES
- report_error("You requested too many nodes (limit is #{MAX_NUMBER_OF_NODES}). Either request a smaller area, or use planet.osm")
+ if node_ids.length > Settings.max_number_of_nodes
+ report_error("You requested too many nodes (limit is #{Settings.max_number_of_nodes}). Either request a smaller area, or use planet.osm")
return
end
- doc = OSM::API.new.get_xml_doc
-
# add bounds
- doc.root << bbox.add_bounds_to(XML::Node.new("bounds"))
+ @bounds = bbox
# get ways
# find which ways are needed
nodes += Node.includes(:node_tags).find(nodes_to_fetch) unless nodes_to_fetch.empty?
visible_nodes = {}
- changeset_cache = {}
- user_display_name_cache = {}
-
+ @nodes = []
nodes.each do |node|
if node.visible?
- doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
visible_nodes[node.id] = node
+ @nodes << node
end
end
+ @ways = []
way_ids = []
ways.each do |way|
if way.visible?
- doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
way_ids << way.id
+ @ways << way
end
end
# this "uniq" may be slightly inefficient; it may be better to first collect and output
# all node-related relations, then find the *not yet covered* way-related ones etc.
+ @relations = []
relations.uniq.each do |relation|
- doc.root << relation.to_xml_node(changeset_cache, user_display_name_cache)
+ @relations << relation
end
response.headers["Content-Disposition"] = "attachment; filename=\"map.osm\""
-
- render :xml => doc.to_s
+ # Render the result
+ respond_to do |format|
+ format.xml
+ end
end
end
end