Class: Amanzi::SLD::RuleBuilder
Instance Attribute Summary
#element
Instance Method Summary
collapse
-
#add_line_symbolizer(options = {}, *args, &block) ⇒ Object
-
#add_polygon_symbolizer(options = {}, *args, &block) ⇒ Object
-
#add_text_symbolizer(options = {}, *args, &block) ⇒ Object
-
#initialize(rule) ⇒ RuleBuilder
constructor
A new instance of RuleBuilder.
-
#style_fill(fill, options = {}) ⇒ Object
-
#style_font(font, options = {}) ⇒ Object
-
#style_it(it, prefix, options = {}) ⇒ Object
-
#style_stroke(stroke, options = {}) ⇒ Object
-
#update_filter_block(options, &block) ⇒ Object
#method_missing
Methods included from Logger
#puts
Constructor Details
Returns a new instance of RuleBuilder.
91
92
93
|
# File 'lib/amanzi/sld.rb', line 91
def initialize(rule)
super rule
end
|
Instance Method Details
#add_line_symbolizer(options = {}, *args, &block) ⇒ Object
128
129
130
131
132
133
134
135
136
|
# File 'lib/amanzi/sld.rb', line 128
def add_line_symbolizer(options={},*args,&block)
options[:stroke] ||= '#000000'
options[:stroke_width] ||= 1
puts "RuleBuilder:Adding line symbolizer with options: #{options.inspect}"
block = update_filter_block(options,&block)
block.call FilterBuilder.new(rule.insert_child(0,'Filter').ns(:ogc)) if(block)
style_stroke(rule.line_symbolizer.stroke,options)
self
end
|
#add_polygon_symbolizer(options = {}, *args, &block) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/amanzi/sld.rb', line 137
def add_polygon_symbolizer(options={},*args,&block)
options[:fill] ||= '#b0b0b0'
puts "Adding polygon symbolizer with options: #{options.inspect}"
block = update_filter_block(options,&block)
block.call FilterBuilder.new(rule.insert_child(0,'Filter').ns(:ogc)) if(block)
rule.polygon_symbolizer do |p|
style_fill(p.fill,options)
style_stroke(p.stroke,options)
end
self
end
|
#add_text_symbolizer(options = {}, *args, &block) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/amanzi/sld.rb', line 148
def add_text_symbolizer(options={},*args,&block)
return self unless options[:text] || options[:property]
options[:font_family] ||= 'Times New Roman'
options[:font_style] ||= 'Normal'
options[:font_size] ||= 14
options[:font_weight] ||= 'bold'
options[:font_color] ||= '#101010'
options[:fill] ||= '#101010'
options[:halo_style] ||= {:fill => '#ffffbb', :fill_opacity => 0.85}
puts "Adding text symbolizer with options: #{options.inspect}"
block = update_filter_block(options,&block)
block.call FilterBuilder.new(rule.insert_child(0,'Filter').ns(:ogc)) if(block)
rule.text_symbolizer do |p|
if options[:property]
p.label.ogc__property_name << options[:property]
else
p.label.ogc__literal << options[:text]
end
style_font(p.font,options)
if options[:halo].to_i > 0
p.halo do |h|
h.radius.ogc__literal << options[:halo].to_i
style_fill(h.fill,options[:halo_style])
end
end
style_fill(p.fill,options)
end
self
end
|
#style_fill(fill, options = {}) ⇒ Object
104
105
106
|
# File 'lib/amanzi/sld.rb', line 104
def style_fill(fill,options={})
style_it(fill,:fill,options)
end
|
#style_font(font, options = {}) ⇒ Object
107
108
109
|
# File 'lib/amanzi/sld.rb', line 107
def style_font(font,options={})
style_it(font,:font,options)
end
|
#style_it(it, prefix, options = {}) ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/amanzi/sld.rb', line 94
def style_it(it,prefix,options={})
options.each do |k,v|
if k.to_s =~ /^#{prefix}/
it.css_parameter(:name => k.to_s.gsub(/_/,'-')) << v
end
end
end
|
#style_stroke(stroke, options = {}) ⇒ Object
101
102
103
|
# File 'lib/amanzi/sld.rb', line 101
def style_stroke(stroke,options={})
style_it(stroke,:stroke,options)
end
|
#update_filter_block(options, &block) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/amanzi/sld.rb', line 110
def update_filter_block(options,&block)
new_block = block
self.max_scale_denominator << options[:max_scale].to_f if(options[:max_scale])
self.min_scale_denominator << options[:min_scale].to_f if(options[:min_scale])
if(options[:geometry])
if(block)
new_block = Proc.new do |f|
f.op(:and) do |f|
f.geometry = options[:geometry]
block.call f
end
end
else
new_block = Proc.new {|f| f.geometry = options[:geometry]}
end
end
new_block
end
|