mapnik 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/.autotest +35 -0
  2. data/.yardopts +1 -0
  3. data/Gemfile +14 -0
  4. data/LICENSE +19 -0
  5. data/Manifest.txt +172 -0
  6. data/README.rdoc +107 -0
  7. data/Rakefile +43 -0
  8. data/demo/data/COPYRIGHT.txt +3 -0
  9. data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.dbf +0 -0
  10. data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.prj +1 -0
  11. data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shp +0 -0
  12. data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shx +0 -0
  13. data/demo/data/boundaries.dbf +0 -0
  14. data/demo/data/boundaries.prj +1 -0
  15. data/demo/data/boundaries.sbx +0 -0
  16. data/demo/data/boundaries.shp +0 -0
  17. data/demo/data/boundaries.shx +0 -0
  18. data/demo/data/boundaries_l.dbf +0 -0
  19. data/demo/data/boundaries_l.prj +1 -0
  20. data/demo/data/boundaries_l.sbx +0 -0
  21. data/demo/data/boundaries_l.shp +0 -0
  22. data/demo/data/boundaries_l.shx +0 -0
  23. data/demo/data/ontdrainage.dbf +0 -0
  24. data/demo/data/ontdrainage.prj +1 -0
  25. data/demo/data/ontdrainage.sbx +0 -0
  26. data/demo/data/ontdrainage.shp +0 -0
  27. data/demo/data/ontdrainage.shx +0 -0
  28. data/demo/data/popplaces.dbf +0 -0
  29. data/demo/data/popplaces.prj +1 -0
  30. data/demo/data/popplaces.sbx +0 -0
  31. data/demo/data/popplaces.shp +0 -0
  32. data/demo/data/popplaces.shx +0 -0
  33. data/demo/data/qcdrainage.dbf +0 -0
  34. data/demo/data/qcdrainage.prj +1 -0
  35. data/demo/data/qcdrainage.sbx +0 -0
  36. data/demo/data/qcdrainage.shp +0 -0
  37. data/demo/data/qcdrainage.shx +0 -0
  38. data/demo/data/roads.dbf +0 -0
  39. data/demo/data/roads.prj +1 -0
  40. data/demo/data/roads.sbx +0 -0
  41. data/demo/data/roads.shp +0 -0
  42. data/demo/data/roads.shx +0 -0
  43. data/demo/data/test/charplacement.dbf +0 -0
  44. data/demo/data/test/charplacement.shp +0 -0
  45. data/demo/data/test/charplacement.shx +0 -0
  46. data/demo/data/test/displacement.dbf +0 -0
  47. data/demo/data/test/displacement.shp +0 -0
  48. data/demo/data/test/displacement.shx +0 -0
  49. data/demo/data/test/overlap.dbf +0 -0
  50. data/demo/data/test/overlap.shp +0 -0
  51. data/demo/data/test/overlap.shx +0 -0
  52. data/demo/data/test/raw/charplacement.gfs +25 -0
  53. data/demo/data/test/raw/charplacement.gml +99 -0
  54. data/demo/data/test/raw/charplacement.xsd +36 -0
  55. data/demo/data/test/raw/displacement.gfs +25 -0
  56. data/demo/data/test/raw/displacement.gml +173 -0
  57. data/demo/data/test/raw/displacement.xsd +36 -0
  58. data/demo/data/test/raw/overlap.gfs +25 -0
  59. data/demo/data/test/raw/overlap.gml +127 -0
  60. data/demo/data/test/raw/overlap.xsd +36 -0
  61. data/demo/data/test/raw/textspacing.gfs +25 -0
  62. data/demo/data/test/raw/textspacing.gml +117 -0
  63. data/demo/data/test/raw/textspacing.xsd +36 -0
  64. data/demo/data/test/readme.txt +3 -0
  65. data/demo/data/test/regenerate.sh +20 -0
  66. data/demo/data/test/textspacing.dbf +0 -0
  67. data/demo/data/test/textspacing.shp +0 -0
  68. data/demo/data/test/textspacing.shx +0 -0
  69. data/demo/rundemo.rb +145 -0
  70. data/demo/sinatra/demo.rb +31 -0
  71. data/demo/sinatra/public/css/demo_map.css +7 -0
  72. data/demo/sinatra/public/index.html +13 -0
  73. data/demo/sinatra/public/javascripts/demo_map.js +42 -0
  74. data/ext/ruby_mapnik/_mapnik.cpp +52 -0
  75. data/ext/ruby_mapnik/_mapnik.h +65 -0
  76. data/ext/ruby_mapnik/_mapnik_color.rb.cpp +179 -0
  77. data/ext/ruby_mapnik/_mapnik_color.rb.h +32 -0
  78. data/ext/ruby_mapnik/_mapnik_coord.rb.cpp +145 -0
  79. data/ext/ruby_mapnik/_mapnik_coord.rb.h +32 -0
  80. data/ext/ruby_mapnik/_mapnik_datasource.rb.cpp +170 -0
  81. data/ext/ruby_mapnik/_mapnik_datasource.rb.h +32 -0
  82. data/ext/ruby_mapnik/_mapnik_datasource_cache.rb.cpp +87 -0
  83. data/ext/ruby_mapnik/_mapnik_datasource_cache.rb.h +32 -0
  84. data/ext/ruby_mapnik/_mapnik_envelope.rb.cpp +220 -0
  85. data/ext/ruby_mapnik/_mapnik_envelope.rb.h +32 -0
  86. data/ext/ruby_mapnik/_mapnik_expression.rb.cpp +91 -0
  87. data/ext/ruby_mapnik/_mapnik_expression.rb.h +32 -0
  88. data/ext/ruby_mapnik/_mapnik_feature.rb.cpp +93 -0
  89. data/ext/ruby_mapnik/_mapnik_feature.rb.h +32 -0
  90. data/ext/ruby_mapnik/_mapnik_font_engine.rb.cpp +71 -0
  91. data/ext/ruby_mapnik/_mapnik_font_engine.rb.h +32 -0
  92. data/ext/ruby_mapnik/_mapnik_layer.rb.cpp +208 -0
  93. data/ext/ruby_mapnik/_mapnik_layer.rb.h +32 -0
  94. data/ext/ruby_mapnik/_mapnik_line_pattern_symbolizer.rb.cpp +71 -0
  95. data/ext/ruby_mapnik/_mapnik_line_pattern_symbolizer.rb.h +32 -0
  96. data/ext/ruby_mapnik/_mapnik_line_symbolizer.rb.cpp +43 -0
  97. data/ext/ruby_mapnik/_mapnik_line_symbolizer.rb.h +32 -0
  98. data/ext/ruby_mapnik/_mapnik_map.rb.cpp +489 -0
  99. data/ext/ruby_mapnik/_mapnik_map.rb.h +32 -0
  100. data/ext/ruby_mapnik/_mapnik_markers_symbolizer.rb.cpp +140 -0
  101. data/ext/ruby_mapnik/_mapnik_markers_symbolizer.rb.h +32 -0
  102. data/ext/ruby_mapnik/_mapnik_point_symbolizer.rb.cpp +150 -0
  103. data/ext/ruby_mapnik/_mapnik_point_symbolizer.rb.h +32 -0
  104. data/ext/ruby_mapnik/_mapnik_polygon_pattern_symbolizer.rb.cpp +93 -0
  105. data/ext/ruby_mapnik/_mapnik_polygon_pattern_symbolizer.rb.h +32 -0
  106. data/ext/ruby_mapnik/_mapnik_polygon_symbolizer.rb.cpp +89 -0
  107. data/ext/ruby_mapnik/_mapnik_polygon_symbolizer.rb.h +32 -0
  108. data/ext/ruby_mapnik/_mapnik_projection.rb.cpp +100 -0
  109. data/ext/ruby_mapnik/_mapnik_projection.rb.h +32 -0
  110. data/ext/ruby_mapnik/_mapnik_raster_colorizer.rb.cpp +162 -0
  111. data/ext/ruby_mapnik/_mapnik_raster_colorizer.rb.h +32 -0
  112. data/ext/ruby_mapnik/_mapnik_raster_symbolizer.rb.cpp +87 -0
  113. data/ext/ruby_mapnik/_mapnik_raster_symbolizer.rb.h +32 -0
  114. data/ext/ruby_mapnik/_mapnik_rule.rb.cpp +69 -0
  115. data/ext/ruby_mapnik/_mapnik_rule.rb.h +32 -0
  116. data/ext/ruby_mapnik/_mapnik_shield_symbolizer.rb.cpp +86 -0
  117. data/ext/ruby_mapnik/_mapnik_shield_symbolizer.rb.h +32 -0
  118. data/ext/ruby_mapnik/_mapnik_stroke.rb.cpp +188 -0
  119. data/ext/ruby_mapnik/_mapnik_stroke.rb.h +32 -0
  120. data/ext/ruby_mapnik/_mapnik_style.rb.cpp +76 -0
  121. data/ext/ruby_mapnik/_mapnik_style.rb.h +32 -0
  122. data/ext/ruby_mapnik/_mapnik_symbolizer.rb.cpp +75 -0
  123. data/ext/ruby_mapnik/_mapnik_symbolizer.rb.h +32 -0
  124. data/ext/ruby_mapnik/_mapnik_text_symbolizer.rb.cpp +471 -0
  125. data/ext/ruby_mapnik/_mapnik_text_symbolizer.rb.h +32 -0
  126. data/ext/ruby_mapnik/extconf.rb +80 -0
  127. data/ext/ruby_mapnik/ruby_mapnik.cpp +32 -0
  128. data/lib/mapnik.rb +1 -0
  129. data/lib/ruby_mapnik.rb +48 -0
  130. data/lib/ruby_mapnik/mapnik/font_engine.rb +35 -0
  131. data/lib/ruby_mapnik/mapnik/layer.rb +68 -0
  132. data/lib/ruby_mapnik/mapnik/map.rb +166 -0
  133. data/lib/ruby_mapnik/mapnik/projection.rb +44 -0
  134. data/lib/ruby_mapnik/mapnik/raster_colorizer.rb +55 -0
  135. data/lib/ruby_mapnik/mapnik/rule.rb +104 -0
  136. data/lib/ruby_mapnik/mapnik/stroke.rb +56 -0
  137. data/lib/ruby_mapnik/mapnik/style.rb +64 -0
  138. data/lib/ruby_mapnik/mapnik/tile.rb +93 -0
  139. data/script/console +2 -0
  140. data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.dbf +0 -0
  141. data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.prj +1 -0
  142. data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shp +0 -0
  143. data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shx +0 -0
  144. data/test/data/test_map.xml +15 -0
  145. data/test/test_helper.rb +29 -0
  146. data/test/test_line_pattern_symbolizer.rb +26 -0
  147. data/test/test_mapnik_color.rb +66 -0
  148. data/test/test_mapnik_coord.rb +92 -0
  149. data/test/test_mapnik_datasource.rb +49 -0
  150. data/test/test_mapnik_envelope.rb +232 -0
  151. data/test/test_mapnik_expression.rb +19 -0
  152. data/test/test_mapnik_feature.rb +29 -0
  153. data/test/test_mapnik_font_engine.rb +13 -0
  154. data/test/test_mapnik_layer.rb +121 -0
  155. data/test/test_mapnik_line_symbolizer.rb +25 -0
  156. data/test/test_mapnik_map.rb +211 -0
  157. data/test/test_mapnik_markers_symbolizer.rb +46 -0
  158. data/test/test_mapnik_point_symbolizer.rb +53 -0
  159. data/test/test_mapnik_polygon_symbolizer.rb +44 -0
  160. data/test/test_mapnik_projection.rb +46 -0
  161. data/test/test_mapnik_raster_colorizer.rb +56 -0
  162. data/test/test_mapnik_raster_symbolizer.rb +45 -0
  163. data/test/test_mapnik_rule.rb +45 -0
  164. data/test/test_mapnik_shield_symbolizer.rb +156 -0
  165. data/test/test_mapnik_stroke.rb +94 -0
  166. data/test/test_mapnik_style.rb +28 -0
  167. data/test/test_mapnik_symbolizer.rb +9 -0
  168. data/test/test_mapnik_text_symbolizer.rb +208 -0
  169. data/test/test_polygon_pattern_symbolizer.rb +34 -0
  170. data/test/test_ruby_mapnik.rb +34 -0
  171. data/yard/lib/yard/parser/generic_parser.rb +72 -0
  172. data/yard/lib/yard_generic.rb +18 -0
  173. metadata +333 -0
