X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/1c6ac719e62145e16ee3fc09d728662f9a04524d..5692b8f3418c3d5e33add3801b29a1bb280bd157:/app/controllers/amf_controller.rb diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 4a5d3346c..4b92db11c 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -14,8 +14,6 @@ class AmfController < ApplicationController # editions Systeme D / Richard Fairhurst 2004-2008 # # All in/out parameters are floats unless explicitly stated. - # Note that in getway/getway_old, SWF object name and way id are - #ĂŠidentical and one could probably be eliminated. # # to trap errors (getway_old,putway,putpoi,deleteway only): # return(-1,"message") <-- just puts up a dialogue @@ -62,8 +60,8 @@ class AmfController < ApplicationController when 'getway_old'; results[index]=putdata(index,getway_old(args)) when 'getway_history'; results[index]=putdata(index,getway_history(args)) when 'putway'; r=putway(args,renumberednodes) - renumberednodes=r[3] - results[index]=putdata(index,r) + renumberednodes=r[3] + results[index]=putdata(index,r) when 'deleteway'; results[index]=putdata(index,deleteway(args)) when 'putpoi'; results[index]=putdata(index,putpoi(args)) when 'getpoi'; results[index]=putdata(index,getpoi(args)) @@ -87,86 +85,28 @@ class AmfController < ApplicationController private + # Return presets (default tags and crap) to potlatch + # Global is set up in config/environment.rb on startup, code is in lib/osm.rb + def getpresets + return POTLATCH_PRESETS + end # ==================================================================== # Remote calls - # ----- getpresets - # in: none - # does: reads tag preset menus, colours, and autocomplete config files - # out: [0] presets, [1] presetmenus, [2] presetnames, - # [3] colours, [4] casing, [5] areas, [6] autotags - # (all hashes) - - def getpresets - RAILS_DEFAULT_LOGGER.info(" Message: getpresets") - - # Read preset menus - presets={} - presetmenus={}; presetmenus['point']=[]; presetmenus['way']=[]; presetmenus['POI']=[] - presetnames={}; presetnames['point']={}; presetnames['way']={}; presetnames['POI']={} - presettype='' - presetcategory='' - # StringIO.open(txt) do |file| - File.open("#{RAILS_ROOT}/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 - # 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 + # Find all the way ids and nodes (including tags and projected lat/lng) which aren't part of those ways in an are # # The argument is an array containing the following, in order: - # 0. minimun longitude + # 0. minimum longitude # 1. minimum latitude # 2. maximum longitude # 3. maximum latitude - # 4. baselong ?? - # 5. basey ?? - # 6. masterscale ?? + # 4. baselong, 5. basey, 6. masterscale as above + def whichways(args) xmin = args[0].to_f-0.01 ymin = args[1].to_f-0.01 @@ -178,7 +118,7 @@ class AmfController < ApplicationController RAILS_DEFAULT_LOGGER.info(" Message: whichways, bbox=#{xmin},#{ymin},#{xmax},#{ymax}") - # find the way id's in an area + # find the way ids in an area nodes_in_area = Node.find_by_area(ymin, xmin, ymax, xmax,:conditions => "visible = 1", :include => :way_nodes) waynodes_in_area = nodes_in_area.collect {|node| node.way_nodes }.flatten ways = waynodes_in_area.collect {|way_node| way_node.id[0]}.uniq @@ -198,6 +138,7 @@ class AmfController < ApplicationController # 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 @@ -207,6 +148,8 @@ class AmfController < ApplicationController basey = args[5] masterscale = args[6] + + sql=<<-EOF SELECT DISTINCT current_ways.id FROM current_nodes,way_nodes,current_ways @@ -221,21 +164,25 @@ class AmfController < ApplicationController [ways] end + + # ----- getway + # Get a way with all of it's nodes and tags # The input is an array with the following components, in order: - # 0. SWF object name (String?) - fuck knows - # 1. wayid (String?) - the ID of the way to get - # 2. baselong - fuck knows - # 3. basey - fuck knows - # 4. masterscale - fuck knows + # 0. wayid - the ID of the way to get + # 1. baselong - origin of SWF map (longitude) + # 2. basey - origin of SWF map (latitude) + # 3. masterscale - SWF map scale # - # The output is an array which contains all the nodes (with projected latitude and longitude) and tags for a way (and all the nodes tags). It also has the way's unprojected (WGS84) bbox. + # The output is an array which contains all the nodes (with projected + # latitude and longitude) and tags for a way (and all the nodes tags). + # It also has the way's unprojected (WGS84) bbox. # # FIXME: The server really shouldn't be figuring out a ways bounding box and doing projection for potlatch # FIXME: the argument splitting should be done in the 'talk' method, not here - # + def getway(args) - objname,wayid,baselong,basey,masterscale = args + wayid,baselong,basey,masterscale = args wayid = wayid.to_i RAILS_DEFAULT_LOGGER.info(" Message: getway, id=#{wayid}") @@ -252,20 +199,20 @@ class AmfController < ApplicationController id = node.id tags_hash = node.tags_as_hash - points << [projected_longitude, projected_latitude, id, nil, tags_hash] # FIXME remove the nil in potlatch. performance matters y'know! + points << [projected_longitude, projected_latitude, id, nil, tags_hash] long_array << projected_longitude lat_array << projected_latitude end - [objname,points,way.tags,long_array.min,long_array.max,lat_array.min,lat_array.max] + [wayid,points,way.tags,long_array.min,long_array.max,lat_array.min,lat_array.max] end # ----- getway_old # returns old version of way - # in: [0] SWF object name, [1] way id, - # [2] way version to get (or -1 for "last deleted version") - # [3] baselong, [4] basey, [5] masterscale + # in: [0] way id, + # [1] way version to get (or -1 for "last deleted version") + # [2] baselong, [3] basey, [4] masterscale # does: gets old version of way and all constituent nodes # for undelete, always uses the most recent version of each node # (even if it's moved) @@ -280,7 +227,7 @@ class AmfController < ApplicationController RAILS_DEFAULT_LOGGER.info(" Message: getway_old (server is #{SERVER_URL})") # if SERVER_URL=="www.openstreetmap.org" then return -1,"Revert is not currently enabled on the OpenStreetMap server." end - objname,wayid,version,baselong,basey,masterscale=args + wayid,version,baselong,basey,masterscale=args wayid = wayid.to_i version = version.to_i xmin = ymin = 999999 @@ -306,7 +253,7 @@ class AmfController < ApplicationController attrlist.each {|a| attributes[a['k'].gsub(':','|')]=a['v'] } attributes['history']="Retrieved from v"+version.to_s - [0,objname,points,attributes,xmin,xmax,ymin,ymax,version] + [0,wayid,points,attributes,xmin,xmax,ymin,ymax,version] end # ----- getway_history