- # Return presets (default tags and crap) to potlatch.
- # Uses POTLATCH_PRESETS global, set up in OSM::Potlatch
- def getpresets #:doc:
- return POTLATCH_PRESETS
- 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. minimum longitude
- # 1. minimum latitude
- # 2. maximum longitude
- # 3. maximum latitude
- # 4. baselong, 5. basey, 6. masterscale as above
- def whichways(args) #:doc:
- 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}")
-
- # 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_potlatch(baselong,masterscale), n.lat_potlatch(basey,masterscale), n.tags_as_hash] }
-
- # find the relations used by those nodes and ways
- relation_ids = Relation.find_for_nodes_and_ways(nodes_in_area.collect {|n| n.id}, way_ids).collect {|n| n.id}.uniq
-
- [way_ids,points,relation_ids]
- 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) #:doc:
- 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]
- 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. 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.
- #
- # 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) #:doc:
- wayid,baselong,basey,masterscale = args
- wayid = wayid.to_i
+ def amf_handle_error(call, rootobj, rootid)
+ yield
+ rescue OSM::APIAlreadyDeletedError => ex
+ [-4, ex.object, ex.object_id]
+ rescue OSM::APIVersionMismatchError => ex
+ [-3, [rootobj, rootid], [ex.type.downcase, ex.id, ex.latest]]
+ rescue OSM::APIUserChangesetMismatchError => ex
+ [-2, ex.to_s]
+ rescue OSM::APIBadBoundingBox => ex
+ [-2, "Sorry - I can't get the map for that area. The server said: #{ex}"]
+ rescue OSM::APIError => ex
+ [-1, ex.to_s]
+ rescue StandardError => ex
+ [-2, "An unusual error happened (in #{call}). The server said: #{ex}"]
+ end