@@ -0,0 +1,19 @@
1
+ require "test_helper"
2
+
3
+ class TestMapnikExpression < Test::Unit::TestCase
4
+
5
+ def test_presence
6
+ assert Mapnik::Expression
7
+ assert Mapnik::PathExpression
8
+ end
9
+
10
+ def test_should_evaluate
11
+ expression = "([place]='town')"
12
+ assert_equal expression, Mapnik::Expression.parse(expression).to_s
13
+ end
14
+
15
+ def test_should_parse_path
16
+ assert Mapnik::PathExpression.parse("/my/path.png")
17
+ end
18
+
19
+ end
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ class TestMapnikFeature < Test::Unit::TestCase
4
+
5
+ def test_should_instantiate
6
+ feature_id = 12
7
+ assert feature = Mapnik::Feature.new(Mapnik::Context.new, feature_id)
8
+ assert_equal feature_id, feature.id
9
+ assert_equal "Feature ( id=#{feature_id})", feature.to_s.gsub("\n", '')
10
+ end
11
+
12
+ def test_should_return_number_of_geometries
13
+ assert feature = Mapnik::Feature.new(Mapnik::Context.new, 1)
14
+ assert_equal 0, feature.number_of_geometries
15
+ end
16
+
17
+ def test_should_return_its_envelope
18
+ assert feature = Mapnik::Feature.new(Mapnik::Context.new, 1)
19
+ assert feature.envelope.kind_of?(Mapnik::Envelope)
20
+ end
21
+
22
+ def test_should_add_a_geometry
23
+ feature = Mapnik::Feature.new(Mapnik::Context.new, 1)
24
+ assert_equal(0, feature.number_of_geometries)
25
+ feature.add_geometries_from_wkt("POINT(30 10)")
26
+ assert_equal(1, feature.number_of_geometries)
27
+ end
28
+
29
+ end
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ class TestMapnikFontEngine < Test::Unit::TestCase
4
+
5
+ def test_presence
6
+ assert Mapnik::FontEngine
7
+ end
8
+
9
+ def test_face_name
10
+ assert Mapnik::FontEngine.face_names.instance_of?(Array)
11
+ end
12
+
13
+ end
@@ -0,0 +1,121 @@
1
+ require "test_helper"
2
+
3
+ class TestMapnikLayer < Test::Unit::TestCase
4
+
5
+ def test_presence
6
+ assert Mapnik::Layer
7
+ end
8
+
9
+ def test_should_initialize
10
+ assert layer = Mapnik::Layer.new("My Layer", "+proj=latlong +datum=WGS84")
11
+ end
12
+
13
+ def test_should_have_datasource
14
+ layer = build_layer
15
+ assert layer.datasource.envelope
16
+ end
17
+
18
+ def test_should_have_same_enevelope_as_datasource
19
+ layer = build_layer
20
+ assert layer.envelope.kind_of?(Mapnik::Envelope)
21
+ assert_equal layer.envelope, layer.datasource.envelope
22
+ end
23
+
24
+ def test_should_get_and_set_name
25
+ layer = build_layer
26
+ name_before = layer.name
27
+ new_name = name_before + "BUT DIFFERENT"
28
+ layer.name = new_name
29
+ assert_equal new_name, layer.name
30
+ end
31
+
32
+ def test_should_get_and_set_srs
33
+ layer = build_layer
34
+ srs_before = layer.srs
35
+ new_srs = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
36
+ layer.srs = new_srs
37
+ assert_equal new_srs, layer.srs
38
+ end
39
+
40
+ def test_should_get_and_set_min_zoom
41
+ layer = build_layer
42
+ min_zoom_before = layer.min_zoom
43
+ new_min_zoom = min_zoom_before + 1.2
44
+ layer.min_zoom = new_min_zoom
45
+ assert_equal new_min_zoom, layer.min_zoom
46
+ end
47
+
48
+ def test_should_get_and_set_max_zoom
49
+ layer = build_layer
50
+ max_zoom_before = layer.max_zoom
51
+ new_max_zoom = max_zoom_before + 1.2
52
+ layer.max_zoom = new_max_zoom
53
+ assert_equal new_max_zoom, layer.max_zoom
54
+ end
55
+
56
+ def test_should_know_if_it_is_visible_at_a_given_scale
57
+ layer = build_layer
58
+ layer.min_zoom = 0.0
59
+ assert layer.visible_at_scale?(1.0/1000000)
60
+ layer.min_zoom = 2.0
61
+ assert !layer.visible_at_scale?(1.0/1000000)
62
+ end
63
+
64
+ def test_should_know_if_it_is_active
65
+ layer = build_layer
66
+ assert layer.active?
67
+ layer.active = false
68
+ assert !layer.active?
69
+ layer.active = true
70
+ assert layer.active?
71
+ end
72
+
73
+ def test_should_know_if_it_is_queryable
74
+ layer = build_layer
75
+ assert !layer.queryable?
76
+ layer.queryable = true
77
+ assert layer.queryable?
78
+ layer.queryable = false
79
+ assert !layer.queryable?
80
+ end
81
+
82
+ def test_should_know_if_it_should_cache_features
83
+ layer = build_layer
84
+ assert !layer.cache_features?
85
+ layer.cache_features = true
86
+ assert layer.cache_features?
87
+ layer.cache_features = false
88
+ assert !layer.cache_features?
89
+ end
90
+
91
+ def test_should_know_if_it_should_clear_its_label_cache
92
+ layer = build_layer
93
+ assert !layer.clear_label_cache?
94
+ layer.clear_label_cache = true
95
+ assert layer.clear_label_cache?
96
+ layer.clear_label_cache = false
97
+ assert !layer.clear_label_cache?
98
+ end
99
+
100
+ def test_should_have_styles
101
+ layer = build_layer
102
+ assert layer.styles.instance_of?(Mapnik::LayerStyleContainer)
103
+ assert layer.styles.empty?
104
+ style_name = 'My Style'
105
+ layer.styles << style_name
106
+ assert !layer.styles.empty?
107
+ assert_equal style_name, layer.styles.first
108
+ end
109
+
110
+ private
111
+
112
+ def build_layer
113
+ layer = Mapnik::Layer.new("My Layer", "+proj=latlong +datum=WGS84")
114
+ layer.datasource = Mapnik::Datasource.create(
115
+ :type => 'shape',
116
+ :file => SHAPEFILE
117
+ )
118
+ layer
119
+ end
120
+
121
+ end
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+
3
+ class TestMapnikLineSymbolizer < Test::Unit::TestCase
4
+
5
+ def test_presence
6
+ assert Mapnik::LineSymbolizer
7
+ end
8
+
9
+ def test_should_instantiate
10
+ assert Mapnik::LineSymbolizer.new
11
+ end
12
+
13
+ def test_should_get_and_set_stroke
14
+ line = Mapnik::LineSymbolizer.new
15
+ stroke_before = line.stroke
16
+ assert stroke_before.kind_of?(Mapnik::Stroke)
17
+
18
+ new_stroke = Mapnik::Stroke.new(Mapnik::Color.new("#fff"), 1.0)
19
+ line.stroke = new_stroke
20
+
21
+ # Once Equality for strokes is established
22
+ # assert_equal new_stroke, line.stroke
23
+ end
24
+
25
+ end
@@ -0,0 +1,211 @@
1
+ require "test_helper"
2
+ require "chunky_png"
3
+
4
+ class TestMapnikMap < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @map = Mapnik::Map.new
8
+ end
9
+
10
+ def test_should_initialize
11
+ assert @map
12
+ end
13
+
14
+ def test_should_have_envelope
15
+ assert @map.envelope.kind_of?(Mapnik::Envelope)
16
+ end
17
+
18
+ def test_should_have_styles
19
+ assert @map.styles.instance_of?(Mapnik::MapStyleContainer)
20
+ assert @map.styles.empty?
21
+
22
+ key = "My Style"
23
+ @map.styles[key] = Mapnik::Style.new
24
+ assert @map.styles.any?
25
+ assert @map.styles[key].is_a?(Mapnik::Style)
26
+
27
+ @map.styles.delete(key)
28
+ assert @map.styles.empty?
29
+ end
30
+
31
+ def test_should_have_buffered_envelope
32
+ envelope_before = @map.envelope
33
+ assert_equal 0, @map.buffer_size
34
+ buffered_envelope_before = @map.buffered_envelope
35
+ assert_equal envelope_before, buffered_envelope_before
36
+
37
+ @map.buffer_size = 1
38
+
39
+ assert_equal 1, @map.buffer_size
40
+ assert_equal envelope_before, @map.envelope
41
+ assert_not_equal buffered_envelope_before, @map.buffered_envelope
42
+ end
43
+
44
+ def test_should_pan
45
+ center_before = @map.envelope.center
46
+ @map.pan(-1,-1)
47
+ assert_not_equal center_before, @map.envelope.center
48
+ end
49
+
50
+ def test_should_get_and_set_background
51
+ assert @map.background.nil?
52
+ color = Mapnik::Color.new("#fff")
53
+ @map.background = color
54
+ assert_equal color, @map.background
55
+ end
56
+
57
+ def test_should_zoom
58
+ scale_before = @map.scale
59
+ @map.zoom(2)
60
+ end
61
+
62
+ def test_should_zoom_all
63
+ # Override since there are no layers
64
+ @map.maximum_extent = Mapnik::Envelope.new(-180,-90,180,90)
65
+ @map.zoom_all
66
+ end
67
+
68
+ def test_should_resize
69
+ width_before = @map.width
70
+ height_before = @map.height
71
+
72
+ new_width = width_before + 1
73
+ new_height = height_before + 1
74
+ @map.resize(new_width, new_height)
75
+ assert_equal(new_width, @map.width)
76
+ assert_equal(new_height, @map.height)
77
+ end
78
+
79
+ def test_should_have_scale
80
+ assert @map.scale.kind_of?(Float)
81
+ end
82
+
83
+ def test_should_zoom_to_box
84
+ box = Mapnik::Envelope.new(1,1,1,1)
85
+ @map.zoom_to_box(box)
86
+ end
87
+
88
+ def test_mapnik_base_path
89
+ assert @map.base_path.kind_of?(String)
90
+ assert_equal "", @map.base_path
91
+ new_base_path = "/some/path"
92
+ @map.base_path = new_base_path
93
+ assert_equal new_base_path, @map.base_path
94
+ end
95
+
96
+ def test_should_get_and_set_buffer_size
97
+ assert_equal 0, @map.buffer_size
98
+ new_buffer_size = 1
99
+ @map.buffer_size = new_buffer_size
100
+ assert_equal new_buffer_size, @map.buffer_size
101
+ end
102
+
103
+ def test_should_get_and_set_height
104
+ assert_equal 400, @map.height
105
+ new_height = 401
106
+ @map.height = new_height
107
+ assert_equal new_height, @map.height
108
+ end
109
+
110
+ def test_should_get_and_set_maximum_extent
111
+ assert_nil @map.maximum_extent
112
+ new_max_extent = Mapnik::Envelope.new(-180,-90,180,90)
113
+ @map.maximum_extent = new_max_extent
114
+ assert_equal new_max_extent, @map.maximum_extent
115
+ end
116
+
117
+ def test_should_get_and_set_srs
118
+ assert_equal "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", @map.srs
119
+ new_srs = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over"
120
+ @map.srs = new_srs
121
+ assert_equal new_srs, @map.srs
122
+ end
123
+
124
+ def test_should_get_and_set_width
125
+ width_before = @map.width
126
+ new_width = width_before + 1
127
+ @map.width = new_width
128
+ assert_equal new_width, @map.width
129
+ end
130
+
131
+ def test_should_have_layers
132
+ assert @map.layers.empty?
133
+ layer = Mapnik::Layer.new("My Layer", "+proj=latlong +datum=WGS84")
134
+ @map.layers << layer
135
+ assert @map.layers.any?
136
+
137
+ @map.layers.clear
138
+ assert @map.layers.empty?
139
+ end
140
+
141
+ def test_should_output_to_xml
142
+ map = build_complete_map
143
+ assert map.to_xml.instance_of?(String)
144
+ assert map.to_xml.include?("<?xml")
145
+ end
146
+
147
+ def test_should_render_to_file
148
+ map = build_complete_map
149
+ filename = File.join(File.expand_path(File.dirname(__FILE__)), "../tmp/world.png")
150
+ assert_equal 0, File.size(filename) if File.exists?(filename)
151
+ assert map.render_to_file(filename)
152
+ assert File.exists?(filename)
153
+ File.delete(filename)
154
+ end
155
+
156
+ def test_should_render_to_file_with_explicit_format
157
+ map = build_complete_map
158
+ filename = File.join(File.expand_path(File.dirname(__FILE__)), "../tmp/world-256.png")
159
+ assert_equal 0, File.size(filename) if File.exists?(filename)
160
+ assert map.render_to_file(filename, "png256")
161
+ assert File.exists?(filename)
162
+ assert_not_nil ChunkyPNG::Datastream.from_file(filename).palette_chunk
163
+ File.delete(filename)
164
+ end
165
+
166
+ def test_should_load_from_xml_string
167
+ map_1 = build_complete_map
168
+ map_2 = Mapnik::Map.from_xml(map_1.to_xml)
169
+ assert_equal map_1.layers.count, map_2.layers.count
170
+ assert_equal map_1.srs, map_2.srs
171
+ end
172
+
173
+ def test_should_load_from_file_path_string
174
+ file_path = File.join(File.expand_path(File.dirname(__FILE__)), "data", "test_map.xml")
175
+ map = Mapnik::Map.from_file(file_path)
176
+ assert map.layers.any?
177
+ assert map.styles['My Style']
178
+ end
179
+
180
+ def test_should_load_from_file
181
+ file = File.open(File.join(File.expand_path(File.dirname(__FILE__)), "data", "test_map.xml"))
182
+ map = Mapnik::Map.from_file(file)
183
+ assert map.layers.any?
184
+ assert map.styles['My Style']
185
+ end
186
+
187
+
188
+ private
189
+
190
+ def build_complete_map
191
+ map = Mapnik::Map.new
192
+ map.width = 600
193
+ map.height = 300
194
+ map.srs = "+proj=latlong +datum=WGS84"
195
+ map.background = Mapnik::Color.new("#0000FF")
196
+ style = Mapnik::Style.new
197
+ rule = Mapnik::Rule.new
198
+ poly = Mapnik::PolygonSymbolizer.new
199
+ poly.fill = Mapnik::Color.new("#FF0088")
200
+ rule.symbols << poly
201
+ style.rules << rule
202
+ map.styles["My Style"]=style
203
+ layer = Mapnik::Layer.new('world',"+proj=latlong +datum=WGS84")
204
+ layer.datasource = Mapnik::Datasource.create(:type => "shape", :file => SHAPEFILE)
205
+ layer.styles << "My Style"
206
+ map.layers << layer
207
+ map.zoom_to_box(layer.envelope)
208
+ map
209
+ end
210
+
211
+ end
@@ -0,0 +1,46 @@
1
+ require "test_helper"
2
+
3
+ class TestMarkersSymbolizer < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @filename = "/my/file.png"
7
+ path_expression = Mapnik::PathExpression.parse("/my/file.png")
8
+ @sym = Mapnik::MarkersSymbolizer.new(path_expression)
9
+ end
10
+
11
+ def test_should_instantiate
12
+ assert @sym
13
+ end
14
+
15
+ def test_should_get_and_set_filename
16
+ assert_equal @filename, @sym.filename
17
+ new_filename = "/something/else.png"
18
+ @sym.filename = new_filename
19
+ assert_equal new_filename, @sym.filename
20
+ end
21
+
22
+ def test_should_get_and_set_allow_overlap
23
+ @sym.allow_overlap = true
24
+ assert @sym.allow_overlap?
25
+ @sym.allow_overlap = false
26
+ assert !@sym.allow_overlap?
27
+ end
28
+
29
+ def test_should_get_and_set_spacing
30
+ @sym.spacing = 90
31
+ assert_equal 90, @sym.spacing
32
+ end
33
+
34
+ def test_should_get_and_set_max_error
35
+ @sym.max_error = 90
36
+ assert_equal 90, @sym.max_error
37
+ end
38
+
39
+ def test_should_get_and_set_opacity
40
+ assert_equal 1, @sym.opacity
41
+ # new_opacity = 0.5
42
+ # @sym.opacity = new_opacity
43
+ # assert_equal new_opacity, @sym.opacity
44
+ end
45
+
46
+ end