def as_json(options = {})
      options = {
        :encoded => true,
        :level => 3,
        :interior_rings => false
      }.merge options

      style_options = Hash.new
      if options[:style_options] && !options[:style_options].empty?
        options[:style_options].each do |k, v|
          style_options[Geos::Helper.camelize(k.to_s)] = v
        end
      end

      if options[:encoded]
        ret = {
          :type => 'polygon',
          :encoded => true,
          :polylines => [ Geos::GoogleMaps::PolylineEncoder.encode(
              self.exterior_ring.coord_seq.to_a,
              options[:level]
            ).merge(:bounds => {
              :sw => self.lower_left.to_a,
              :ne => self.upper_right.to_a
            })
          ],
          :options => style_options
        }

        if options[:interior_rings] && self.num_interior_rings > 0
          (0..(self.num_interior_rings) - 1).to_a.each do |n|
            ret[:polylines] << Geos::GoogleMaps::PolylineEncoder.encode(
              self.interior_ring_n(n).coord_seq.to_a,
              options[:level]
            )
          end
        end
        ret
      else
        ret = {
          :type => 'polygon',
          :encoded => false,
          :polylines => [{
            :points => self.exterior_ring.coord_seq.to_a,
            :bounds => {
              :sw => self.lower_left.to_a,
              :ne => self.upper_right.to_a
            }
          }]
        }
        if options[:interior_rings] && self.num_interior_rings > 0
          (0..(self.num_interior_rings) - 1).to_a.each do |n|
            ret[:polylines] << {
              :points => self.interior_ring_n(n).coord_seq.to_a
            }
          end
        end
        ret
      end
    end
def as_json(options = {})
      options = {
        :encoded => true,
        :level => 3,
        :interior_rings => false
      }.merge options

      style_options = Hash.new
      if options[:style_options] && !options[:style_options].empty?
        options[:style_options].each do |k, v|
          style_options[Geos::Helper.camelize(k.to_s)] = v
        end
      end

      if options[:encoded]
        ret = {
          :type => 'polygon',
          :encoded => true,
          :polylines => [ Geos::GoogleMaps::PolylineEncoder.encode(
              self.exterior_ring.coord_seq.to_a,
              options[:level]
            ).merge(:bounds => {
              :sw => self.lower_left.to_a,
              :ne => self.upper_right.to_a
            })
          ],
          :options => style_options
        }

        if options[:interior_rings] && self.num_interior_rings > 0
          (0..(self.num_interior_rings) - 1).to_a.each do |n|
            ret[:polylines] << Geos::GoogleMaps::PolylineEncoder.encode(
              self.interior_ring_n(n).coord_seq.to_a,
              options[:level]
            )
          end
        end
        ret
      else
        ret = {
          :type => 'polygon',
          :encoded => false,
          :polylines => [{
            :points => self.exterior_ring.coord_seq.to_a,
            :bounds => {
              :sw => self.lower_left.to_a,
              :ne => self.upper_right.to_a
            }
          }]
        }
        if options[:interior_rings] && self.num_interior_rings > 0
          (0..(self.num_interior_rings) - 1).to_a.each do |n|
            ret[:polylines] << {
              :points => self.interior_ring_n(n).coord_seq.to_a
            }
          end
        end
        ret
      end
    end
Returns a Hash suitable for converting to JSON.

 Options:

 * :encoded - enable or disable Google Maps encoding. The default is
   true.
 * :level - set the level of the Google Maps encoding algorithm.
 * :interior_rings - add interior rings to the output. The default
   is false.
 * :style_options - any style options you want to pass along in the
   JSON. These options will be automatically camelized into
   Javascripty code.