X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/df31fe13a535a9b36206c035a48f1e4cdec913f4..755b9711b520feea5bb7ca5f5130f18dc3fc5e00:/app/models/node.rb diff --git a/app/models/node.rb b/app/models/node.rb index f9210bf06..59aa4d36f 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -1,5 +1,6 @@ -class Node < ActiveRecord::Base +class Node < GeoRecord require 'xml/libxml' + set_table_name 'current_nodes' validates_presence_of :user_id, :timestamp @@ -10,34 +11,6 @@ class Node < ActiveRecord::Base has_many :old_nodes, :foreign_key => :id belongs_to :user - before_save :update_tile - - def self.find_by_area(minlat, minlon, maxlat, maxlon, options) - self.with_scope(:find => {:conditions => OSM.sql_for_area(minlat, minlon, maxlat, maxlon)}) do - return self.find(:all, options) - end - end - - def update_tile - self.tile = QuadTile.tile_for_point(lat, lon) - end - - def lat=(l) - self.latitude = (l * 10000000).round - end - - def lon=(l) - self.longitude = (l * 10000000).round - end - - def lat - return self.latitude.to_f / 10000000 - end - - def lon - return self.longitude.to_f / 10000000 - end - def validate_position errors.add_to_base("Node is not in the world") unless in_world? end @@ -84,10 +57,7 @@ class Node < ActiveRecord::Base tags << [tag['k'],tag['v']] end - tags = tags.collect { |k,v| "#{k}=#{v}" }.join(';') - tags = '' if tags.nil? - - node.tags = tags + node.tags = Tags.join(tags) end rescue node = nil @@ -129,25 +99,15 @@ class Node < ActiveRecord::Base el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil? - Node.split_tags(el1, self.tags) + Tags.split(self.tags) do |k,v| + el2 = XML::Node.new('tag') + el2['k'] = k.to_s + el2['v'] = v.to_s + el1 << el2 + end + el1['visible'] = self.visible.to_s el1['timestamp'] = self.timestamp.xmlschema return el1 end - - def self.split_tags(el, tags) - tags.split(';').each do |tag| - parts = tag.split('=') - key = '' - val = '' - key = parts[0].strip unless parts[0].nil? - val = parts[1].strip unless parts[1].nil? - if key != '' && val != '' - el2 = XML::Node.new('tag') - el2['k'] = key.to_s - el2['v'] = val.to_s - el << el2 - end - end - end end