1 class ApiController < ApplicationController
3 before_filter :authorize
4 after_filter :compress_output
7 response.headers["Content-Type"] = 'application/xml'
10 unless bbox and bbox.count(',') == 3
11 render :nothing => true, :status => 400
15 bbox = bbox.split(',')
17 min_lon = bbox[0].to_f
18 min_lat = bbox[1].to_f
19 max_lon = bbox[2].to_f
20 max_lat = bbox[3].to_f
23 nodes = Node.find(:all, :conditions => ['latitude > ? AND longitude > ? AND latitude < ? AND longitude < ? AND visible = 1', min_lat, min_lon, max_lat, max_lon])
25 node_ids = nodes.collect {|node| node.id }
27 if node_ids.length > 0
28 node_ids_sql = "(#{node_ids.join(',')})"
29 # get the referenced segments
30 segments = Segment.find_by_sql "select * from current_segments where visible = 1 and (node_a in #{node_ids_sql} or node_b in #{node_ids_sql})"
32 # see if we have nay missing nodes
33 segments_nodes = segments.collect {|segment| segment.node_a }
34 segments_nodes += segments.collect {|segment| segment.node_b }
38 missing_nodes = segments_nodes - node_ids
40 # get missing nodes if there are any
41 nodes += Node.find(missing_nodes) if missing_nodes.length > 0
43 doc = OSM::API.get_xml_doc
46 # find which ways are needed
47 segment_ids = segments.collect {|segment| segment.id }
49 if segment_ids.length > 0
50 way_segments = WaySegment.find_all_by_segment_id(segment_ids)
51 way_ids = way_segments.collect {|way_segment| way_segment.id }
52 ways = Way.find(way_ids) # NB: doesn't pick up segments, tags from db until accessed via way.way_segments etc.
56 doc.root << node.to_xml_node()
59 segments.each do |segment|
60 doc.root << segment.to_xml_node()
64 doc.root << way.to_xml_node()
67 render :text => doc.to_s