Class: GoogleMap::Marker

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::JavaScriptHelper
Defined in:
lib/google_map/marker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Marker

Returns a new instance of Marker.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/google_map/marker.rb', line 20

def initialize(options = {})
  options.each_pair { |key, value| send("#{key}=", value) }
  
  if lat.blank? or lng.blank? or !map or !map.kind_of?(GoogleMap::Map)
    raise "Must set lat, lng, and map for GoogleMapMarker."
  end
  
  if dom_id.blank?
    # This needs self to set the attr_accessor, why?
    self.dom_id = "#{map.dom_id}_marker_#{map.markers.size + 1}"
  end
  
end

Instance Attribute Details

#dom_idObject

Returns the value of attribute dom_id.



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

def dom_id
  @dom_id
end

#dragendObject

Returns the value of attribute dragend.



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

def dragend
  @dragend
end

#draggableObject

Returns the value of attribute draggable.



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

def draggable
  @draggable
end

#dragstartObject

Returns the value of attribute dragstart.



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

def dragstart
  @dragstart
end

#htmlObject

Returns the value of attribute html.



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

def html
  @html
end

#iconObject

Returns the value of attribute icon.



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

def icon
  @icon
end

#latObject

Returns the value of attribute lat.



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

def lat
  @lat
end

#lngObject

Returns the value of attribute lng.



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

def lng
  @lng
end

#mapObject

Returns the value of attribute map.



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

def map
  @map
end

#marker_hover_textObject

Returns the value of attribute marker_hover_text.



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

def marker_hover_text
  @marker_hover_text
end

#marker_icon_pathObject

Returns the value of attribute marker_icon_path.



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

def marker_icon_path
  @marker_icon_path
end

#open_infoWindowObject

Returns the value of attribute open_infoWindow.



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

def open_infoWindow
  @open_infoWindow
end

Instance Method Details

#open_info_windowObject



44
45
46
# File 'lib/google_map/marker.rb', line 44

def open_info_window
  "#{dom_id}_infowindow_function();"
end

#open_info_window_functionObject



34
35
36
37
38
39
40
41
42
# File 'lib/google_map/marker.rb', line 34

def open_info_window_function
  js = []

  js << "function #{dom_id}_infowindow_function() {"
  js << "  #{dom_id}.openInfoWindowHtml(\"#{escape_javascript(html)}\")"
  js << "}"

  return js.join("\n")
end

#to_jsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/google_map/marker.rb', line 48

def to_js
  js = []

  h = ", title: '#{escape_javascript(marker_hover_text)}'" if marker_hover_text

  # If a icon is specified, use it in marker creation.
  i = ", { icon: #{icon.dom_id} #{h} }" if icon
  i = ", { icon: new GIcon( G_DEFAULT_ICON, '#{marker_icon_path}') #{h} }" if marker_icon_path
		
  options = ', { draggable: true }' if self.draggable
  js << "#{dom_id} = new GMarker( new GLatLng( #{lat}, #{lng} ) #{i} #{options} );"
  js << "GEvent.bind(#{dom_id}, \"dragstart\", #{dom_id}, #{self.dragstart});" if dragstart
  js << "GEvent.bind(#{dom_id}, \"dragend\", #{dom_id}, #{self.dragend});" if dragend
  
  if self.html
    js << "GEvent.addListener(#{dom_id}, 'click', function() {#{dom_id}_infowindow_function()});"
  end

  js << "#{map.dom_id}.addOverlay(#{dom_id});"

  if open_infoWindow
    js << "GEvent.trigger(#{dom_id}, 'click')"
  end

  return js.join("\n")
end