Module: Ropenlayer::ActsAs::Nodeable::InstanceMethods

Defined in:
lib/ropenlayer/acts_as/nodeable.rb

Instance Method Summary collapse

Instance Method Details

#ensure_nodeable_modelObject



91
92
93
# File 'lib/ropenlayer/acts_as/nodeable.rb', line 91

def ensure_nodeable_model
  raise "Model `#{ self.class }` doesnt acts as nodeable" unless self.class.methods.include?("acts_as_nodeable") and self.class.acts_as_nodeable
end

#node_dataObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ropenlayer/acts_as/nodeable.rb', line 70

def node_data
  attributes_config = self.class.ropenlayer_node_config[:attributes] || {}
  #[ :name, :popup_content, :icon_url, :color ].each do |attribute|
  node_map_attributes = Ropenlayer::Openlayer::Feature.all_attributes.inject({}) do |hash, attribute|

    hash[attribute] = eval_node_attribute(attributes_config[attribute]) unless attributes_config[attribute].nil?
    hash
  end
  
  if self.node.localizations.any?
    node_map_attributes[:id]            = self.node.id
    node_map_attributes[:geometry]      = self.node.geometry
    node_map_attributes[:longitude]     = self.node.localizations.first.longitude
    node_map_attributes[:latitude]      = self.node.localizations.first.latitude
    node_map_attributes[:localizations] = self.node.localizations.map{|l| { :latitude => l.latitude, :longitude => l.longitude }}
  else
    node_map_attributes = nil
  end
  node_map_attributes
end