1 class NodeController < ApplicationController
4 before_filter :authorize
9 p.string = request.raw_post
12 doc.find('//osm/node').each do |pt|
15 node_id = pt['id'].to_i
17 if lat > 90 or lat < -90 or lon > 180 or lon < -180 or node_id != 0
18 render :nothing => true, :status => 400 # BAD REQUEST
24 pt.find('tag').each do |tag|
25 tags << [tag['k'],tag['v']]
27 tags = tags.collect { |k,v| "#{k}=#{v}" }.join(';')
28 tags = '' if tags.nil?
38 node.user_id = @user.id
40 #FIXME add a node to the old nodes table too
43 render :text => node.id
45 render :nothing => true, :status => 500
52 render :nothing => true, :status => 400 # if we got here the doc didnt parse
56 unless Node.exists?(params[:id])
57 render :nothing => true, :status => 400
61 node = Node.find(params[:id])
66 doc = XML::Document.new
68 doc.encoding = "UTF-8"
69 root = XML::Node.new 'osm'
70 root['version'] = '0.4'
71 root['generator'] = 'OpenStreetMap server'
73 el1 = XML::Node.new 'node'
74 el1['id'] = node.id.to_s
75 el1['lat'] = node.latitude.to_s
76 el1['lon'] = node.longitude.to_s
77 split_tags(el1, node.tags)
78 el1['visible'] = node.visible.to_s
79 el1['timestamp'] = node.timestamp.xmlschema
82 render :text => doc.to_s
92 render :nothing => true
94 render :nothing => true, :status => 410
103 p.string = request.raw_post
106 doc.find('//osm/node').each do |pt|
109 node_id = pt['id'].to_i
111 if lat > 90 or lat < -90 or lon > 180 or lon < -180 or node_id != params[:id]
112 render :nothing => true, :status => 400
118 pt.find('tag').each do |tag|
119 tags << [tag['k'],tag['v']]
121 tags = tags.collect { |k,v| "#{k}=#{v}" }.join(';')
122 tags = '' if tags.nil?
131 node.user_id = @user.id
133 #FIXME add a node to the old nodes table too
136 render :text => node.id
138 render :nothing => true, :status => 500
145 def split_tags(el, tags)
146 tags.split(';').each do |tag|
147 parts = tag.split('=')
150 key = parts[0].strip unless parts[0].nil?
151 val = parts[1].strip unless parts[1].nil?
152 if key != '' && val != ''
153 el2 = Node.new('tag')