- # ====================================================================
- # Remote calls
-
- def getpresets
- presets={}
- presetmenus={}; presetmenus['point']=[]; presetmenus['way']=[]
- presetnames={}; presetnames['point']={}; presetnames['way']={}
- presettype=''
- presetcategory=''
-
- File.open("config/potlatch/presets.txt") do |file|
- file.each_line {|line|
- t=line.chomp
- if (t=~/(\w+)\/(\w+)/) then
- presettype=$1
- presetcategory=$2
- presetmenus[presettype].push(presetcategory)
- presetnames[presettype][presetcategory]=["(no preset)"]
- elsif (t=~/^(.+):\s?(.+)$/) then
- pre=$1; kv=$2
- presetnames[presettype][presetcategory].push(pre)
- presets[pre]={}
- kv.split(',').each {|a|
- if (a=~/^(.+)=(.*)$/) then presets[pre][$1]=$2 end
- }
- end
- }
- end
- [presets,presetmenus,presetnames]
+ # Return presets (default tags, localisation etc.):
+ # uses POTLATCH_PRESETS global, set up in OSM::Potlatch.
+
+ def getpresets() #:doc:
+ return POTLATCH_PRESETS
+ end
+
+ # Find all the ways, POI nodes (i.e. not part of ways), and relations
+ # in a given bounding box. Nodes are returned in full; ways and relations
+ # are IDs only.
+
+ def whichways(xmin, ymin, xmax, ymax) #:doc:
+ enlarge = [(xmax-xmin)/8,0.01].min
+ xmin -= enlarge; ymin -= enlarge
+ xmax += enlarge; ymax += enlarge
+
+ if POTLATCH_USE_SQL then
+ way_ids = sql_find_way_ids_in_area(xmin, ymin, xmax, ymax)
+ points = sql_find_pois_in_area(xmin, ymin, xmax, ymax)
+ relation_ids = sql_find_relations_in_area_and_ways(xmin, ymin, xmax, ymax, way_ids)
+ else
+ # find the way ids in an area
+ nodes_in_area = Node.find_by_area(ymin, xmin, ymax, xmax, :conditions => "current_nodes.visible = 1", :include => :ways)
+ way_ids = nodes_in_area.collect { |node| node.way_ids }.flatten.uniq
+
+ # find the node ids in an area that aren't part of ways
+ nodes_not_used_in_area = nodes_in_area.select { |node| node.ways.empty? }
+ points = nodes_not_used_in_area.collect { |n| [n.id, n.lon, n.lat, n.tags_as_hash] }
+
+ # find the relations used by those nodes and ways
+ relations = Relation.find_for_nodes(nodes_in_area.collect { |n| n.id }, :conditions => "visible = 1") +
+ Relation.find_for_ways(way_ids, :conditions => "visible = 1")
+ relation_ids = relations.collect { |relation| relation.id }.uniq