Module: Geos::GoogleMaps::Api3::CoordinateSequence

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

Instance Method Summary collapse

Instance Method Details

#to_g_lat_lng_api3(options = {}) ⇒ Object

Returns a Ruby Array of LatLngs.



77
78
79
80
81
# File 'lib/geos/google_maps/api_3.rb', line 77

def to_g_lat_lng_api3(options = {})
  self.to_a.collect do |p|
    "new google.maps.LatLng(#{p[1]}, #{p[0]})"
  end
end

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

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

The polygon_options Hash follows the Google Maps API arguments to the Polyline constructor and include :clickable, :geodesic, :map, etc. See the Google Maps API documentation for details.

The options Hash allows you to specify if certain arguments should be escaped on output. Usually the options in UNESCAPED_POLY_OPTIONS are escaped, but if for some reason you want some other options to be escaped, pass them along in options. The options Hash also passes along options to to_g_lat_lng_api3.



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/geos/google_maps/api_3.rb', line 122

def to_g_polygon_api3(polygon_options = {}, options = {})
  options = {
    :escape => [],
    :lat_lng_options => {}
  }.merge(options)

  opts = Geos::Helper.camelize_keys(polygon_options)
  opts[:paths] = "[#{self.to_g_lat_lng_api3(options[:lat_lng_options]).join(', ')}]"
  json = Geos::Helper.escape_json(opts, Geos::GoogleMaps::Api3Constants::UNESCAPED_POLY_OPTIONS - options[:escape])

  "new google.maps.Polygon(#{json})"
end

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

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

The polyline_options Hash follows the Google Maps API arguments to the Polyline constructor and include :clickable, :geodesic, :map, etc. See the Google Maps API documentation for details.

The options Hash allows you to specify if certain arguments should be escaped on output. Usually the options in UNESCAPED_POLY_OPTIONS are escaped, but if for some reason you want some other options to be escaped, pass them along in options. The options Hash also passes along options to to_g_lat_lng_api3.



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/geos/google_maps/api_3.rb', line 96

def to_g_polyline_api3(polyline_options = {}, options = {})
  options = {
    :escape => [],
    :lat_lng_options => {}
  }.merge(options)

  opts = Geos::Helper.camelize_keys(polyline_options)
  opts[:path] = "[#{self.to_g_lat_lng_api3(options[:lat_lng_options]).join(', ')}]"
  json = Geos::Helper.escape_json(opts, Geos::GoogleMaps::Api3Constants::UNESCAPED_POLY_OPTIONS - options[:escape])

  "new google.maps.Polyline(#{json})"
end