-
- # Read colours/styling
- colours={}; casing={}; areas={}
- File.open("#{RAILS_ROOT}/config/potlatch/colours.txt") do |file|
- file.each_line {|line|
- t=line.chomp
- if (t=~/(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/) then
- tag=$1
- if ($2!='-') then colours[tag]=$2.hex end
- if ($3!='-') then casing[tag]=$3.hex end
- if ($4!='-') then areas[tag]=$4.hex end
- end
- }
- end
-
- # Read auto-complete
- autotags={}; autotags['point']={}; autotags['way']={}; autotags['POI']={};
- File.open("#{RAILS_ROOT}/config/potlatch/autocomplete.txt") do |file|
- file.each_line {|line|
- t=line.chomp
- if (t=~/^(\w+)\/(\w+)\s+(.+)$/) then
- tag=$1; type=$2; values=$3
- if values=='-' then autotags[type][tag]=[]
- else autotags[type][tag]=values.split(',').sort.reverse end
- end
- }
- end
-
- [presets,presetmenus,presetnames,colours,casing,areas,autotags]
- end
-
- # ----- whichways
- # return array of ways in current bounding box
-
- # in: [0] xmin, [1] ymin, [2] xmax, [3] ymax (bbox in degrees)
- # [4] baselong (longitude of SWF map origin),
- # [5] basey (projected latitude of SWF map origin),
- # [6] masterscale (SWF map scale)
- # does: finds all ways and POI nodes in bounding box
- # at present, instead of using correct (=more complex) SQL to find
- # corner-crossing ways, it simply enlarges the bounding box
- # out: [0] array of way ids,
- # [1] array of POIs
- # (where each POI is an array containing:
- # [0] id, [1] projected long, [2] projected lat, [3] hash of tags)
-
- def whichways(args)
- xmin = args[0].to_f-0.01
- ymin = args[1].to_f-0.01
- xmax = args[2].to_f+0.01
- ymax = args[3].to_f+0.01
- baselong = args[4]
- basey = args[5]
- masterscale = args[6]
-
- RAILS_DEFAULT_LOGGER.info(" Message: whichways, bbox=#{xmin},#{ymin},#{xmax},#{ymax}")
-
- waylist = ActiveRecord::Base.connection.select_all("SELECT DISTINCT current_way_nodes.id AS wayid"+
- " FROM current_way_nodes,current_nodes,current_ways "+
- " WHERE current_nodes.id=current_way_nodes.node_id "+
- " AND current_nodes.visible=1 "+
- " AND current_ways.id=current_way_nodes.id "+
- " AND current_ways.visible=1 "+
- " AND "+OSM.sql_for_area(ymin, xmin, ymax, xmax, "current_nodes."))
-
- ways = waylist.collect {|a| a['wayid'].to_i } # get an array of way IDs
-
- pointlist = ActiveRecord::Base.connection.select_all("SELECT current_nodes.id,current_nodes.latitude*0.0000001 AS lat,current_nodes.longitude*0.0000001 AS lng,current_nodes.tags "+
- " FROM current_nodes "+
- " LEFT OUTER JOIN current_way_nodes cwn ON cwn.node_id=current_nodes.id "+
- " WHERE "+OSM.sql_for_area(ymin, xmin, ymax, xmax, "current_nodes.")+
- " AND cwn.id IS NULL "+
- " AND current_nodes.visible=1")
-
- points = pointlist.collect {|a| [a['id'],long2coord(a['lng'].to_f,baselong,masterscale),lat2coord(a['lat'].to_f,basey,masterscale),tag2array(a['tags'])] } # get a list of node ids and their tags
-
- [ways,points]
- end
-
- # ----- whichways_deleted
- # return array of deleted ways in current bounding box
-
- # in: as whichways
- # does: finds all deleted ways with a deleted node in bounding box
- # out: [0] array of way ids
-
- def whichways_deleted(args)
- xmin = args[0].to_f-0.01
- ymin = args[1].to_f-0.01
- xmax = args[2].to_f+0.01
- ymax = args[3].to_f+0.01
- baselong = args[4]
- basey = args[5]
- masterscale = args[6]
-
- sql=<<-EOF
- SELECT DISTINCT current_ways.id
- FROM current_nodes,way_nodes,current_ways
- WHERE #{OSM.sql_for_area(ymin, xmin, ymax, xmax, "current_nodes.")}
- AND way_nodes.node_id=current_nodes.id
- AND way_nodes.id=current_ways.id
- AND current_nodes.visible=0
- AND current_ways.visible=0
- EOF
- waylist = ActiveRecord::Base.connection.select_all(sql)
- ways = waylist.collect {|a| a['id'].to_i }
- [ways]