Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 844 lines (731 sloc) 28.906 kB
88892c1 @artemp added save/load functionality based on boost::property_tree (aka Elem…
artemp authored
1 /*****************************************************************************
a3a5859 @artemp Patch from David Eastcott :
artemp authored
2 *
88892c1 @artemp added save/load functionality based on boost::property_tree (aka Elem…
artemp authored
3 * This file is part of Mapnik (c++ mapping toolkit)
4 *
f1fb0c1 @kunitoki - fix copyright to 2011 (script to do this will follow)
kunitoki authored
5 * Copyright (C) 2011 Artem Pavlenko
88892c1 @artemp added save/load functionality based on boost::property_tree (aka Elem…
artemp authored
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 *****************************************************************************/
47dc1e1 @artemp + merge mapnik2 to trunk
artemp authored
22
bc54b15 - reversed header include order
David authored
23 // mapnik
0de815b @springmeyer remove raster mode serialization and a few std::clog references in sa…
springmeyer authored
24 #include <mapnik/debug.hpp>
bc54b15 - reversed header include order
David authored
25 #include <mapnik/save_map.hpp>
384c703 @herm Remove unneeded headers from save_map.{cpp,hpp}
herm authored
26 #include <mapnik/map.hpp>
bc54b15 - reversed header include order
David authored
27 #include <mapnik/ptree_helpers.hpp>
47dc1e1 @artemp + merge mapnik2 to trunk
artemp authored
28 #include <mapnik/expression_string.hpp>
e9748ab @albertov xml de/serialization support for RasterColorizer
albertov authored
29 #include <mapnik/raster_colorizer.hpp>
e580078 @artemp + apply MetaWriter patch from zerebubuth
artemp authored
30 #include <mapnik/metawriter_factory.hpp>
69f153b @herm Fix all includes.
herm authored
31 #include <mapnik/text_placements/simple.hpp>
32 #include <mapnik/text_placements/list.hpp>
33 #include <mapnik/text_placements/dummy.hpp>
2f45de8 @springmeyer serialize comp-op in save_map - refs #1292
springmeyer authored
34 #include <mapnik/image_compositing.hpp>
3823890 @springmeyer rollback 34c3128b0cea7, move 'scaling' to proper enum, and move image…
springmeyer authored
35 #include <mapnik/image_scaling.hpp>
216768f @artemp + output image-filters and direct-image-filters
artemp authored
36 #include <mapnik/image_filter_types.hpp>
992af47 @artemp 1. move include to mapnik/include
artemp authored
37 // boost
88892c1 @artemp added save/load functionality based on boost::property_tree (aka Elem…
artemp authored
38 #include <boost/algorithm/string.hpp>
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
39 #include <boost/optional.hpp>
88892c1 @artemp added save/load functionality based on boost::property_tree (aka Elem…
artemp authored
40 #include <boost/property_tree/ptree.hpp>
41 #include <boost/property_tree/xml_parser.hpp>
bc54b15 - reversed header include order
David authored
42
43 // stl
44 #include <iostream>
88892c1 @artemp added save/load functionality based on boost::property_tree (aka Elem…
artemp authored
45
a3a5859 @artemp Patch from David Eastcott :
artemp authored
46 namespace mapnik
88892c1 @artemp added save/load functionality based on boost::property_tree (aka Elem…
artemp authored
47 {
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
48 using boost::property_tree::ptree;
49 using boost::optional;
50
51
52 class serialize_symbolizer : public boost::static_visitor<>
53 {
54 public:
55 serialize_symbolizer( ptree & r , bool explicit_defaults):
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
56 rule_(r),
57 explicit_defaults_(explicit_defaults) {}
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
58
7163806 @springmeyer c++ style
springmeyer authored
59 void operator () ( point_symbolizer const& sym )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
60 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
61 ptree & sym_node = rule_.push_back(
62 ptree::value_type("PointSymbolizer", ptree()))->second;
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
63
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
64 add_image_attributes( sym_node, sym );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
65
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
66 point_symbolizer dfl;
67 if (sym.get_allow_overlap() != dfl.get_allow_overlap() || explicit_defaults_ )
68 {
154dc59 @springmeyer serialize all dashes, no underscores, as per #644
springmeyer authored
69 set_attr( sym_node, "allow-overlap", sym.get_allow_overlap() );
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
70 }
71 if ( sym.get_opacity() != dfl.get_opacity() || explicit_defaults_ )
72 {
73 set_attr( sym_node, "opacity", sym.get_opacity() );
74 }
c52c91c @springmeyer serialize point_placement
springmeyer authored
75 if ( sym.get_point_placement() != dfl.get_point_placement() || explicit_defaults_ )
76 {
77 set_attr( sym_node, "placement", sym.get_point_placement() );
78 }
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
79 serialize_symbolizer_base(sym_node, sym);
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
80 }
81
7163806 @springmeyer c++ style
springmeyer authored
82 void operator () ( line_symbolizer const& sym )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
83 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
84 ptree & sym_node = rule_.push_back(
85 ptree::value_type("LineSymbolizer", ptree()))->second;
1fcb0ee @springmeyer serialize stroke separately from line_symbolizer, setting up for othe…
springmeyer authored
86
87 const stroke & strk = sym.get_stroke();
88 add_stroke_attributes(sym_node, strk);
c1495c0 @springmeyer restore the fast line rasterizer (rasterizer_outline_aa) and improve …
springmeyer authored
89
90 line_symbolizer dfl;
91 if ( sym.get_rasterizer() != dfl.get_rasterizer() || explicit_defaults_ )
92 {
93 set_attr( sym_node, "rasterizer", sym.get_rasterizer() );
94 }
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
95 serialize_symbolizer_base(sym_node, sym);
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
96 }
d991427 @springmeyer formatting
springmeyer authored
97
7163806 @springmeyer c++ style
springmeyer authored
98 void operator () ( line_pattern_symbolizer const& sym )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
99 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
100 ptree & sym_node = rule_.push_back(
101 ptree::value_type("LinePatternSymbolizer",
102 ptree()))->second;
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
103
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
104 add_image_attributes( sym_node, sym );
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
105 serialize_symbolizer_base(sym_node, sym);
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
106 }
107
7163806 @springmeyer c++ style
springmeyer authored
108 void operator () ( polygon_symbolizer const& sym )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
109 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
110 ptree & sym_node = rule_.push_back(
111 ptree::value_type("PolygonSymbolizer", ptree()))->second;
112 polygon_symbolizer dfl;
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
113
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
114 if ( sym.get_fill() != dfl.get_fill() || explicit_defaults_ )
115 {
116 set_attr( sym_node, "fill", sym.get_fill() );
117 }
118 if ( sym.get_opacity() != dfl.get_opacity() || explicit_defaults_ )
119 {
120 set_attr( sym_node, "fill-opacity", sym.get_opacity() );
121 }
122 if ( sym.get_gamma() != dfl.get_gamma() || explicit_defaults_ )
123 {
124 set_attr( sym_node, "gamma", sym.get_gamma() );
125 }
c007a60 @tarnowsc Adding gamma-method to polygon symbolizer
tarnowsc authored
126 if ( sym.get_gamma_method() != dfl.get_gamma_method() || explicit_defaults_ )
127 {
128 set_attr( sym_node, "gamma-method", sym.get_gamma_method() );
129 }
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
130 serialize_symbolizer_base(sym_node, sym);
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
131 }
132
7163806 @springmeyer c++ style
springmeyer authored
133 void operator () ( polygon_pattern_symbolizer const& sym )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
134 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
135 ptree & sym_node = rule_.push_back(
136 ptree::value_type("PolygonPatternSymbolizer",
137 ptree()))->second;
0959f8e @springmeyer + add support to polygon_patter_symbolizer for global pattern alignme…
springmeyer authored
138 polygon_pattern_symbolizer dfl(parse_path(""));
139
140 if ( sym.get_alignment() != dfl.get_alignment() || explicit_defaults_ )
141 {
142 set_attr( sym_node, "alignment", sym.get_alignment() );
143 }
476e04c @springmeyer add gamma to polygon-pattern-symbolizer, useful for avoiding AA affec…
springmeyer authored
144 if ( sym.get_gamma() != dfl.get_gamma() || explicit_defaults_ )
145 {
146 set_attr( sym_node, "gamma", sym.get_gamma() );
147 }
93ff232 @tarnowsc #1023 making gamma power default, making gamma-method awailable for p…
tarnowsc authored
148 if ( sym.get_gamma_method() != dfl.get_gamma_method() || explicit_defaults_ )
149 {
150 set_attr( sym_node, "gamma-method", sym.get_gamma_method() );
151 }
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
152 add_image_attributes( sym_node, sym );
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
153 serialize_symbolizer_base(sym_node, sym);
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
154 }
155
7163806 @springmeyer c++ style
springmeyer authored
156 void operator () ( raster_symbolizer const& sym )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
157 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
158 ptree & sym_node = rule_.push_back(
159 ptree::value_type("RasterSymbolizer", ptree()))->second;
160 raster_symbolizer dfl;
161
3823890 @springmeyer rollback 34c3128b0cea7, move 'scaling' to proper enum, and move image…
springmeyer authored
162 if ( sym.get_scaling_method() != dfl.get_scaling_method() || explicit_defaults_ )
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
163 {
3823890 @springmeyer rollback 34c3128b0cea7, move 'scaling' to proper enum, and move image…
springmeyer authored
164 set_attr( sym_node, "scaling", *scaling_method_to_string(sym.get_scaling_method()) );
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
165 }
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
166
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
167 if ( sym.get_opacity() != dfl.get_opacity() || explicit_defaults_ )
168 {
169 set_attr( sym_node, "opacity", sym.get_opacity() );
170 }
171
97431c8 @albertov made mesh_size configurable
albertov authored
172 if ( sym.get_mesh_size() != dfl.get_mesh_size() || explicit_defaults_ )
173 {
174 set_attr( sym_node, "mesh-size", sym.get_mesh_size() );
175 }
176
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
177 if (sym.get_colorizer()) {
178 serialize_raster_colorizer(sym_node, sym.get_colorizer(),
179 explicit_defaults_);
180 }
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
181 serialize_symbolizer_base(sym_node, sym);
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
182 }
183
7163806 @springmeyer c++ style
springmeyer authored
184 void operator () ( shield_symbolizer const& sym )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
185 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
186 ptree & sym_node = rule_.push_back(
187 ptree::value_type("ShieldSymbolizer",
188 ptree()))->second;
189
49a3b3c @herm Make code easier to read by using std::pair instead of boost::tuple f…
herm authored
190 add_font_attributes(sym_node, sym);
191 add_image_attributes(sym_node, sym);
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
192
193 // pseudo-default-construct a shield_symbolizer. It is used
194 // to avoid printing of attributes with default values without
195 // repeating the default values here.
196 // maybe add a real, explicit default-ctor?
197
49a3b3c @herm Make code easier to read by using std::pair instead of boost::tuple f…
herm authored
198 shield_symbolizer dfl;
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
199
49a3b3c @herm Make code easier to read by using std::pair instead of boost::tuple f…
herm authored
200 if (sym.get_unlock_image() != dfl.get_unlock_image() || explicit_defaults_)
ed22d07 @springmeyer fix serialization of missing shield symbolizer properties
springmeyer authored
201 {
49a3b3c @herm Make code easier to read by using std::pair instead of boost::tuple f…
herm authored
202 set_attr(sym_node, "unlock-image", sym.get_unlock_image());
ed22d07 @springmeyer fix serialization of missing shield symbolizer properties
springmeyer authored
203 }
49a3b3c @herm Make code easier to read by using std::pair instead of boost::tuple f…
herm authored
204 if (sym.get_text_opacity() != dfl.get_text_opacity() || explicit_defaults_)
ed22d07 @springmeyer fix serialization of missing shield symbolizer properties
springmeyer authored
205 {
49a3b3c @herm Make code easier to read by using std::pair instead of boost::tuple f…
herm authored
206 set_attr(sym_node, "text-opacity", sym.get_text_opacity());
ed22d07 @springmeyer fix serialization of missing shield symbolizer properties
springmeyer authored
207 }
208 position displacement = sym.get_shield_displacement();
49a3b3c @herm Make code easier to read by using std::pair instead of boost::tuple f…
herm authored
209 if (displacement.first != dfl.get_shield_displacement().first || explicit_defaults_)
ed22d07 @springmeyer fix serialization of missing shield symbolizer properties
springmeyer authored
210 {
49a3b3c @herm Make code easier to read by using std::pair instead of boost::tuple f…
herm authored
211 set_attr(sym_node, "shield-dx", displacement.first);
ed22d07 @springmeyer fix serialization of missing shield symbolizer properties
springmeyer authored
212 }
49a3b3c @herm Make code easier to read by using std::pair instead of boost::tuple f…
herm authored
213 if (displacement.second != dfl.get_shield_displacement().second || explicit_defaults_)
ed22d07 @springmeyer fix serialization of missing shield symbolizer properties
springmeyer authored
214 {
49a3b3c @herm Make code easier to read by using std::pair instead of boost::tuple f…
herm authored
215 set_attr(sym_node, "shield-dy", displacement.second);
ed22d07 @springmeyer fix serialization of missing shield symbolizer properties
springmeyer authored
216 }
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
217 serialize_symbolizer_base(sym_node, sym);
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
218 }
219
7163806 @springmeyer c++ style
springmeyer authored
220 void operator () ( text_symbolizer const& sym )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
221 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
222 ptree & sym_node = rule_.push_back(
223 ptree::value_type("TextSymbolizer",
224 ptree()))->second;
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
225
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
226 add_font_attributes( sym_node, sym);
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
227 serialize_symbolizer_base(sym_node, sym);
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
228 }
229
7163806 @springmeyer c++ style
springmeyer authored
230 void operator () ( building_symbolizer const& sym )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
231 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
232 ptree & sym_node = rule_.push_back(
233 ptree::value_type("BuildingSymbolizer", ptree()))->second;
234 building_symbolizer dfl;
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
235
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
236 if ( sym.get_fill() != dfl.get_fill() || explicit_defaults_ )
237 {
238 set_attr( sym_node, "fill", sym.get_fill() );
239 }
240 if ( sym.get_opacity() != dfl.get_opacity() || explicit_defaults_ )
241 {
242 set_attr( sym_node, "fill-opacity", sym.get_opacity() );
243 }
bd9609c @lightmare new feature: transform expressions are now dynamic
lightmare authored
244 if (sym.height())
245 {
246 set_attr( sym_node, "height", mapnik::to_expression_string(*sym.height()) );
247 }
b438a56 @tarnowsc refactoring following comment on pull request
tarnowsc authored
248
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
249 serialize_symbolizer_base(sym_node, sym);
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
250 }
251
a688c36 @springmeyer serialize the experimental MarkersSymbolizer and avoid serializing de…
springmeyer authored
252 void operator () ( markers_symbolizer const& sym)
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
253 {
a688c36 @springmeyer serialize the experimental MarkersSymbolizer and avoid serializing de…
springmeyer authored
254 ptree & sym_node = rule_.push_back(
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
255 ptree::value_type("MarkersSymbolizer", ptree()))->second;
89f6b32 @springmeyer apply patch from Herm from #553 adding support for markers_symbolizer…
springmeyer authored
256 markers_symbolizer dfl(parse_path("")); //TODO: Parameter?
bd9609c @lightmare new feature: transform expressions are now dynamic
lightmare authored
257 if (sym.get_filename())
258 {
259 std::string filename = path_processor_type::to_string(*sym.get_filename());
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
260 set_attr( sym_node, "file", filename );
261 }
89f6b32 @springmeyer apply patch from Herm from #553 adding support for markers_symbolizer…
springmeyer authored
262 if (sym.get_allow_overlap() != dfl.get_allow_overlap() || explicit_defaults_)
263 {
154dc59 @springmeyer serialize all dashes, no underscores, as per #644
springmeyer authored
264 set_attr( sym_node, "allow-overlap", sym.get_allow_overlap() );
89f6b32 @springmeyer apply patch from Herm from #553 adding support for markers_symbolizer…
springmeyer authored
265 }
0ecd5ba @novldp +add MarkersSymbolizer ignore-placement to save_map and python bindings
novldp authored
266 if (sym.get_ignore_placement() != dfl.get_ignore_placement() || explicit_defaults_)
267 {
268 set_attr( sym_node, "ignore-placement", sym.get_ignore_placement() );
269 }
89f6b32 @springmeyer apply patch from Herm from #553 adding support for markers_symbolizer…
springmeyer authored
270 if (sym.get_spacing() != dfl.get_spacing() || explicit_defaults_)
271 {
272 set_attr( sym_node, "spacing", sym.get_spacing() );
273 }
274 if (sym.get_max_error() != dfl.get_max_error() || explicit_defaults_)
275 {
154dc59 @springmeyer serialize all dashes, no underscores, as per #644
springmeyer authored
276 set_attr( sym_node, "max-error", sym.get_max_error() );
89f6b32 @springmeyer apply patch from Herm from #553 adding support for markers_symbolizer…
springmeyer authored
277 }
278 if (sym.get_fill() != dfl.get_fill() || explicit_defaults_)
279 {
280 set_attr( sym_node, "fill", sym.get_fill() );
281 }
f8b3a4b @springmeyer add serialization of all markers_symbolizer attributes
springmeyer authored
282 if (sym.get_opacity() != dfl.get_opacity() || explicit_defaults_)
283 {
284 set_attr( sym_node, "opacity", sym.get_opacity() );
285 }
c8b816e @springmeyer add missing serialization of marker width and height
springmeyer authored
286 if (sym.get_width() != dfl.get_width() || explicit_defaults_)
287 {
67e9b0d @springmeyer move marker width/height to expressions - closes #1102 and replaces #…
springmeyer authored
288 set_attr( sym_node, "width", to_expression_string(*sym.get_width()) );
c8b816e @springmeyer add missing serialization of marker width and height
springmeyer authored
289 }
290 if (sym.get_height() != dfl.get_height() || explicit_defaults_)
291 {
67e9b0d @springmeyer move marker width/height to expressions - closes #1102 and replaces #…
springmeyer authored
292 set_attr( sym_node, "height", to_expression_string(*sym.get_height()) );
c8b816e @springmeyer add missing serialization of marker width and height
springmeyer authored
293 }
f8b3a4b @springmeyer add serialization of all markers_symbolizer attributes
springmeyer authored
294 if (sym.get_marker_placement() != dfl.get_marker_placement() || explicit_defaults_)
295 {
296 set_attr( sym_node, "placement", sym.get_marker_placement() );
297 }
bd9609c @lightmare new feature: transform expressions are now dynamic
lightmare authored
298 if (sym.get_image_transform())
f8b3a4b @springmeyer add serialization of all markers_symbolizer attributes
springmeyer authored
299 {
bd9609c @lightmare new feature: transform expressions are now dynamic
lightmare authored
300 std::string tr_str = sym.get_image_transform_string();
5c91860 @springmeyer rename 'image-transform' to just 'transform' (for backward compatibil…
springmeyer authored
301 set_attr( sym_node, "transform", tr_str );
f8b3a4b @springmeyer add serialization of all markers_symbolizer attributes
springmeyer authored
302 }
b307013 @springmeyer add additional support for dynamically drawing ellipses in the marker…
springmeyer authored
303
9d75616 @artemp + update to work with optional stroke (markers)
artemp authored
304 boost::optional<stroke> const& strk = sym.get_stroke();
305 if (strk)
306 {
307 add_stroke_attributes(sym_node, *strk);
308 }
b307013 @springmeyer add additional support for dynamically drawing ellipses in the marker…
springmeyer authored
309
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
310 serialize_symbolizer_base(sym_node, sym);
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
311 }
312
95cfb06 @artemp + experimental compositing symbolizer (fill only)
artemp authored
313 template <typename Symbolizer>
314 void operator () ( Symbolizer const& sym)
315 {
316 // not-supported
317 #ifdef MAPNIK_DEBUG
ee7f72d @artemp + fix compilation issue
artemp authored
318 MAPNIK_LOG_WARN(save_map) << typeid(sym).name() << " is not supported";
95cfb06 @artemp + experimental compositing symbolizer (fill only)
artemp authored
319 #endif
320 }
9d75616 @artemp + update to work with optional stroke (markers)
artemp authored
321
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
322 private:
323 serialize_symbolizer();
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
324
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
325 void serialize_symbolizer_base(ptree & node, symbolizer_base const& sym)
326 {
327 symbolizer_base dfl = symbolizer_base();
328 if (!sym.get_metawriter_name().empty() || explicit_defaults_) {
329 set_attr(node, "meta-writer", sym.get_metawriter_name());
330 }
331 if (!sym.get_metawriter_properties_overrides().empty() || explicit_defaults_) {
332 set_attr(node, "meta-output", sym.get_metawriter_properties_overrides().to_string());
333 }
334 if (sym.get_transform())
335 {
336 std::string tr_str = sym.get_transform_string();
337 set_attr( node, "geometry-transform", tr_str );
338 }
339 if (sym.clip() != dfl.clip() || explicit_defaults_)
340 {
341 set_attr( node, "clip", sym.clip() );
342 }
343 if (sym.smooth() != dfl.smooth() || explicit_defaults_)
344 {
345 set_attr( node, "smooth", sym.smooth() );
346 }
347 if (sym.comp_op() != dfl.comp_op() || explicit_defaults_)
348 {
349 set_attr( node, "comp-op", *comp_op_to_string(sym.comp_op()) );
350 }
351 }
352
d05b0c5 @springmeyer apply major refactor of RasterColorizer by ben moores from https://gi…
springmeyer authored
353 void serialize_raster_colorizer(ptree & sym_node,
354 raster_colorizer_ptr const& colorizer,
355 bool explicit_defaults)
356 {
357 ptree & col_node = sym_node.push_back(
358 ptree::value_type("RasterColorizer", ptree() ))->second;
359
360 set_attr(col_node, "default-mode", colorizer->get_default_mode());
361 set_attr(col_node, "default-color", colorizer->get_default_color());
362 set_attr(col_node, "epsilon", colorizer->get_epsilon());
363
364 unsigned i;
365 colorizer_stops const &stops = colorizer->get_stops();
366 for (i=0; i<stops.size(); i++) {
367 ptree &stop_node = col_node.push_back( ptree::value_type("stop", ptree()) )->second;
368 set_attr(stop_node, "value", stops[i].get_value());
369 set_attr(stop_node, "color", stops[i].get_color());
370 set_attr(stop_node, "mode", stops[i].get_mode().as_string());
e41abb0 @albertov add a label attribute to colorizer_stop
albertov authored
371 if (stops[i].get_label()!=std::string(""))
372 set_attr(stop_node, "label", stops[i].get_label());
d05b0c5 @springmeyer apply major refactor of RasterColorizer by ben moores from https://gi…
springmeyer authored
373 }
374
375 }
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
376
c44b921 @springmeyer serialize all properties shared by all symbolizers
springmeyer authored
377 void add_image_attributes(ptree & node, symbolizer_with_image const& sym)
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
378 {
bd9609c @lightmare new feature: transform expressions are now dynamic
lightmare authored
379 if (sym.get_filename())
380 {
381 std::string filename = path_processor_type::to_string( *sym.get_filename());
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
382 set_attr( node, "file", filename );
383 }
ed22d07 @springmeyer fix serialization of missing shield symbolizer properties
springmeyer authored
384 if (sym.get_opacity() != 1.0 || explicit_defaults_ )
385 {
386 set_attr( node, "opacity", sym.get_opacity() );
387 }
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
388 }
bd9609c @lightmare new feature: transform expressions are now dynamic
lightmare authored
389
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
390 void add_font_attributes(ptree & node, const text_symbolizer & sym)
391 {
af42e2d @herm Update save_map.cpp.
herm authored
392 text_placements_ptr p = sym.get_placement_options();
819ee98 @herm Rename properties=>defauls, default_format=>format.
herm authored
393 p->defaults.to_xml(node, explicit_defaults_);
af42e2d @herm Update save_map.cpp.
herm authored
394 /* Known types:
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
395 - text_placements_dummy: no handling required
396 - text_placements_simple: positions string
397 - text_placements_list: list string
398 */
af42e2d @herm Update save_map.cpp.
herm authored
399 text_placements_simple *simple = dynamic_cast<text_placements_simple *>(p.get());
400 text_placements_list *list = dynamic_cast<text_placements_list *>(p.get());
401 if (simple) {
819ee98 @herm Rename properties=>defauls, default_format=>format.
herm authored
402 set_attr(node, "placement-type", "simple");
af42e2d @herm Update save_map.cpp.
herm authored
403 set_attr(node, "placements", simple->get_positions());
404 }
405 if (list) {
819ee98 @herm Rename properties=>defauls, default_format=>format.
herm authored
406 set_attr(node, "placement-type", "list");
af42e2d @herm Update save_map.cpp.
herm authored
407 unsigned i;
819ee98 @herm Rename properties=>defauls, default_format=>format.
herm authored
408 //dfl = last properties passed as default so only attributes that change are actually written
409 text_symbolizer_properties *dfl = &(list->defaults);
af42e2d @herm Update save_map.cpp.
herm authored
410 for (i=0; i < list->size(); i++) {
411 ptree &placement_node = node.push_back(ptree::value_type("Placement", ptree()))->second;
412 list->get(i).to_xml(placement_node, explicit_defaults_, *dfl);
413 dfl = &(list->get(i));
414 }
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
415 }
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
416 }
24fb874 @herm Add metawriter support to save_map.cpp
herm authored
417
1fcb0ee @springmeyer serialize stroke separately from line_symbolizer, setting up for othe…
springmeyer authored
418 void add_stroke_attributes(ptree & node, const stroke & strk)
419 {
420
421 stroke dfl = stroke();
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
422
1fcb0ee @springmeyer serialize stroke separately from line_symbolizer, setting up for othe…
springmeyer authored
423 if ( strk.get_color() != dfl.get_color() || explicit_defaults_ )
424 {
425 set_attr( node, "stroke", strk.get_color() );
426 }
427 if ( strk.get_width() != dfl.get_width() || explicit_defaults_ )
428 {
429 set_attr( node, "stroke-width", strk.get_width() );
430 }
431 if ( strk.get_opacity() != dfl.get_opacity() || explicit_defaults_ )
432 {
433 set_attr( node, "stroke-opacity", strk.get_opacity() );
434 }
435 if ( strk.get_line_join() != dfl.get_line_join() || explicit_defaults_ )
436 {
437 set_attr( node, "stroke-linejoin", strk.get_line_join() );
438 }
439 if ( strk.get_line_cap() != dfl.get_line_cap() || explicit_defaults_ )
440 {
441 set_attr( node, "stroke-linecap", strk.get_line_cap() );
442 }
fd2d9d7 @springmeyer enable aliased lines using stroke-gamma for line_symbolizer - closes …
springmeyer authored
443 if ( strk.get_gamma() != dfl.get_gamma() || explicit_defaults_ )
444 {
445 set_attr( node, "stroke-gamma", strk.get_gamma());
446 }
93ff232 @tarnowsc #1023 making gamma power default, making gamma-method awailable for p…
tarnowsc authored
447 if ( strk.get_gamma_method() != dfl.get_gamma_method() || explicit_defaults_ )
448 {
449 set_attr( node, "stroke-gamma-method", strk.get_gamma_method() );
450 }
fd2d9d7 @springmeyer enable aliased lines using stroke-gamma for line_symbolizer - closes …
springmeyer authored
451 if ( strk.dash_offset() != dfl.dash_offset() || explicit_defaults_ )
452 {
9458e2d @springmeyer stroke-dash-offet -> stroke-dash-offset (spelling)- #762
springmeyer authored
453 set_attr( node, "stroke-dash-offset", strk.dash_offset());
fd2d9d7 @springmeyer enable aliased lines using stroke-gamma for line_symbolizer - closes …
springmeyer authored
454 }
1fcb0ee @springmeyer serialize stroke separately from line_symbolizer, setting up for othe…
springmeyer authored
455 if ( ! strk.get_dash_array().empty() )
456 {
457 std::ostringstream os;
458 const dash_array & dashes = strk.get_dash_array();
459 for (unsigned i = 0; i < dashes.size(); ++i) {
460 os << dashes[i].first << ", " << dashes[i].second;
461 if ( i + 1 < dashes.size() ) os << ", ";
462 }
463 set_attr( node, "stroke-dasharray", os.str() );
464 }
465 }
bd9609c @lightmare new feature: transform expressions are now dynamic
lightmare authored
466
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
467 ptree & rule_;
468 bool explicit_defaults_;
469 };
470
98b7f62 @artemp + remove template from mapnik::rule
artemp authored
471 void serialize_rule( ptree & style_node, const rule & r, bool explicit_defaults)
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
472 {
473 ptree & rule_node = style_node.push_back(
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
474 ptree::value_type("Rule", ptree() ))->second;
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
475
98b7f62 @artemp + remove template from mapnik::rule
artemp authored
476 rule dfl;
477 if ( r.get_name() != dfl.get_name() )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
478 {
98b7f62 @artemp + remove template from mapnik::rule
artemp authored
479 set_attr(rule_node, "name", r.get_name());
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
480 }
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
481
98b7f62 @artemp + remove template from mapnik::rule
artemp authored
482 if ( r.has_else_filter() )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
483 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
484 rule_node.push_back( ptree::value_type(
485 "ElseFilter", ptree()));
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
486 }
9e87c9f @springmeyer apply patch from Peter Körner adding AlsoFilter functionality - close…
springmeyer authored
487 else if ( r.has_also_filter() )
488 {
489 rule_node.push_back( ptree::value_type(
490 "AlsoFilter", ptree()));
491 }
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
492 else
493 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
494 // filters were not comparable, perhaps should now compare expressions?
98b7f62 @artemp + remove template from mapnik::rule
artemp authored
495 expression_ptr const& expr = r.get_filter();
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
496 std::string filter = mapnik::to_expression_string(*expr);
497 std::string default_filter = mapnik::to_expression_string(*dfl.get_filter());
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
498
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
499 if ( filter != default_filter)
500 {
501 rule_node.push_back( ptree::value_type(
502 "Filter", ptree()))->second.put_value( filter );
503 }
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
504 }
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
505
98b7f62 @artemp + remove template from mapnik::rule
artemp authored
506 if (r.get_min_scale() != dfl.get_min_scale() )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
507 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
508 ptree & min_scale = rule_node.push_back( ptree::value_type(
509 "MinScaleDenominator", ptree()))->second;
98b7f62 @artemp + remove template from mapnik::rule
artemp authored
510 min_scale.put_value( r.get_min_scale() );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
511 }
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
512
98b7f62 @artemp + remove template from mapnik::rule
artemp authored
513 if (r.get_max_scale() != dfl.get_max_scale() )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
514 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
515 ptree & max_scale = rule_node.push_back( ptree::value_type(
516 "MaxScaleDenominator", ptree()))->second;
98b7f62 @artemp + remove template from mapnik::rule
artemp authored
517 max_scale.put_value( r.get_max_scale() );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
518 }
519
98b7f62 @artemp + remove template from mapnik::rule
artemp authored
520 rule::symbolizers::const_iterator begin = r.get_symbolizers().begin();
521 rule::symbolizers::const_iterator end = r.get_symbolizers().end();
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
522 serialize_symbolizer serializer( rule_node, explicit_defaults);
523 std::for_each( begin, end , boost::apply_visitor( serializer ));
524 }
525
526 void serialize_style( ptree & map_node, Map::const_style_iterator style_it, bool explicit_defaults )
527 {
7163806 @springmeyer c++ style
springmeyer authored
528 feature_type_style const& style = style_it->second;
529 std::string const& name = style_it->first;
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
530
531 ptree & style_node = map_node.push_back(
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
532 ptree::value_type("Style", ptree()))->second;
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
533
534 set_attr(style_node, "name", name);
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
535
7043c41 @springmeyer enable if/else type behavior in rules using style level keyword to co…
springmeyer authored
536 feature_type_style dfl;
48a543b @springmeyer implement style-level opacity - closes #314
springmeyer authored
537 filter_mode_e filter_mode = style.get_filter_mode();
7043c41 @springmeyer enable if/else type behavior in rules using style level keyword to co…
springmeyer authored
538 if (filter_mode != dfl.get_filter_mode() || explicit_defaults)
539 {
540 set_attr(style_node, "filter-mode", filter_mode);
541 }
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
542
48a543b @springmeyer implement style-level opacity - closes #314
springmeyer authored
543 double opacity = style.get_opacity();
544 if (opacity != dfl.get_opacity() || explicit_defaults)
545 {
546 set_attr(style_node, "opacity", opacity);
547 }
548
2f45de8 @springmeyer serialize comp-op in save_map - refs #1292
springmeyer authored
549 boost::optional<composite_mode_e> comp_op = style.comp_op();
550 if (comp_op)
551 {
552 set_attr(style_node, "comp-op", *comp_op_to_string(*comp_op));
553 }
554 else if (explicit_defaults)
555 {
556 set_attr(style_node, "comp-op", "src-over");
557 }
558
216768f @artemp + output image-filters and direct-image-filters
artemp authored
559 if (style.image_filters().size() > 0)
560 {
561 std::string filters_str;
562 std::back_insert_iterator<std::string> sink(filters_str);
563 if (generate_image_filters(sink, style.image_filters()))
564 {
565 set_attr(style_node, "image-filters", filters_str);
566 }
567 }
568
569 if (style.direct_image_filters().size() > 0)
570 {
571 std::string filters_str;
572 std::back_insert_iterator<std::string> sink(filters_str);
573 if (generate_image_filters(sink, style.direct_image_filters()))
574 {
575 set_attr(style_node, "direct-image-filters", filters_str);
576 }
577 }
578
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
579 rules::const_iterator it = style.get_rules().begin();
580 rules::const_iterator end = style.get_rules().end();
581 for (; it != end; ++it)
582 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
583 serialize_rule( style_node, * it , explicit_defaults);
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
584 }
585
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
586 }
587
588 void serialize_fontset( ptree & map_node, Map::const_fontset_iterator fontset_it )
589 {
7163806 @springmeyer c++ style
springmeyer authored
590 font_set const& fontset = fontset_it->second;
591 std::string const& name = fontset_it->first;
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
592
593 ptree & fontset_node = map_node.push_back(
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
594 ptree::value_type("FontSet", ptree()))->second;
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
595
596 set_attr(fontset_node, "name", name);
597
598 std::vector<std::string>::const_iterator it = fontset.get_face_names().begin();
599 std::vector<std::string>::const_iterator end = fontset.get_face_names().end();
600 for (; it != end; ++it)
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
601 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
602 ptree & font_node = fontset_node.push_back(
603 ptree::value_type("Font", ptree()))->second;
154dc59 @springmeyer serialize all dashes, no underscores, as per #644
springmeyer authored
604 set_attr(font_node, "face-name", *it);
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
605 }
a3a5859 @artemp Patch from David Eastcott :
artemp authored
606
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
607 }
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
608
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
609 void serialize_datasource( ptree & layer_node, datasource_ptr datasource)
610 {
611 ptree & datasource_node = layer_node.push_back(
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
612 ptree::value_type("Datasource", ptree()))->second;
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
613
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
614 parameters::const_iterator it = datasource->params().begin();
615 parameters::const_iterator end = datasource->params().end();
616 for (; it != end; ++it)
617 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
618 boost::property_tree::ptree & param_node = datasource_node.push_back(
619 boost::property_tree::ptree::value_type("Parameter",
620 boost::property_tree::ptree()))->second;
621 param_node.put("<xmlattr>.name", it->first );
622 param_node.put_value( it->second );
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
623
624 }
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
625 }
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
626
9e924bf @springmeyer add ability to have typed arbitrary parameters in xml - refs #977
springmeyer authored
627 class serialize_type : public boost::static_visitor<>
628 {
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
629 public:
9e924bf @springmeyer add ability to have typed arbitrary parameters in xml - refs #977
springmeyer authored
630 serialize_type( boost::property_tree::ptree & node):
631 node_(node) {}
632
633 void operator () ( int val ) const
634 {
635 node_.put("<xmlattr>.type", "int" );
636 }
637
638 void operator () ( double val ) const
639 {
640 node_.put("<xmlattr>.type", "float" );
641 }
642
643 void operator () ( std::string const& val ) const
644 {
645 node_.put("<xmlattr>.type", "string" );
646 }
647
648 void operator () ( mapnik::value_null val ) const
649 {
650 node_.put("<xmlattr>.type", "string" );
651 }
652
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
653 private:
9e924bf @springmeyer add ability to have typed arbitrary parameters in xml - refs #977
springmeyer authored
654 boost::property_tree::ptree & node_;
655 };
656
60de1c8 @springmeyer add support for arbitrary, custom parameters to be attached to the ma…
springmeyer authored
657 void serialize_parameters( ptree & map_node, mapnik::parameters const& params)
658 {
410dea5 @springmeyer only serialize Parameters if one or more exist
springmeyer authored
659 if (params.size()) {
660 ptree & params_node = map_node.push_back(
661 ptree::value_type("Parameters", ptree()))->second;
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
662
410dea5 @springmeyer only serialize Parameters if one or more exist
springmeyer authored
663 parameters::const_iterator it = params.begin();
664 parameters::const_iterator end = params.end();
665 for (; it != end; ++it)
666 {
667 boost::property_tree::ptree & param_node = params_node.push_back(
668 boost::property_tree::ptree::value_type("Parameter",
669 boost::property_tree::ptree()))->second;
670 param_node.put("<xmlattr>.name", it->first );
671 param_node.put_value( it->second );
672 boost::apply_visitor(serialize_type(param_node),it->second);
673 }
60de1c8 @springmeyer add support for arbitrary, custom parameters to be attached to the ma…
springmeyer authored
674 }
675 }
676
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
677 void serialize_layer( ptree & map_node, const layer & layer, bool explicit_defaults )
678 {
679 ptree & layer_node = map_node.push_back(
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
680 ptree::value_type("Layer", ptree()))->second;
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
681
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
682 if ( layer.name() != "" )
387ff21 @artemp + mapnik-serialize-fontset.patch from jonb
artemp authored
683 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
684 set_attr( layer_node, "name", layer.name() );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
685 }
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
686
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
687 if ( layer.srs() != "" )
688 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
689 set_attr( layer_node, "srs", layer.srs() );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
690 }
691
207ecfd @artemp remove camel-case names from layer.[h,c]pp
artemp authored
692 if ( !layer.active() || explicit_defaults )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
693 {
207ecfd @artemp remove camel-case names from layer.[h,c]pp
artemp authored
694 set_attr/*<bool>*/( layer_node, "status", layer.active() );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
695 }
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
696
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
697 if ( layer.clear_label_cache() || explicit_defaults )
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
698 {
154dc59 @springmeyer serialize all dashes, no underscores, as per #644
springmeyer authored
699 set_attr/*<bool>*/( layer_node, "clear-label-cache", layer.clear_label_cache() );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
700 }
387ff21 @artemp + mapnik-serialize-fontset.patch from jonb
artemp authored
701
207ecfd @artemp remove camel-case names from layer.[h,c]pp
artemp authored
702 if ( layer.min_zoom() )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
703 {
207ecfd @artemp remove camel-case names from layer.[h,c]pp
artemp authored
704 set_attr( layer_node, "minzoom", layer.min_zoom() );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
705 }
387ff21 @artemp + mapnik-serialize-fontset.patch from jonb
artemp authored
706
207ecfd @artemp remove camel-case names from layer.[h,c]pp
artemp authored
707 if ( layer.max_zoom() != std::numeric_limits<double>::max() )
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
708 {
207ecfd @artemp remove camel-case names from layer.[h,c]pp
artemp authored
709 set_attr( layer_node, "maxzoom", layer.max_zoom() );
387ff21 @artemp + mapnik-serialize-fontset.patch from jonb
artemp authored
710 }
711
207ecfd @artemp remove camel-case names from layer.[h,c]pp
artemp authored
712 if ( layer.queryable() || explicit_defaults )
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
713 {
207ecfd @artemp remove camel-case names from layer.[h,c]pp
artemp authored
714 set_attr( layer_node, "queryable", layer.queryable() );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
715 }
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
716
4079fd7 @springmeyer make feature caching optional, and disabled by default (to avoid std:…
springmeyer authored
717 if ( layer.cache_features() || explicit_defaults )
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
718 {
4079fd7 @springmeyer make feature caching optional, and disabled by default (to avoid std:…
springmeyer authored
719 set_attr/*<bool>*/( layer_node, "cache-features", layer.cache_features() );
720 }
721
763ece8 @kkaefer group-by attribute for Layer
kkaefer authored
722 if ( layer.group_by() != "" || explicit_defaults )
723 {
724 set_attr( layer_node, "group-by", layer.group_by() );
725 }
726
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
727 std::vector<std::string> const& style_names = layer.styles();
728 for (unsigned i = 0; i < style_names.size(); ++i)
729 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
730 boost::property_tree::ptree & style_node = layer_node.push_back(
731 boost::property_tree::ptree::value_type("StyleName",
732 boost::property_tree::ptree()))->second;
733 style_node.put_value( style_names[i] );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
734 }
a3a5859 @artemp Patch from David Eastcott :
artemp authored
735
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
736 datasource_ptr datasource = layer.datasource();
737 if ( datasource )
738 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
739 serialize_datasource( layer_node, datasource );
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
740 }
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
741 }
742
24fb874 @herm Add metawriter support to save_map.cpp
herm authored
743 void serialize_metawriter(ptree & map_node, Map::const_metawriter_iterator metawriter_it, bool explicit_defaults)
744 {
745 std::string const& name = metawriter_it->first;
746 metawriter_ptr const& metawriter = metawriter_it->second;
747
748 ptree & metawriter_node = map_node.push_back(
749 ptree::value_type("MetaWriter", ptree()))->second;
750
751 set_attr(metawriter_node, "name", name);
e580078 @artemp + apply MetaWriter patch from zerebubuth
artemp authored
752 metawriter_save(metawriter, metawriter_node, explicit_defaults);
24fb874 @herm Add metawriter support to save_map.cpp
herm authored
753 }
754
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
755 void serialize_map(ptree & pt, Map const & map, bool explicit_defaults)
756 {
757
758 ptree & map_node = pt.push_back(ptree::value_type("Map", ptree() ))->second;
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
759
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
760 set_attr( map_node, "srs", map.srs() );
761
8b8e247 @artemp + add support for background-image attribute
artemp authored
762 optional<color> const& c = map.background();
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
763 if ( c )
b2df387 - merged strict-xml-branch r530:532 to trunk:
David authored
764 {
91a1091 @artemp + align attribute names with W3C standards
artemp authored
765 set_attr( map_node, "background-color", * c );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
766 }
68e784d @springmeyer + add load_map() and save_map() support for reading and writing of ab…
springmeyer authored
767
8b8e247 @artemp + add support for background-image attribute
artemp authored
768 optional<std::string> const& image_filename = map.background_image();
769 if ( image_filename )
770 {
771 set_attr( map_node, "background-image", *image_filename );
772 }
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
773
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
774 unsigned buffer_size = map.buffer_size();
775 if ( buffer_size || explicit_defaults)
776 {
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
777 set_attr( map_node, "buffer-size", buffer_size );
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
778 }
7a17c7e @springmeyer load_map_from_string has always accepted a base path argument to driv…
springmeyer authored
779
780 std::string const& base_path = map.base_path();
781 if ( !base_path.empty() || explicit_defaults)
782 {
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
783 set_attr( map_node, "base", base_path );
7a17c7e @springmeyer load_map_from_string has always accepted a base path argument to driv…
springmeyer authored
784 }
68e784d @springmeyer + add load_map() and save_map() support for reading and writing of ab…
springmeyer authored
785
7570cb5 @springmeyer load and save the new map 'maximum-extent' attribute
springmeyer authored
786 optional<box2d<double> > const& maximum_extent = map.maximum_extent();
787 if ( maximum_extent)
788 {
789 std::ostringstream s;
790 s << std::setprecision(16)
791 << maximum_extent->minx() << "," << maximum_extent->miny() << ","
792 << maximum_extent->maxx() << "," << maximum_extent->maxy();
17d13cf @springmeyer whitespace fixes - closes #911
springmeyer authored
793 set_attr( map_node, "maximum-extent", s.str() );
7570cb5 @springmeyer load and save the new map 'maximum-extent' attribute
springmeyer authored
794 }
795
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
796 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
797 Map::const_fontset_iterator it = map.fontsets().begin();
798 Map::const_fontset_iterator end = map.fontsets().end();
799 for (; it != end; ++it)
800 {
801 serialize_fontset( map_node, it);
802 }
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
803 }
68e784d @springmeyer + add load_map() and save_map() support for reading and writing of ab…
springmeyer authored
804
60de1c8 @springmeyer add support for arbitrary, custom parameters to be attached to the ma…
springmeyer authored
805 serialize_parameters( map_node, map.get_extra_parameters());
688b1f2 @springmeyer add an 'extra_attributes' property to the map to store mapnik::parame…
springmeyer authored
806
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
807 Map::const_style_iterator it = map.styles().begin();
808 Map::const_style_iterator end = map.styles().end();
809 for (; it != end; ++it)
810 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
811 serialize_style( map_node, it, explicit_defaults);
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
812 }
a3a5859 @artemp Patch from David Eastcott :
artemp authored
813
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
814 std::vector<layer> const & layers = map.layers();
815 for (unsigned i = 0; i < layers.size(); ++i )
816 {
2467318 @artemp + apply 'mapnik-format' to *.cpp *.hpp
artemp authored
817 serialize_layer( map_node, layers[i], explicit_defaults );
286ad12 @springmeyer add method to save a map to a string (closes #396)
springmeyer authored
818 }
24fb874 @herm Add metawriter support to save_map.cpp
herm authored
819
820 Map::const_metawriter_iterator m_it = map.begin_metawriters();
821 Map::const_metawriter_iterator m_end = map.end_metawriters();
822 for (; m_it != m_end; ++m_it) {
823 serialize_metawriter(map_node, m_it, explicit_defaults);
824 }
5fcc311 @artemp + add stroke-dashoffset property
artemp authored
825 }
826
827 void save_map(Map const & map, std::string const& filename, bool explicit_defaults)
828 {
829 ptree pt;
830 serialize_map(pt,map,explicit_defaults);
831 write_xml(filename,pt,std::locale(),boost::property_tree::xml_writer_make_settings(' ',4));
832 }
833
834 std::string save_map_to_string(Map const & map, bool explicit_defaults)
835 {
836 ptree pt;
837 serialize_map(pt,map,explicit_defaults);
838 std::ostringstream ss;
839 write_xml(ss,pt,boost::property_tree::xml_writer_make_settings(' ',4));
840 return ss.str();
841 }
286ad12 @springmeyer add method to save a map to a string (closes #396)
springmeyer authored
842
88892c1 @artemp added save/load functionality based on boost::property_tree (aka Elem…
artemp authored
843 }
Something went wrong with that request. Please try again.