Class: GoogleMap::Polyline

Inherits:
Object
  • Object
show all
Includes:
UnbackedDomId
Defined in:
lib/google_map/polyline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Polyline

Returns a new instance of Polyline.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/google_map/polyline.rb', line 14

def initialize(options = {})
  self.vertices = []
  self.color = "#000"
  self.weight = 1
  self.opacity = 1
  options.each_pair { |key, value| send("#{key}=", value) }
  if !map or !map.kind_of?(GoogleMap::Map)
    raise "Must set map for GoogleMap::Polyline."
  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

#colorObject

Returns the value of attribute color.



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

def color
  @color
end

#dom_idObject

Returns the value of attribute dom_id.



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

def dom_id
  @dom_id
end

#mapObject

Returns the value of attribute map.



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

def map
  @map
end

#opacityObject

Returns the value of attribute opacity.



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

def opacity
  @opacity
end

#verticesObject

Returns the value of attribute vertices.



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

def vertices
  @vertices
end

#weightObject

Returns the value of attribute weight.



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

def weight
  @weight
end

Instance Method Details

#to_jsObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/google_map/polyline.rb', line 29

def to_js

  js = []
  js << "#{dom_id}_vertices = new Array();"
  vertices.each_with_index do |point, index|
    js << "#{dom_id}_vertices[#{index}] = new GLatLng(#{point.lat}, #{point.lng});"
  end

  js << "#{dom_id} = new GPolyline(#{dom_id}_vertices, '#{color}', #{weight}, #{opacity});"

  js.join "\n"
end