Module: SpatialFeatures::FusionTables::API
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_styler => { :kind => 'fusiontables#fromColumn', :column_name => 'colour' }, :stroke_weight => 1 }, :polyline_options => { :stroke_color_styler => { :kind => 'fusiontables#fromColumn', :column_name => 'colour'} } }
- TABLE_TEMPLATE =
{ :body => "<h3>{name}</h3>{metadata}" }
Instance Method Summary collapse
- #create_table(name) ⇒ Object
- #delete_table(table_id) ⇒ Object
- #find_or_create_table(name) ⇒ Object
- #find_table(name) ⇒ Object
- #service ⇒ Object
- #set_features(table_id, features, colour: nil) ⇒ Object
- #set_style(table_id, style) ⇒ Object
- #tables ⇒ Object
Instance Method Details
#create_table(name) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 30 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
42 43 44 |
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 42 def delete_table(table_id) service.delete_table(table_id) end |
#find_or_create_table(name) ⇒ Object
26 27 28 |
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 26 def find_or_create_table(name) find_table(name) || create_table(name) end |
#find_table(name) ⇒ Object
38 39 40 |
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 38 def find_table(name) service.tables.find {|table| table.name == name }.try(:table_id) end |
#service ⇒ Object
61 62 63 |
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 61 def service @service ||= Service.new(Configuration.service_account_credentials) end |
#set_features(table_id, features, colour: nil) ⇒ Object
50 51 52 |
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 50 def set_features(table_id, features, colour: nil) service.replace_rows(table_id, features_to_csv(features, colour)) end |
#set_style(table_id, style) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 54 def set_style(table_id, style) service.style_ids(table_id).each do |style_id| service.delete_style(table_id, style_id) end service.insert_style(table_id, style) end |
#tables ⇒ Object
46 47 48 |
# File 'lib/spatial_features/has_fusion_table_features/api.rb', line 46 def tables service.tables end |