Class: GoogleMap::Marker
- Inherits:
-
Object
- Object
- GoogleMap::Marker
- Includes:
- ActionView::Helpers::JavaScriptHelper
- Defined in:
- lib/google_map/marker.rb
Instance Attribute Summary collapse
-
#dom_id ⇒ Object
Returns the value of attribute dom_id.
-
#dragend ⇒ Object
Returns the value of attribute dragend.
-
#draggable ⇒ Object
Returns the value of attribute draggable.
-
#dragstart ⇒ Object
Returns the value of attribute dragstart.
-
#html ⇒ Object
Returns the value of attribute html.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lng ⇒ Object
Returns the value of attribute lng.
-
#map ⇒ Object
Returns the value of attribute map.
-
#marker_hover_text ⇒ Object
Returns the value of attribute marker_hover_text.
-
#marker_icon_path ⇒ Object
Returns the value of attribute marker_icon_path.
-
#open_infoWindow ⇒ Object
Returns the value of attribute open_infoWindow.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Marker
constructor
A new instance of Marker.
- #open_info_window ⇒ Object
- #open_info_window_function ⇒ Object
- #to_js ⇒ Object
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( = {}) .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_id ⇒ Object
Returns the value of attribute dom_id.
7 8 9 |
# File 'lib/google_map/marker.rb', line 7 def dom_id @dom_id end |
#dragend ⇒ Object
Returns the value of attribute dragend.
7 8 9 |
# File 'lib/google_map/marker.rb', line 7 def dragend @dragend end |
#draggable ⇒ Object
Returns the value of attribute draggable.
7 8 9 |
# File 'lib/google_map/marker.rb', line 7 def draggable @draggable end |
#dragstart ⇒ Object
Returns the value of attribute dragstart.
7 8 9 |
# File 'lib/google_map/marker.rb', line 7 def dragstart @dragstart end |
#html ⇒ Object
Returns the value of attribute html.
7 8 9 |
# File 'lib/google_map/marker.rb', line 7 def html @html end |
#icon ⇒ Object
Returns the value of attribute icon.
7 8 9 |
# File 'lib/google_map/marker.rb', line 7 def icon @icon end |
#lat ⇒ Object
Returns the value of attribute lat.
7 8 9 |
# File 'lib/google_map/marker.rb', line 7 def lat @lat end |
#lng ⇒ Object
Returns the value of attribute lng.
7 8 9 |
# File 'lib/google_map/marker.rb', line 7 def lng @lng end |
#map ⇒ Object
Returns the value of attribute map.
7 8 9 |
# File 'lib/google_map/marker.rb', line 7 def map @map end |
#marker_hover_text ⇒ Object
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_path ⇒ Object
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_infoWindow ⇒ Object
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_window ⇒ Object
44 45 46 |
# File 'lib/google_map/marker.rb', line 44 def open_info_window "#{dom_id}_infowindow_function();" end |
#open_info_window_function ⇒ Object
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_js ⇒ Object
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 = ', { draggable: true }' if self.draggable js << "#{dom_id} = new GMarker( new GLatLng( #{lat}, #{lng} ) #{i} #{} );" 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 |