ids = params['segments'].split(',').collect {|s| s.to_i }
if ids.length > 0
segmentlist = Segment.find(ids)
- doc = OSM::API.get_xml_doc
+ doc = OSM::API.new.get_xml_doc
+ segmentlist.each do |segment|
+ doc.root << segment.to_xml_node
+ end
+ render :text => doc.to_s
+ else
+ render :nothing => true, :status => 400
+ end
+ end
+
+ def segments_for_node
+ response.headers["Content-Type"] = 'text/xml'
+ segmentids = Segment.find(:all, :conditions => ['node_a = ? OR node_b = ?', params[:id], params[:id]]).collect { |s| s.id }.uniq
+ if segmentids.length > 0
+ segmentlist = Segment.find(segmentids)
+ doc = OSM::API.new.get_xml_doc
segmentlist.each do |segment|
doc.root << segment.to_xml_node
end
end
end
+ def ways_for_segment
+ response.headers["Content-Type"] = 'text/xml'
+ wayids = WaySegment.find(:all, :conditions => ['segment_id = ?', params[:id]]).collect { |ws| ws.id }.uniq
+ if wayids.length > 0
+ waylist = Way.find(wayids)
+ doc = OSM::API.new.get_xml_doc
+ waylist.each do |way|
+ doc.root << way.to_xml_node
+ end
+ render :text => doc.to_s
+ else
+ render :nothing => true, :status => 400
+ end
+ end
+
end
# API
map.connect "api/#{API_VERSION}/node/create", :controller => 'node', :action => 'create'
+ map.connect "api/#{API_VERSION}/node/:id/segments", :controller => 'segment', :action => 'segments_for_node'
map.connect "api/#{API_VERSION}/node/:id/history", :controller => 'old_node', :action => 'history', :id => nil
map.connect "api/#{API_VERSION}/node/:id", :controller => 'node', :action => 'rest', :id => nil
map.connect "api/#{API_VERSION}/nodes", :controller => 'node', :action => 'nodes', :id => nil
map.connect "api/#{API_VERSION}/segment/create", :controller => 'segment', :action => 'create'
+ map.connect "api/#{API_VERSION}/segment/:id/ways", :controller => 'way', :action => 'ways_for_segment'
map.connect "api/#{API_VERSION}/segment/:id/history", :controller => 'old_segment', :action => 'history'
map.connect "api/#{API_VERSION}/segment/:id", :controller => 'segment', :action => 'rest'
map.connect "api/#{API_VERSION}/segments", :controller => 'segment', :action => 'segments', :id => nil