Class: GoogleMap::Icon

Inherits:
Object
  • Object
show all
Defined in:
lib/google_map/icon.rb

Direct Known Subclasses

LetterIcon, SmallIcon

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Icon

Returns a new instance of Icon.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/google_map/icon.rb', line 20

def initialize(options = {})
  self.image_url       = 'http://www.google.com/mapfiles/marker.png'
  self.shadow_url      = 'http://www.google.com/mapfiles/shadow50.png'
  self.width           = 20
  self.height          = 34
  self.shadow_width    = 37
  self.shadow_height   = 34
  self.anchor_x        = 6
  self.anchor_y        = 20
  self.info_anchor_x   = 5
  self.info_anchor_y   = 1
  options.each_pair { |key, value| send("#{key}=", value) }
  
  if !map or !map.kind_of?(GoogleMap::Map)
    raise "Must set map for GoogleMap::Icon."
  end
  if dom_id.blank?
    self.dom_id = "#{map.dom_id}_icon_#{map.markers.size + 1}"
  end
  
end

Instance Attribute Details

#anchor_xObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def anchor_x
  @anchor_x
end

#anchor_yObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def anchor_y
  @anchor_y
end

#dom_idObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def dom_id
  @dom_id
end

#heightObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def height
  @height
end

#image_urlObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def image_url
  @image_url
end

#info_anchor_xObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def info_anchor_x
  @info_anchor_x
end

#info_anchor_yObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def info_anchor_y
  @info_anchor_y
end

#mapObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def map
  @map
end

#shadow_heightObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def shadow_height
  @shadow_height
end

#shadow_urlObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def shadow_url
  @shadow_url
end

#shadow_widthObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def shadow_width
  @shadow_width
end

#widthObject

include Reloadable include UnbackedDomId



7
8
9
# File 'lib/google_map/icon.rb', line 7

def width
  @width
end

Instance Method Details

#to_htmlObject



54
55
56
57
58
59
60
# File 'lib/google_map/icon.rb', line 54

def to_html
  html = []
  html << "<script type=\"text/javascript\">\n/* <![CDATA[ */\n"  
  html << to_js
  html << "/* ]]> */</script> "
  return html.join("\n")
end

#to_jsObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/google_map/icon.rb', line 42

def to_js
  js = []
  js << "var #{dom_id} = new GIcon();"
  js << "#{dom_id}.image = \"#{image_url}\";"
  js << "#{dom_id}.shadow = \"#{shadow_url}\";"
  js << "#{dom_id}.iconSize = new GSize(#{width}, #{height});"
  js << "#{dom_id}.shadowSize = new GSize(#{shadow_width}, #{shadow_height});"
  js << "#{dom_id}.iconAnchor = new GPoint(#{anchor_x}, #{anchor_y});"
  js << "#{dom_id}.infoWindowAnchor = new GPoint(#{info_anchor_x}, #{info_anchor_y});"
  return js.join("\n")
end