2006-10-03 10:39:43 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Artem Pavlenko
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2006-10-04 13:22:18 +02:00
|
|
|
// $Id$
|
2007-10-08 19:42:41 +02:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/save_map.hpp>
|
2009-05-20 00:59:56 +02:00
|
|
|
#include <mapnik/image_util.hpp>
|
2007-10-08 19:42:41 +02:00
|
|
|
#include <mapnik/ptree_helpers.hpp>
|
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
// boost
|
2006-10-03 10:39:43 +02:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <boost/tokenizer.hpp>
|
2007-09-25 20:47:12 +02:00
|
|
|
#include <boost/optional.hpp>
|
2006-10-03 10:39:43 +02:00
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
#include <boost/property_tree/xml_parser.hpp>
|
2007-10-08 19:42:41 +02:00
|
|
|
|
|
|
|
// stl
|
|
|
|
#include <iostream>
|
2006-10-03 10:39:43 +02:00
|
|
|
|
|
|
|
namespace mapnik
|
|
|
|
{
|
2007-09-25 20:47:12 +02:00
|
|
|
using boost::property_tree::ptree;
|
|
|
|
using boost::optional;
|
|
|
|
|
|
|
|
class serialize_symbolizer : public boost::static_visitor<>
|
|
|
|
{
|
|
|
|
public:
|
2009-04-28 23:44:34 +02:00
|
|
|
serialize_symbolizer( ptree & r , bool explicit_defaults):
|
|
|
|
rule_(r),
|
|
|
|
explicit_defaults_(explicit_defaults) {}
|
2007-09-25 20:47:12 +02:00
|
|
|
|
|
|
|
void operator () ( const point_symbolizer & sym )
|
|
|
|
{
|
|
|
|
ptree & sym_node = rule_.push_back(
|
|
|
|
ptree::value_type("PointSymbolizer", ptree()))->second;
|
|
|
|
|
|
|
|
add_image_attributes( sym_node, sym );
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator () ( const line_symbolizer & sym )
|
|
|
|
{
|
|
|
|
ptree & sym_node = rule_.push_back(
|
|
|
|
ptree::value_type("LineSymbolizer", ptree()))->second;
|
|
|
|
const stroke & strk = sym.get_stroke();
|
|
|
|
stroke dfl = stroke();
|
|
|
|
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( strk.get_color() != dfl.get_color() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_css( sym_node, "stroke", strk.get_color() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( strk.get_width() != dfl.get_width() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_css( sym_node, "stroke-width", strk.get_width() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( strk.get_opacity() != dfl.get_opacity() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_css( sym_node, "stroke-opacity", strk.get_opacity() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( strk.get_line_join() != dfl.get_line_join() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_css( sym_node, "stroke-linejoin", strk.get_line_join() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( strk.get_line_cap() != dfl.get_line_cap() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_css( sym_node, "stroke-linecap", strk.get_line_cap() );
|
|
|
|
}
|
|
|
|
if ( ! strk.get_dash_array().empty() )
|
|
|
|
{
|
|
|
|
std::ostringstream os;
|
|
|
|
const dash_array & dashes = strk.get_dash_array();
|
|
|
|
for (unsigned i = 0; i < dashes.size(); ++i) {
|
|
|
|
os << dashes[i].first << ", " << dashes[i].second;
|
|
|
|
if ( i + 1 < dashes.size() ) os << ", ";
|
|
|
|
}
|
|
|
|
set_css( sym_node, "stroke-dasharray", os.str() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator () ( const line_pattern_symbolizer & sym )
|
|
|
|
{
|
|
|
|
ptree & sym_node = rule_.push_back(
|
|
|
|
ptree::value_type("LinePatternSymbolizer",
|
|
|
|
ptree()))->second;
|
|
|
|
|
|
|
|
add_image_attributes( sym_node, sym );
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator () ( const polygon_symbolizer & sym )
|
|
|
|
{
|
|
|
|
ptree & sym_node = rule_.push_back(
|
|
|
|
ptree::value_type("PolygonSymbolizer", ptree()))->second;
|
|
|
|
polygon_symbolizer dfl;
|
|
|
|
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( sym.get_fill() != dfl.get_fill() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_css( sym_node, "fill", sym.get_fill() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( sym.get_opacity() != dfl.get_opacity() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
2009-01-21 16:41:44 +01:00
|
|
|
set_css( sym_node, "fill-opacity", sym.get_opacity() );
|
2007-09-25 20:47:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator () ( const polygon_pattern_symbolizer & sym )
|
|
|
|
{
|
|
|
|
ptree & sym_node = rule_.push_back(
|
|
|
|
ptree::value_type("PolygonPatternSymbolizer",
|
|
|
|
ptree()))->second;
|
|
|
|
|
|
|
|
add_image_attributes( sym_node, sym );
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator () ( const raster_symbolizer & sym )
|
|
|
|
{
|
2009-03-29 13:05:20 +02:00
|
|
|
ptree & sym_node = rule_.push_back(
|
|
|
|
ptree::value_type("RasterSymbolizer", ptree()))->second;
|
|
|
|
raster_symbolizer dfl;
|
|
|
|
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( sym.get_mode() != dfl.get_mode() || explicit_defaults_ )
|
2009-03-29 13:05:20 +02:00
|
|
|
{
|
|
|
|
set_css( sym_node, "mode", sym.get_mode() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( sym.get_scaling() != dfl.get_scaling() || explicit_defaults_ )
|
2009-03-29 13:05:20 +02:00
|
|
|
{
|
|
|
|
set_css( sym_node, "scaling", sym.get_scaling() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( sym.get_opacity() != dfl.get_opacity() || explicit_defaults_ )
|
2009-03-29 13:05:20 +02:00
|
|
|
{
|
|
|
|
set_css( sym_node, "opacity", sym.get_opacity() );
|
|
|
|
}
|
2007-09-25 20:47:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator () ( const shield_symbolizer & sym )
|
|
|
|
{
|
|
|
|
ptree & sym_node = rule_.push_back(
|
|
|
|
ptree::value_type("ShieldSymbolizer",
|
|
|
|
ptree()))->second;
|
|
|
|
|
|
|
|
add_font_attributes( sym_node, sym);
|
|
|
|
add_image_attributes( sym_node, sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator () ( const text_symbolizer & sym )
|
|
|
|
{
|
|
|
|
ptree & sym_node = rule_.push_back(
|
|
|
|
ptree::value_type("TextSymbolizer",
|
|
|
|
ptree()))->second;
|
|
|
|
|
|
|
|
add_font_attributes( sym_node, sym);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator () ( const building_symbolizer & sym )
|
|
|
|
{
|
|
|
|
ptree & sym_node = rule_.push_back(
|
|
|
|
ptree::value_type("BuildingSymbolizer", ptree()))->second;
|
|
|
|
building_symbolizer dfl;
|
|
|
|
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( sym.get_fill() != dfl.get_fill() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_css( sym_node, "fill", sym.get_fill() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( sym.get_opacity() != dfl.get_opacity() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_css( sym_node, "fill-opacity", sym.get_opacity() );
|
|
|
|
}
|
2009-07-24 08:10:42 +02:00
|
|
|
if ( sym.height() != dfl.height() || explicit_defaults_ )
|
|
|
|
{
|
|
|
|
set_css( sym_node, "height", sym.height() );
|
|
|
|
}
|
2007-09-25 20:47:12 +02:00
|
|
|
}
|
2007-11-02 13:50:15 +01:00
|
|
|
|
|
|
|
void operator () ( markers_symbolizer const& )
|
|
|
|
{
|
|
|
|
// FIXME!!!!!
|
|
|
|
}
|
2007-09-25 20:47:12 +02:00
|
|
|
private:
|
|
|
|
serialize_symbolizer();
|
|
|
|
void add_image_attributes(ptree & node, const symbolizer_with_image & sym)
|
|
|
|
{
|
|
|
|
const std::string & filename = sym.get_filename();
|
|
|
|
if ( ! filename.empty() ) {
|
|
|
|
set_attr( node, "file", filename );
|
|
|
|
set_attr( node, "type", guess_type( filename ) );
|
|
|
|
|
|
|
|
boost::shared_ptr<ImageData32> img = sym.get_image();
|
|
|
|
if ( img )
|
|
|
|
{
|
|
|
|
if ( img->width() > 0)
|
|
|
|
{
|
|
|
|
set_attr( node, "width", img->width() );
|
|
|
|
}
|
|
|
|
if ( img->height() > 0)
|
|
|
|
{
|
|
|
|
set_attr( node, "height", img->height() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void add_font_attributes(ptree & node, const text_symbolizer & sym)
|
|
|
|
{
|
|
|
|
const std::string & name = sym.get_name();
|
|
|
|
if ( ! name.empty() ) {
|
|
|
|
set_attr( node, "name", name );
|
|
|
|
}
|
|
|
|
const std::string & face_name = sym.get_face_name();
|
|
|
|
if ( ! face_name.empty() ) {
|
|
|
|
set_attr( node, "face_name", face_name );
|
|
|
|
}
|
2009-01-17 21:18:41 +01:00
|
|
|
const std::string & fontset_name = sym.get_fontset().get_name();
|
|
|
|
if ( ! fontset_name.empty() ) {
|
|
|
|
set_attr( node, "fontset_name", fontset_name );
|
|
|
|
}
|
|
|
|
|
2007-09-25 20:47:12 +02:00
|
|
|
set_attr( node, "size", sym.get_text_size() );
|
|
|
|
set_attr( node, "fill", sym.get_fill() );
|
|
|
|
|
|
|
|
// pseudo-default-construct a text_symbolizer. It is used
|
|
|
|
// to avoid printing ofattributes with default values without
|
|
|
|
// repeating the default values here.
|
|
|
|
// maybe add a real, explicit default-ctor?
|
|
|
|
text_symbolizer dfl("<no default>", "<no default>",
|
2009-01-14 13:10:24 +01:00
|
|
|
0, color(0,0,0) );
|
2007-09-25 20:47:12 +02:00
|
|
|
|
|
|
|
position displacement = sym.get_displacement();
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( displacement.get<0>() != dfl.get_displacement().get<0>() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_attr( node, "dx", displacement.get<0>() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( displacement.get<1>() != dfl.get_displacement().get<1>() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_attr( node, "dy", displacement.get<1>() );
|
|
|
|
}
|
|
|
|
|
2009-04-28 23:44:34 +02:00
|
|
|
if (sym.get_label_placement() != dfl.get_label_placement() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_attr( node, "placement", sym.get_label_placement() );
|
|
|
|
}
|
2009-03-30 22:47:26 +02:00
|
|
|
|
2009-04-28 23:44:34 +02:00
|
|
|
if (sym.get_vertical_alignment() != dfl.get_vertical_alignment() || explicit_defaults_ )
|
2009-03-30 22:47:26 +02:00
|
|
|
{
|
|
|
|
set_attr( node, "vertical_alignment", sym.get_vertical_alignment() );
|
|
|
|
}
|
|
|
|
|
2009-04-28 23:44:34 +02:00
|
|
|
if (sym.get_halo_radius() != dfl.get_halo_radius() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_attr( node, "halo_radius", sym.get_halo_radius() );
|
|
|
|
}
|
2009-01-14 13:10:24 +01:00
|
|
|
const color & c = sym.get_halo_fill();
|
2009-04-28 23:44:34 +02:00
|
|
|
if ( c != dfl.get_halo_fill() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_attr( node, "halo_fill", c );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if (sym.get_text_ratio() != dfl.get_text_ratio() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_attr( node, "text_ratio", sym.get_text_ratio() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if (sym.get_wrap_width() != dfl.get_wrap_width() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_attr( node, "wrap_width", sym.get_wrap_width() );
|
|
|
|
}
|
2009-07-20 17:30:19 +02:00
|
|
|
if (sym.get_wrap_char() != dfl.get_wrap_char() || explicit_defaults_ )
|
|
|
|
{
|
|
|
|
set_attr( node, "wrap_character", std::string(1, sym.get_wrap_char()) );
|
|
|
|
}
|
|
|
|
if (sym.get_text_convert() != dfl.get_text_convert() || explicit_defaults_ )
|
|
|
|
{
|
|
|
|
set_attr( node, "text_convert", sym.get_text_convert() );
|
|
|
|
}
|
|
|
|
if (sym.get_line_spacing() != dfl.get_line_spacing() || explicit_defaults_ )
|
|
|
|
{
|
|
|
|
set_attr( node, "line_spacing", sym.get_line_spacing() );
|
|
|
|
}
|
|
|
|
if (sym.get_character_spacing() != dfl.get_character_spacing() || explicit_defaults_ )
|
|
|
|
{
|
|
|
|
set_attr( node, "character_spacing", sym.get_character_spacing() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if (sym.get_label_spacing() != dfl.get_label_spacing() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_attr( node, "spacing", sym.get_label_spacing() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if (sym.get_minimum_distance() != dfl.get_minimum_distance() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_attr( node, "min_distance", sym.get_minimum_distance() );
|
|
|
|
}
|
2009-04-28 23:44:34 +02:00
|
|
|
if (sym.get_allow_overlap() != dfl.get_allow_overlap() || explicit_defaults_ )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
set_attr( node, "allow_overlap", sym.get_allow_overlap() );
|
|
|
|
}
|
2009-06-25 22:06:01 +02:00
|
|
|
if (sym.get_avoid_edges() != dfl.get_avoid_edges() || explicit_defaults_ )
|
|
|
|
{
|
|
|
|
set_attr( node, "avoid_edges", sym.get_avoid_edges() );
|
|
|
|
}
|
2007-09-25 20:47:12 +02:00
|
|
|
}
|
|
|
|
ptree & rule_;
|
2009-04-28 23:44:34 +02:00
|
|
|
bool explicit_defaults_;
|
2007-09-25 20:47:12 +02:00
|
|
|
};
|
|
|
|
|
2009-04-28 23:44:34 +02:00
|
|
|
void serialize_rule( ptree & style_node, const rule_type & rule, bool explicit_defaults)
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
ptree & rule_node = style_node.push_back(
|
|
|
|
ptree::value_type("Rule", ptree() ))->second;
|
|
|
|
|
|
|
|
rule_type dfl;
|
|
|
|
if ( rule.get_name() != dfl.get_name() )
|
|
|
|
{
|
|
|
|
set_attr(rule_node, "name", rule.get_name());
|
|
|
|
}
|
|
|
|
if ( rule.get_title() != dfl.get_title() )
|
|
|
|
{
|
|
|
|
set_attr(rule_node, "title", rule.get_title());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( rule.has_else_filter() )
|
|
|
|
{
|
|
|
|
rule_node.push_back( ptree::value_type(
|
|
|
|
"ElseFilter", ptree()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// filters are not comparable, so compare strings for now
|
|
|
|
std::string filter = rule.get_filter()->to_string();
|
|
|
|
std::string default_filter = dfl.get_filter()->to_string();
|
|
|
|
if ( filter != default_filter)
|
|
|
|
{
|
|
|
|
rule_node.push_back( ptree::value_type(
|
|
|
|
"Filter", ptree()))->second.put_own( filter );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-28 23:44:34 +02:00
|
|
|
if (rule.get_min_scale() != dfl.get_min_scale() )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
ptree & min_scale = rule_node.push_back( ptree::value_type(
|
|
|
|
"MinScaleDenominator", ptree()))->second;
|
|
|
|
min_scale.put_own( rule.get_min_scale() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rule.get_max_scale() != dfl.get_max_scale() )
|
|
|
|
{
|
|
|
|
ptree & max_scale = rule_node.push_back( ptree::value_type(
|
|
|
|
"MaxScaleDenominator", ptree()))->second;
|
|
|
|
max_scale.put_own( rule.get_max_scale() );
|
|
|
|
}
|
|
|
|
|
|
|
|
symbolizers::const_iterator begin = rule.get_symbolizers().begin();
|
|
|
|
symbolizers::const_iterator end = rule.get_symbolizers().end();
|
2009-04-28 23:44:34 +02:00
|
|
|
serialize_symbolizer serializer( rule_node, explicit_defaults);
|
2007-09-25 20:47:12 +02:00
|
|
|
std::for_each( begin, end , boost::apply_visitor( serializer ));
|
|
|
|
}
|
|
|
|
|
2009-04-28 23:44:34 +02:00
|
|
|
void serialize_style( ptree & map_node, Map::const_style_iterator style_it, bool explicit_defaults )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
|
|
|
const feature_type_style & style = style_it->second;
|
|
|
|
const std::string & name = style_it->first;
|
|
|
|
|
|
|
|
ptree & style_node = map_node.push_back(
|
|
|
|
ptree::value_type("Style", ptree()))->second;
|
|
|
|
|
|
|
|
set_attr(style_node, "name", name);
|
|
|
|
|
|
|
|
rules::const_iterator it = style.get_rules().begin();
|
|
|
|
rules::const_iterator end = style.get_rules().end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
{
|
2009-04-28 23:44:34 +02:00
|
|
|
serialize_rule( style_node, * it , explicit_defaults);
|
2007-09-25 20:47:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-17 21:18:41 +01:00
|
|
|
void serialize_fontset( ptree & map_node, Map::const_fontset_iterator fontset_it )
|
|
|
|
{
|
|
|
|
const FontSet & fontset = fontset_it->second;
|
|
|
|
const std::string & name = fontset_it->first;
|
|
|
|
|
|
|
|
ptree & fontset_node = map_node.push_back(
|
|
|
|
ptree::value_type("FontSet", ptree()))->second;
|
|
|
|
|
|
|
|
set_attr(fontset_node, "name", name);
|
|
|
|
|
|
|
|
std::vector<std::string>::const_iterator it = fontset.get_face_names().begin();
|
|
|
|
std::vector<std::string>::const_iterator end = fontset.get_face_names().end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
{
|
|
|
|
ptree & font_node = fontset_node.push_back(
|
|
|
|
ptree::value_type("Font", ptree()))->second;
|
|
|
|
set_attr(font_node, "face_name", *it);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-09-25 20:47:12 +02:00
|
|
|
void serialize_datasource( ptree & layer_node, datasource_ptr datasource)
|
|
|
|
{
|
|
|
|
ptree & datasource_node = layer_node.push_back(
|
|
|
|
ptree::value_type("Datasource", ptree()))->second;
|
|
|
|
|
|
|
|
parameters::const_iterator it = datasource->params().begin();
|
|
|
|
parameters::const_iterator end = datasource->params().end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
{
|
|
|
|
boost::property_tree::ptree & param_node = datasource_node.push_back(
|
|
|
|
boost::property_tree::ptree::value_type("Parameter",
|
|
|
|
boost::property_tree::ptree()))->second;
|
|
|
|
param_node.put("<xmlattr>.name", it->first );
|
|
|
|
param_node.put_own( it->second );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void serialize_layer( ptree & map_node, const Layer & layer )
|
|
|
|
{
|
|
|
|
ptree & layer_node = map_node.push_back(
|
|
|
|
ptree::value_type("Layer", ptree()))->second;
|
|
|
|
if ( layer.name() != "" )
|
|
|
|
{
|
|
|
|
set_attr( layer_node, "name", layer.name() );
|
|
|
|
}
|
2009-01-11 19:55:29 +01:00
|
|
|
|
|
|
|
if ( layer.abstract() != "" )
|
|
|
|
{
|
|
|
|
set_attr( layer_node, "abstract", layer.abstract() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( layer.title() != "" )
|
|
|
|
{
|
|
|
|
set_attr( layer_node, "title", layer.title() );
|
|
|
|
}
|
|
|
|
|
2007-09-25 20:47:12 +02:00
|
|
|
if ( layer.srs() != "" )
|
|
|
|
{
|
|
|
|
set_attr( layer_node, "srs", layer.srs() );
|
|
|
|
}
|
2009-01-11 19:55:29 +01:00
|
|
|
|
2007-09-25 20:47:12 +02:00
|
|
|
set_attr/*<bool>*/( layer_node, "status", layer.isActive() );
|
|
|
|
set_attr/*<bool>*/( layer_node, "clear_label_cache", layer.clear_label_cache() );
|
|
|
|
|
2009-01-11 19:55:29 +01:00
|
|
|
if ( layer.getMinZoom() )
|
|
|
|
{
|
|
|
|
set_attr( layer_node, "minzoom", layer.getMinZoom() );
|
|
|
|
}
|
|
|
|
|
2009-01-11 21:09:32 +01:00
|
|
|
if ( layer.getMaxZoom() != std::numeric_limits<double>::max() )
|
2009-01-11 19:55:29 +01:00
|
|
|
{
|
|
|
|
set_attr( layer_node, "maxzoom", layer.getMaxZoom() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( layer.isQueryable() )
|
|
|
|
{
|
|
|
|
set_attr( layer_node, "queryable", layer.isQueryable() );
|
|
|
|
}
|
|
|
|
|
2007-09-25 20:47:12 +02:00
|
|
|
std::vector<std::string> const& style_names = layer.styles();
|
|
|
|
for (unsigned i = 0; i < style_names.size(); ++i)
|
|
|
|
{
|
|
|
|
boost::property_tree::ptree & style_node = layer_node.push_back(
|
|
|
|
boost::property_tree::ptree::value_type("StyleName",
|
|
|
|
boost::property_tree::ptree()))->second;
|
|
|
|
style_node.put_own( style_names[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
datasource_ptr datasource = layer.datasource();
|
|
|
|
if ( datasource )
|
|
|
|
{
|
|
|
|
serialize_datasource( layer_node, datasource );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-28 23:44:34 +02:00
|
|
|
void save_map(Map const & map, std::string const& filename, bool explicit_defaults)
|
2006-10-03 10:39:43 +02:00
|
|
|
{
|
|
|
|
ptree pt;
|
2007-09-25 20:47:12 +02:00
|
|
|
|
|
|
|
ptree & map_node = pt.push_back(ptree::value_type("Map", ptree() ))->second;
|
|
|
|
|
|
|
|
set_attr( map_node, "srs", map.srs() );
|
|
|
|
|
2009-01-14 13:10:24 +01:00
|
|
|
optional<color> c = map.background();
|
2007-09-25 20:47:12 +02:00
|
|
|
if ( c )
|
|
|
|
{
|
|
|
|
set_attr( map_node, "bgcolor", * c );
|
|
|
|
}
|
|
|
|
|
2009-01-17 21:18:41 +01:00
|
|
|
{
|
|
|
|
Map::const_fontset_iterator it = map.fontsets().begin();
|
|
|
|
Map::const_fontset_iterator end = map.fontsets().end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
{
|
|
|
|
serialize_fontset( map_node, it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-25 20:47:12 +02:00
|
|
|
Map::const_style_iterator it = map.styles().begin();
|
|
|
|
Map::const_style_iterator end = map.styles().end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
{
|
2009-04-28 23:44:34 +02:00
|
|
|
serialize_style( map_node, it, explicit_defaults);
|
2007-09-25 20:47:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Layer> const & layers = map.layers();
|
|
|
|
for (unsigned i = 0; i < layers.size(); ++i )
|
|
|
|
{
|
|
|
|
serialize_layer( map_node, layers[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-03 10:39:43 +02:00
|
|
|
write_xml(filename,pt);
|
|
|
|
}
|
2007-09-25 20:47:12 +02:00
|
|
|
|
2006-10-03 10:39:43 +02:00
|
|
|
}
|