Class: Gmaps4rails::MarkersBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gmaps4rails/markers_builder.rb

Overview

the to_gmaps4rails method accepts a block to customize:

  • infowindow

  • picture

  • shadow

  • title

  • sidebar

  • json

This works this way:

@users = User.all
@json  = Gmaps4rails.build_markers @users do |user, marker|
  marker.lat user.latitude
  marker.lng user.longitude
  marker.infowindow render_to_string(:partial => "/users/my_template", :locals => { :object => user}).gsub(/\n/, '').gsub(/"/, '\"')
  marker.picture({
                  :url    => "http://www.blankdots.com/img/github-32x32.png",
                  :width  => "32",
                  :height => "32"
                 })
  marker.title   "i'm the title"
  marker.json({ :id => user.id })
end

Defined Under Namespace

Classes: MarkerBuilder

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ MarkersBuilder

Returns a new instance of MarkersBuilder.



26
27
28
# File 'lib/gmaps4rails/markers_builder.rb', line 26

def initialize(collection)
  @collection = Array(collection)
end

Instance Method Details

#call(&block) ⇒ Object



30
31
32
33
34
# File 'lib/gmaps4rails/markers_builder.rb', line 30

def call(&block)
  @collection.map do |object|
    MarkerBuilder.new(object).call(&block)
  end
end