Class: SimpleMapnik::Config
- Inherits:
-
Object
- Object
- SimpleMapnik::Config
- Defined in:
- lib/simple_mapnik/config.rb
Instance Attribute Summary collapse
- #background_color ⇒ Object
- #line_stroke_color ⇒ Object
- #line_stroke_width ⇒ Object
- #marker_fill ⇒ Object
- #marker_height ⇒ Object
- #marker_stroke_color ⇒ Object
- #marker_stroke_width ⇒ Object
- #marker_width ⇒ Object
- #polygon_fill_color ⇒ Object
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
- #srs ⇒ Object
- #type ⇒ Object
Instance Method Summary collapse
- #config_file ⇒ Object
-
#initialize(path) ⇒ Config
constructor
A new instance of Config.
-
#xml ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
Constructor Details
#initialize(path) ⇒ Config
Returns a new instance of Config.
19 20 21 22 |
# File 'lib/simple_mapnik/config.rb', line 19 def initialize(path) @path = path @settings ||= File.exist?(config_file) ? YAML.load_file(config_file) : {} end |
Instance Attribute Details
#background_color ⇒ Object
40 41 42 |
# File 'lib/simple_mapnik/config.rb', line 40 def background_color @background_color ||= settings.fetch('background_color', '#483d8b') end |
#line_stroke_color ⇒ Object
48 49 50 |
# File 'lib/simple_mapnik/config.rb', line 48 def line_stroke_color @line_stroke_color ||= settings.fetch('line_stroke_color', '#483d8b') end |
#line_stroke_width ⇒ Object
52 53 54 |
# File 'lib/simple_mapnik/config.rb', line 52 def line_stroke_width @line_stroke_width ||= settings.fetch('line_stroke_width', '0.2') end |
#marker_fill ⇒ Object
56 57 58 |
# File 'lib/simple_mapnik/config.rb', line 56 def marker_fill @marker_fill ||= settings.fetch('marker_fill', '#0000ff') end |
#marker_height ⇒ Object
64 65 66 |
# File 'lib/simple_mapnik/config.rb', line 64 def marker_height @marker_height ||= settings.fetch('marker_height', '5') end |
#marker_stroke_color ⇒ Object
68 69 70 |
# File 'lib/simple_mapnik/config.rb', line 68 def marker_stroke_color @marker_stroke_color ||= settings.fetch('marker_stroke_color', '#483d8b') end |
#marker_stroke_width ⇒ Object
72 73 74 |
# File 'lib/simple_mapnik/config.rb', line 72 def marker_stroke_width @marker_stroke_width ||= settings.fetch('marker_stroke_width', '0.2') end |
#marker_width ⇒ Object
60 61 62 |
# File 'lib/simple_mapnik/config.rb', line 60 def marker_width @marker_width ||= settings.fetch('marker_width', '5') end |
#polygon_fill_color ⇒ Object
44 45 46 |
# File 'lib/simple_mapnik/config.rb', line 44 def polygon_fill_color @polygon_fill_color ||= settings.fetch('polygon_fill_color', '#fffff0') end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
6 7 8 |
# File 'lib/simple_mapnik/config.rb', line 6 def settings @settings end |
#srs ⇒ Object
32 33 34 |
# File 'lib/simple_mapnik/config.rb', line 32 def srs @srs ||= '+init=epsg:4326' end |
#type ⇒ Object
36 37 38 |
# File 'lib/simple_mapnik/config.rb', line 36 def type @type ||= 'shape' end |
Instance Method Details
#config_file ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/simple_mapnik/config.rb', line 24 def config_file if defined?(Rails) && Rails.root File.join(Rails.root, 'config/mapnik.yml') else File.('../../config/mapnik.yml', File.dirname(__FILE__)) end end |
#xml ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/simple_mapnik/config.rb', line 77 def xml Nokogiri::XML::Builder.new do |xml| xml.Map(srs: srs, :'background-color' => background_color) do xml.Style(name: 'style') do xml.Rule() do xml.Filter('[mapnik::geometry_type]=point') xml.MarkersSymbolizer( fill: marker_fill, width: marker_width, height: marker_height, stroke: marker_stroke_color, :'stroke-width' => marker_stroke_width, :'allow-overlap' => 'true' ) end xml.Rule() do xml.PolygonSymbolizer(fill: polygon_fill_color) xml.LineSymbolizer( stroke: line_stroke_color, :'stroke-width' => line_stroke_width) end end xml.Layer(name: 'layer', srs: srs) do xml.StyleName 'style' xml.Datasource do xml.Parameter(@path, name: 'file') xml.Parameter(type, name: 'type') end end end end.to_xml # rubocop:enable Metrics/AbcSize, Metrics/MethodLength end |