Module: Ropenlayer::ActsAs::Nodeable

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

Overview

acts_as_localizable_on: give to the model facilities to store and draw object in a map.

class Team < ActiveRecord::Base
  acts_as_map :default_layer => :google_streets, :nodes => [ :offices ]
end

class Office < ActiveRecord::Base
  belongs_to :team
  acts_as_localizable_on :team
end

Avalaible options:

All the options can be mapped to a Proc object that will bind self or a Symbol which perform send(:symbol) method.
- :name, :Name of the point. By default, Just another Element
- :popup_content:Content of the popup, if set, element will render a popup in click with this xhtml content. by default, is false 
- :icon_url: Icon url to show, by default, /images/ropenlayer/default_marker.png
- :color: Background color, by default transparent

Examples

Build a Map of the team offices with custom icons

 # on app/models/team.rb
 class Team < ActiveRecord::Base
   has_many :offices
   acts_as_map :default_layer => :google_streets, :latitude => 40000.23, :longitude => 54555.233, :zoom => 3
               :nodes => [ :offices ]
 end

 # on app/models/office.rb
 class Office < ActiveRecord::Base
   belongs_to :team
   acts_as_localizable_on :team, :icon_url      => Proc.new{|o| o.main ? '/images/main_office.png' : '/images/office.png' },
                                 :color         => Proc.new{|o| o.main ? 'red' : 'blue' },
                                 :popup_content => :full_description

   def full_description
     %( #{ name } - #{ address } )
   end
end

on your view, just

apps/views/offices/index.html

<div id="offices_for_team_map" style="width: 500px; height: 400px;"></div>
<%= raw @team.ropenlayer_map(:id => 'offices_for_team_map').to_js %>

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ropenlayer/acts_as/nodeable.rb', line 56

def included(base)
   
   base.class_eval do 
     
     has_one :node,      :as => :nodeable, :dependent => :destroy, :include => :localizations, :class_name => "Ropenlayer::Node"
     accepts_nested_attributes_for :node
 
     base.send :include, InstanceMethods
     
   end
end