Module: Ropenlayer::ActsAs::Mapper
- Defined in:
- lib/ropenlayer/acts_as/mapper.rb
Overview
acts_as_map: give to the model map construiction and build facilities.
class Team < ActiveRecord::Base
acts_as_map :default_layer => :google_streets
end
Avalaible options:
- :longitude, :latitude, :zoom : Default starting values for map. Can be a float (latitude, longitude) or integer (zoom) object, so values will be parsed as them are.
A Symbol, in this case, ropenlayer will send :symbol method to mapper instance, or a valid Proc object
- :default_layer: Default layer for visualization. For avalaible layers see Ropenlayer::Openlayer::Map
- :nodes: Relations which can be pointed on the map. Relations are expected to have acts_as_localizable_on behaviour in their class
Examples
Build a Map with static features, just for localization
class Team < ActiveRecord::Base
acts_as_map :default_layer => :google_streets, :latitude => 40000.23, :longitude => 54555.233, :zoom => 3
end
Build a Map with Proc calls to perform automatic localization on forms
class Team < ActiveRecord
has_many :offices
has_one :main_office, :conditions => { :main => true }
acts_as_map :default_layer => :google_streets, :longitude => :main_office_longitude, :latitude => :main_office_latitude, :zoom => :main_office_zoom
:nodes => [ :offices ]
def main_office_longitude
main_office.longitude
end
def main_office_longitude=(value)
main_office_longitude = value
end
def main_office_latitude
main_office.latitude
end
def main_office_latitude=(value)
main_office.latitude = value
end
def main_office_longitude
main_office.longitude
end
def main_office_zoom=(value)
main_office.zoom = value
end
end
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ropenlayer/acts_as/mapper.rb', line 64 def included(base) base.class_eval do base.send :include, InstanceMethods localizable = [:longitude, :latitude, :zoom ].inject(true) do |all_positions, position| all_positions = false unless self.ropenlayer_mapper_config[position].is_a?(Symbol) and self.attribute_method?(self.ropenlayer_mapper_config[position]) all_positions end send("class_variable_set", "@@localizable", true) if localizable end end |