spatial_features 2.4.3 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68aa7bdc309d176e516eb2a32156373e0dbaad1c
4
- data.tar.gz: 0c1a5d5153cc35ab38d5a37a96a9bafc4c154adc
3
+ metadata.gz: 3f9a2d017923b7bb6f058501fa83c871a9d215f3
4
+ data.tar.gz: 9e54295de270f2aaa04404bd2aec8ce71dc9b1dc
5
5
  SHA512:
6
- metadata.gz: 77bf00cb03c9608d111c8474912d7bcd125746ae5e150fdf6d098cd1b6677ed182b162d3528bbf852c92322a126ea40ae2610a347ebb064d078ac94258f3a96b
7
- data.tar.gz: c232858bf11da70cabe5dc7ea468524fed63c949f73e8b8b600fb38f940f7b55a48a8d30fcbd6fc44a85ef612f49081965f4ad86abf1d31e430517eb6da2d95c
6
+ metadata.gz: 61d4a13e97fa049f174e06d8fae41b5620db491c00e6a7e45eb5ae41cc0916771163e4e29d1732cb78a100ecdb3734ff392d214297b73aea0388b06d5ee25958
7
+ data.tar.gz: dc79046fb16d330cc7025cbfa30e12234cccff8f1f94293924064e1b7985a5df915f3b05ed0c9397f78bd2dd08e2d89f4e52d2a127bbd3f530fa24a79c6077f2
@@ -0,0 +1,15 @@
1
+ module Chroma
2
+ class Color
3
+ module Serializers
4
+ # Google's Fusion Table colouring expects the alpha value in the last position, not the first
5
+ def to_ft_hex
6
+ [
7
+ to_2char_hex(@rgb.r),
8
+ to_2char_hex(@rgb.g),
9
+ to_2char_hex(@rgb.b),
10
+ to_2char_hex(alpha * 255)
11
+ ].join('')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -12,8 +12,10 @@ module SpatialFeatures
12
12
  :metadata => 'STRING'
13
13
  }
14
14
  TABLE_STYLE = {
15
- :polygon_options => { :fill_color_styler => { :kind => 'fusiontables#fromColumn', :column_name => 'colour' }, :stroke_color => '#000000', :stroke_opacity => 0.2 },
16
- :polyline_options => { :stroke_color_styler => { :kind => 'fusiontables#fromColumn', :column_name => 'colour'} }
15
+ :polygon_options => { :fill_color_styler => { :kind => 'fusiontables#fromColumn', :column_name => 'colour' },
16
+ :stroke_color => { :kind => 'fusiontables#fromColumn', :column_name => 'colour' },
17
+ :stroke_opacity => 0.5 },
18
+ :polyline_options => { :stroke_color_styler => { :kind => 'fusiontables#fromColumn', :column_name => 'stroke_colour'} }
17
19
  }
18
20
 
19
21
  TABLE_TEMPLATE = {
@@ -45,8 +47,7 @@ module SpatialFeatures
45
47
  end
46
48
 
47
49
  def set_features(table_id, features, colour: nil)
48
- colour_features(features, colour)
49
- service.replace_rows(table_id, features_to_csv(features))
50
+ service.replace_rows(table_id, features_to_csv(features, colour))
50
51
  end
51
52
 
52
53
  def service
@@ -55,11 +56,20 @@ module SpatialFeatures
55
56
 
56
57
  private
57
58
 
58
- def features_to_csv(features)
59
+ def features_to_csv(features, colour)
60
+ ActiveRecord::Associations::Preloader.new.preload(features, :spatial_model) if colour.is_a?(Symbol)
61
+
59
62
  csv = CSV.generate do |csv|
60
63
  features.each do |feature|
61
64
  csv << FEATURE_COLUMNS.keys.collect do |attribute|
62
- render_feature_attribute feature.send(attribute)
65
+ case attribute
66
+ when :colour
67
+ render_feature_colour(feature, colour)
68
+ when :metadata
69
+ render_feature_metadata(feature)
70
+ else
71
+ feature.send(attribute)
72
+ end
63
73
  end
64
74
  end
65
75
  end
@@ -69,39 +79,24 @@ module SpatialFeatures
69
79
  return file
70
80
  end
71
81
 
72
- def render_feature_attribute(value)
73
- case value
74
- when Hash
75
- value.collect do |name, val|
76
- "<b>#{name}:</b> #{val}"
77
- end.join('<br/>')
78
- else
79
- value
80
- end
82
+ def render_feature_metadata(feature)
83
+ feature.metadata.collect do |name, val|
84
+ "<b>#{name}:</b> #{val}"
85
+ end.join('<br/>')
81
86
  end
82
87
 
83
- def colour_features(features, colour)
88
+ def render_feature_colour(feature, colour)
84
89
  case colour
85
90
  when Symbol
86
- ActiveRecord::Associations::Preloader.new.preload(features, :spatial_model)
87
- features.each do |feature|
88
- feature.define_singleton_method(:colour) do
89
- spatial_model.send(colour)
90
- end
91
- end
91
+ feature.spatial_model.send(colour)
92
92
  when Proc
93
- features.each do |feature|
94
- feature.define_singleton_method(:colour) do
95
- colour.call(feature)
96
- end
97
- end
93
+ colour.call(feature)
98
94
  else
99
- features.each do |feature|
100
- feature.define_singleton_method(:colour) do
101
- colour
102
- end
103
- end
104
- end
95
+ colour
96
+ end.paint.to_ft_hex
97
+
98
+ rescue Chroma::Errors::UnrecognizedColor
99
+ nil
105
100
  end
106
101
  end
107
102
  end
@@ -5,6 +5,8 @@ module SpatialFeatures
5
5
  class_attribute :fusion_table_features_options
6
6
  self.fusion_table_features_options = options
7
7
 
8
+ after_update_features :expire_fusion_table
9
+
8
10
  include InstanceMethods
9
11
  extend ClassMethods
10
12
  end
@@ -54,6 +56,14 @@ module SpatialFeatures
54
56
  true
55
57
  end
56
58
 
59
+ def stale_fusion_table?
60
+ @stale_fusion_table
61
+ end
62
+
63
+ def expire_fusion_table
64
+ @stale_fusion_table = true
65
+ end
66
+
57
67
  def update_fusion_table
58
68
  self.class.update_fusion_tables(only: fusion_table_id)
59
69
  end
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "2.4.3"
2
+ VERSION = "2.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spatial_features
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Wallace
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-09-04 00:00:00.000000000 Z
12
+ date: 2017-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -109,6 +109,20 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0.9'
112
+ - !ruby/object:Gem::Dependency
113
+ name: chroma
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 0.1.0
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: 0.1.0
112
126
  - !ruby/object:Gem::Dependency
113
127
  name: pg
114
128
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,7 @@ files:
150
164
  - app/models/feature.rb
151
165
  - app/models/spatial_cache.rb
152
166
  - app/models/spatial_proximity.rb
167
+ - config/initializers/chroma_serializers.rb
153
168
  - config/initializers/register_oids.rb
154
169
  - lib/spatial_features.rb
155
170
  - lib/spatial_features/caching.rb