# create XML.
doc = OSM::API.new.get_xml_doc
visible_nodes = {}
- visible_members = { "Node" => {}, "Way" => {}, "Relation" => {} }
changeset_cache = {}
user_display_name_cache = {}
-
+
nodes.each do |node|
- if node.visible? # should be unnecessary if data is consistent.
- doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
- visible_nodes[node.id] = node
- end
+ next unless node.visible? # should be unnecessary if data is consistent.
+
+ 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|
- if way.visible? # should be unnecessary if data is consistent.
- doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
- end
+ 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|
- if rel.visible? # should be unnecessary if data is consistent.
- doc.root << rel.to_xml_node(changeset_cache, user_display_name_cache)
- end
+ 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 :text => doc.to_s, :content_type => "text/xml"
-
+ render :xml => doc.to_s
+
else
- render :nothing => true, :status => :gone
+ head :gone
end
end
def to_xml
doc = OSM::API.new.get_xml_doc
- doc.root << to_xml_node()
- return doc
+ doc.root << to_xml_node
+ 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 = {})
- el1 = XML::Node.new 'relation'
- el1['id'] = self.id.to_s
- el1['visible'] = self.visible.to_s
- el1['timestamp'] = self.timestamp.xmlschema
- el1['version'] = self.version.to_s
- el1['changeset'] = self.changeset_id.to_s
-
- if changeset_cache.key?(self.changeset_id)
- # use the cache if available
- else
- changeset_cache[self.changeset_id] = self.changeset.user_id
- end
-
- user_id = changeset_cache[self.changeset_id]
+ el = XML::Node.new "relation"
+ el["id"] = id.to_s
- if user_display_name_cache.key?(user_id)
- # use the cache if available
- elsif self.changeset.user.data_public?
- user_display_name_cache[user_id] = self.changeset.user.display_name
- else
- user_display_name_cache[user_id] = nil
- end
+ add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
- if not user_display_name_cache[user_id].nil?
- el1['user'] = user_display_name_cache[user_id]
- el1['uid'] = user_id.to_s
+ 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
+ member_el["role"] = member.member_role
+ el << member_el
end
- self.relation_members.each do |member|
- e = XML::Node.new 'member'
- e['type'] = member.member_type.downcase
- e['ref'] = member.member_id.to_s
- e['role'] = member.member_role
- el1 << e
- end
+ add_tags_to_xml_node(el, relation_tags)
- self.relation_tags.each do |tag|
- e = XML::Node.new 'tag'
- e['k'] = tag.k
- e['v'] = tag.v
- el1 << e
- end
- return el1
- end
+ el
+ end
- # FIXME is this really needed?
+ # FIXME: is this really needed?
def members
- @members ||= self.relation_members.map do |member|
+ @members ||= relation_members.map do |member|
[member.member_type, member.member_id, member.member_role]
end
end