Module: Geos::GoogleMaps::Api2::CoordinateSequence

Defined in:
lib/geos/google_maps/api_2.rb

Instance Method Summary collapse

Instance Method Details

#to_g_lat_lng_api2(options = {}) ⇒ Object

Returns a Ruby Array of GLatLngs.



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/geos/google_maps/api_2.rb', line 52

def to_g_lat_lng_api2(options = {})
  klass = if options[:short_class]
    'GLatLng'
  else
    'google.maps.LatLng'
  end

  self.to_a.collect do |p|
    "new #{klass}(#{p[1]}, #{p[0]})"
  end
end

#to_g_polygon_api2(polygon_options = {}, options = {}) ⇒ Object

Returns a new GPolygon. Note that this GPolygon just uses whatever coordinates are found in the sequence in order, so it might not make much sense at all.

The options Hash follows the Google Maps API arguments to the GPolygon constructor and include :stroke_color, :stroke_weight, :stroke_opacity, :fill_color, :fill_opacity and :options. ‘null’ is used in place of any unset options.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/geos/google_maps/api_2.rb', line 100

def to_g_polygon_api2(polygon_options = {}, options = {})
  klass = if options[:short_class]
    'GPolygon'
  else
    'google.maps.Polygon'
  end

  poly_opts = if polygon_options[:polygon_options]
    Geos::Helper.camelize_keys(polygon_options[:polygon_options])
  end

  args = [
    (polygon_options[:stroke_color] ? "'#{Geos::Helper.escape_javascript(polygon_options[:stroke_color])}'" : 'null'),
    (polygon_options[:stroke_weight] || 'null'),
    (polygon_options[:stroke_opacity] || 'null'),
    (polygon_options[:fill_color] ? "'#{Geos::Helper.escape_javascript(polygon_options[:fill_color])}'" : 'null'),
    (polygon_options[:fill_opacity] || 'null'),
    (poly_opts ? poly_opts.to_json : 'null')
  ].join(', ')
  "new #{klass}([#{self.to_g_lat_lng_api2(options).join(', ')}], #{args})"
end

#to_g_polyline_api2(polyline_options = {}, options = {}) ⇒ Object

Returns a new GPolyline. Note that this GPolyline just uses whatever coordinates are found in the sequence in order, so it might not make much sense at all.

The options Hash follows the Google Maps API arguments to the GPolyline constructor and include :color, :weight, :opacity and :options. ‘null’ is used in place of any unset options.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/geos/google_maps/api_2.rb', line 71

def to_g_polyline_api2(polyline_options = {}, options = {})
  klass = if options[:short_class]
    'GPolyline'
  else
    'google.maps.Polyline'
  end

  poly_opts = if polyline_options[:polyline_options]
    Geos::Helper.camelize_keys(polyline_options[:polyline_options])
  end

  args = [
    (polyline_options[:color] ? "'#{Geos::Helper.escape_javascript(polyline_options[:color])}'" : 'null'),
    (polyline_options[:weight] || 'null'),
    (polyline_options[:opacity] || 'null'),
    (poly_opts ? poly_opts.to_json : 'null')
  ].join(', ')

  "new #{klass}([#{self.to_g_lat_lng(options).join(', ')}], #{args})"
end