# 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.uniq.each do |relation|
- doc.root << relation.to_xml_node(nil, changeset_cache, user_display_name_cache)
+ doc.root << relation.to_xml_node(changeset_cache, user_display_name_cache)
end
response.headers["Content-Disposition"] = "attachment; filename=\"map.osm\""
# create XML.
doc = OSM::API.new.get_xml_doc
visible_nodes = {}
- visible_members = { "Node" => {}, "Way" => {}, "Relation" => {} }
changeset_cache = {}
user_display_name_cache = {}
doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
visible_nodes[node.id] = node
- visible_members["Node"][node.id] = true
end
ways.each do |way|
next unless way.visible? # should be unnecessary if data is consistent.
doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
- visible_members["Way"][way.id] = true
end
relations.each do |rel|
next unless rel.visible? # should be unnecessary if data is consistent.
- doc.root << rel.to_xml_node(nil, changeset_cache, user_display_name_cache)
- visible_members["Relation"][rel.id] = true
+ doc.root << rel.to_xml_node(changeset_cache, user_display_name_cache)
end
# finally add self and output
- doc.root << relation.to_xml_node(visible_members, changeset_cache, user_display_name_cache)
+ doc.root << relation.to_xml_node(changeset_cache, user_display_name_cache)
render :xml => doc.to_s
else
end
relations.each do |rel|
- doc.root << rel.to_xml_node(nil, changeset_cache, user_display_name_cache)
+ doc.root << rel.to_xml_node(changeset_cache, user_display_name_cache)
end
render :xml => doc.to_s
doc
end
- def to_xml_node(visible_members = nil, changeset_cache = {}, user_display_name_cache = {})
+ def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
el = XML::Node.new "relation"
el["id"] = id.to_s
add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
relation_members.each do |member|
- p = 0
-
- if visible_members
- # if there is a list of visible members then use that to weed out deleted segments
- p = 1 if visible_members[member.member_type][member.member_id]
- else
- # otherwise, manually go to the db to check things
- p = 1 if member.member.visible?
- end
-
- next unless p
-
member_el = XML::Node.new "member"
member_el["type"] = member.member_type.downcase
member_el["ref"] = member.member_id.to_s