Module: SpatialFeatures::FusionTables::API

Extended by:
API
Included in:
API
Defined in:
lib/spatial_features/has_fusion_table_features/api.rb

Constant Summary collapse

FEATURE_COLUMNS =
{
  :name => 'STRING',
  :spatial_model_type => 'STRING',
  :spatial_model_id => 'NUMBER',
  :kml_lowres => 'LOCATION',
  :colour => 'STRING',
  :metadata => 'STRING'
}
TABLE_STYLE =
{
  :polygon_options => { :fill_color_styler => { :kind => 'fusiontables#fromColumn', :column_name => 'colour' },
                        :stroke_color => { :kind => 'fusiontables#fromColumn', :column_name => 'colour' },
                        :stroke_opacity => 0.5 },
  :polyline_options => { :stroke_color_styler => { :kind => 'fusiontables#fromColumn', :column_name => 'stroke_colour'} }
}
TABLE_TEMPLATE =
{
  :body => "<h3>{name}</h3>{metadata}"
}

Instance Method Summary collapse

Instance Method Details

#create_table(name) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 29

def create_table(name)
  table_id = service.create_table(name, FEATURE_COLUMNS.collect {|name, type| {:name => name, :type => type} })
  service.share_table(table_id)
  service.insert_style(table_id, TABLE_STYLE)
  service.insert_template(table_id, TABLE_TEMPLATE)
  return table_id
end

#delete_table(table_id) ⇒ Object



41
42
43
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 41

def delete_table(table_id)
  service.delete_table(table_id)
end

#find_or_create_table(name) ⇒ Object



25
26
27
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 25

def find_or_create_table(name)
  find_table(name) || create_table(name)
end

#find_table(name) ⇒ Object



37
38
39
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 37

def find_table(name)
  service.tables.find {|table| table.name == name }.try(:table_id)
end

#serviceObject



53
54
55
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 53

def service
  @service ||= Service.new(Configuration.)
end

#set_features(table_id, features, colour: nil) ⇒ Object



49
50
51
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 49

def set_features(table_id, features, colour: nil)
  service.replace_rows(table_id, features_to_csv(features, colour))
end

#tablesObject



45
46
47
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 45

def tables
  service.tables
end