Class: BHM::GoogleMaps::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/bhm/google_maps/builder.rb

Defined Under Namespace

Classes: BasicMarker

Instance Method Summary collapse

Constructor Details

#initialize(template, address, options) ⇒ Builder

Returns a new instance of Builder.



6
7
8
9
10
# File 'lib/bhm/google_maps/builder.rb', line 6

def initialize(template, address, options)
  @template = template
  @address  = address
  @options  = options.symbolize_keys
end

Instance Method Details

#address_as_stringObject



44
45
46
# File 'lib/bhm/google_maps/builder.rb', line 44

def address_as_string
  BHM::GoogleMaps.address_to_s_proc.call(@address)
end

#build_containerObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bhm/google_maps/builder.rb', line 20

def build_container
  marker_options = @options[:marker] || {}
  ll = self.ll_pair
  address = self.address_as_string
  container_options = {}
  container_options['data-latitude'] = ll[0]
  container_options['data-longitude'] = ll[1]
  marker_options[:title] ||= address
  marker_options.each_pair do |k, v|
    container_options["data-marker-#{k.to_s.dasherize}"] = v
  end
  default_css_class = "#{BHM::GoogleMaps.container_class} #{BHM::GoogleMaps.static_map_class}"
  container_options = merge_options_with_class(container_options, :class => default_css_class)
  @template.(:div, build_static_map(marker_options), container_options)
end

#build_static_map(marker_options) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/bhm/google_maps/builder.rb', line 12

def build_static_map(marker_options)
  ll             = self.ll_pair
  address        = self.address_as_string
  address_proxy  = BasicMarker.new(address, ll[0], ll[1])
  static_map_url = StaticMap.for_address(address_proxy, marker_options.merge(@options[:static_map] || {}))
  @template.image_tag(static_map_url, {:alt => address}.reverse_merge(@options[:static_map_html] || {}))
end

#ll_pairObject



40
41
42
# File 'lib/bhm/google_maps/builder.rb', line 40

def ll_pair
  BHM::GoogleMaps.address_to_lat_lng_proc.call(@address)
end

#to_htmlObject



36
37
38
# File 'lib/bhm/google_maps/builder.rb', line 36

def to_html
  @to_html ||= build_container
end