class Hexagonly::GeoJson

Attributes

features[R]

Public Class Methods

new(features = nil) click to toggle source

@param [Array] features an array of objects that support the to_geojson method

# File lib/hexagonly/geo_json.rb, line 9
def initialize(features = nil)
  add_features(features) unless features.nil?
end

Public Instance Methods

add_features(features) click to toggle source

Adds features (Points, Spaces, Hexagons) that support the to_geojson method.

@param [Array] features an array of objects that support the to_geojson method

# File lib/hexagonly/geo_json.rb, line 16
def add_features(features)
  @features ||= []
  features.each do |feat|
    @features << feat.to_geojson
  end
end
to_json() click to toggle source

Outputs the GeoJson string.

@return [String] a valid GeoJSON string

# File lib/hexagonly/geo_json.rb, line 26
def to_json
  {
    :type => "FeatureCollection",
    :features => @features
  }.to_json
end