simple_mapnik 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fde74f6c08431ecd79eadd9e53cb013c93f318e6
4
- data.tar.gz: 67b3788a29f8a9e3fa08eff3b563292507f3affd
3
+ metadata.gz: 606d7bb053ce8d471f71f8d37763e932dbd3b292
4
+ data.tar.gz: 86b8767e26a6d7fa0f59873776a20ef951afa9e1
5
5
  SHA512:
6
- metadata.gz: 30332c347f933f7699f91bfb13bda27983ad9536b4e5719c6de30285f00c880fe63b7444819afc48e6f9aa1e9ebb0d0a33e8296783cfbdf3ce52e00608a6a441
7
- data.tar.gz: 136498479b705627db8c8f7cf11d669f53c596fe595a011884b003d32b4c32523e2d249454ac3bd850474728466390513acf0b230368cd25de482f63d0776ac5
6
+ metadata.gz: 2f51f5b63d46d1f1d6626d2657aa5eb74b1bced00e7e9fd6281336bea38fa88e158a41aef72f61b4502fe9e375c36b5a6379e8e4ab356562bd3a6135478e3143
7
+ data.tar.gz: 1847a6420707c81f291553c8812cc36e588c98ce4f3d76d9b8a55a621d6c288b90e22675d86bbb0ce14d73d0ec323c61399b985ac6f16d71000ced5f2e653a91
data/config/mapnik.yml ADDED
@@ -0,0 +1,14 @@
1
+ background_color: '#ffffff' # use '#ffffff00' for a transparent background
2
+
3
+ polygon_fill_color: '#fffff0'
4
+
5
+ line_stroke_color: '#483d8b'
6
+ line_stroke_width: '0.3'
7
+
8
+ marker_fill: '#0000ff'
9
+ marker_width: '5'
10
+ marker_height: '5'
11
+ marker_stroke_color: '#483d8b'
12
+ marker_stroke_width: '0.2'
13
+ marker_placement: 'point'
14
+ marker_allow_overlap-overlap: 'true'
@@ -1,52 +1,102 @@
1
1
  require 'nokogiri'
2
+ require 'yaml'
2
3
 
3
4
  module SimpleMapnik
4
5
  class Config
5
- attr_accessor :path
6
- attr_writer :background_color, :srs, :polygon_fill, :stroke, :stroke_width
6
+ attr_reader :settings
7
+ attr_writer :srs,
8
+ :type,
9
+ :background_color,
10
+ :polygon_fill_color,
11
+ :line_stroke_color,
12
+ :line_stroke_width,
13
+ :marker_fill,
14
+ :marker_width,
15
+ :marker_height,
16
+ :marker_stroke_color,
17
+ :marker_stroke_width
7
18
 
8
19
  def initialize(path)
9
20
  @path = path
21
+ @settings ||= File.exist?(config_file) ? YAML.load_file(config_file) : {}
10
22
  end
11
23
 
12
- def background_color
13
- @background_color ||= 'white'
24
+ def config_file
25
+ File.expand_path('../../config/mapnik.yml', File.dirname(__FILE__))
14
26
  end
15
27
 
16
28
  def srs
17
29
  @srs ||= '+init=epsg:4326'
18
30
  end
19
31
 
20
- def polygon_fill
21
- @polygon_fill ||= 'ivory'
32
+ def type
33
+ @type ||= 'shape'
22
34
  end
23
35
 
24
- def stroke
25
- @stroke ||= 'darkslateblue'
36
+ def background_color
37
+ @background_color ||= settings.fetch('background_color', '#483d8b')
26
38
  end
27
39
 
28
- def stroke_width
29
- @stroke_width ||= '.3'
40
+ def polygon_fill_color
41
+ @polygon_fill_color ||= settings.fetch('polygon_fill_color', '#fffff0')
30
42
  end
31
43
 
32
- def type
33
- @type ||= 'shape'
44
+ def line_stroke_color
45
+ @line_stroke_color ||= settings.fetch('line_stroke_color', '#483d8b')
46
+ end
47
+
48
+ def line_stroke_width
49
+ @line_stroke_width ||= settings.fetch('line_stroke_width', '0.2')
50
+ end
51
+
52
+ def marker_fill
53
+ @marker_fill ||= settings.fetch('marker_fill', '#0000ff')
54
+ end
55
+
56
+ def marker_width
57
+ @marker_width ||= settings.fetch('marker_width', '5')
58
+ end
59
+
60
+ def marker_height
61
+ @marker_height ||= settings.fetch('marker_height', '5')
62
+ end
63
+
64
+ def marker_stroke_color
65
+ @marker_stroke_color ||= settings.fetch('marker_stroke_color', '#483d8b')
66
+ end
67
+
68
+ def marker_stroke_width
69
+ @marker_stroke_width ||= settings.fetch('marker_stroke_width', '0.2')
34
70
  end
35
71
 
36
72
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
37
73
  def xml
38
74
  Nokogiri::XML::Builder.new do |xml|
39
- xml.Map(srs: srs, 'background-color'.to_sym => background_color) do
75
+ xml.Map(srs: srs, :'background-color' => background_color) do
40
76
  xml.Style(name: 'style') do
41
77
  xml.Rule() do
42
- xml.PolygonSymbolizer(fill: polygon_fill)
43
- xml.LineSymbolizer(stroke: stroke, 'stroke-width'.to_sym => stroke_width)
78
+ xml.Filter('[mapnik::geometry_type]=point')
79
+ xml.MarkersSymbolizer(
80
+ fill: marker_fill,
81
+ width: marker_width,
82
+ height: marker_height,
83
+ :'stroke-color' => marker_stroke_color,
84
+ :'stroke-width' => marker_stroke_width,
85
+ :'allow_overlap-overlap' => 'true'
86
+ )
87
+ end
88
+ xml.Rule() do
89
+ xml.PolygonSymbolizer(fill: polygon_fill_color)
90
+ xml.LineSymbolizer(
91
+ stroke: line_stroke_color,
92
+ smooth: '1.0',
93
+ :'stroke-width' => line_stroke_width)
44
94
  end
45
95
  end
46
96
  xml.Layer(name: 'layer', srs: srs) do
47
97
  xml.StyleName 'style'
48
98
  xml.Datasource do
49
- xml.Parameter(path, name: 'file')
99
+ xml.Parameter(@path, name: 'file')
50
100
  xml.Parameter(type, name: 'type')
51
101
  end
52
102
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleMapnik
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.0.6'.freeze
3
3
  end
@@ -4,13 +4,12 @@ describe SimpleMapnik::Config do
4
4
  subject { described_class.new('shapefile') }
5
5
 
6
6
  describe '#xml' do
7
- it 'has style elements' do
7
+ it 'has layer rules' do
8
8
  config = subject.xml
9
- expect(config).to include('background-color')
9
+ expect(config).to include('MarkersSymbolizer')
10
+ expect(config).to include('PolygonSymbolizer')
11
+ expect(config).to include('LineSymbolizer')
10
12
  expect(config).to include('+init=epsg:4326')
11
- expect(config).to include('ivory')
12
- expect(config).to include('darkslateblue')
13
- expect(config).to include('stroke-width')
14
13
  expect(config).to include('shape')
15
14
  end
16
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_mapnik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eliot Jordan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-17 00:00:00.000000000 Z
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -169,6 +169,7 @@ files:
169
169
  - README.md
170
170
  - Rakefile
171
171
  - bin/mapnik_console
172
+ - config/mapnik.yml
172
173
  - coveralls.yml
173
174
  - lib/simple_mapnik.rb
174
175
  - lib/simple_mapnik/api.rb