2006-10-03 10:39:43 +02:00
|
|
|
/*****************************************************************************
|
Patch from David Eastcott :
1. Modified Text Symbolizer
a) corrected line fragment centering (for 2nd and subsequent lines, when line breaks occur).
b) adjusted vertical alignment calculation so that:
i) middle -> has the center of the text line(s) at the point origin
ii) bottom -> has the text line(s) below the point origin
iii) top -> has the text line(s) above the point origin
c) added new text_symbolizer attribute: 'wrap_before', value range: true/false, default == false
allows line breaks at first wrap_char before wrap_width as an alternative to the original
which was to create the line break at the first wrap_char after wrap_width
d) added new text_symbolizer attribute: 'horizontal_alignment', value range: left/middle/right, default == middle
i) left -> has all text line(s) to left of the point origin
ii) middle -> has all text line(s) centered on the the point origin
iii) right -> has all text line(s) to the right of the point origin
NOTE: dx, dy position adjustments are applied after alignments and before Justify.
e) added new text_symbolizer attribute: 'justify_alignment', value range: left/middle/right, default == middle
i) left -> after alignments, has all text line(s) are left justified (left to right reading)
ii) middle -> after alignments, has all text line(s) center justified
iii) right -> after alignments, has all text line(s) right justified (right to left reading)
f) added new text_symbolizer attribute: 'opacity', value range: 0.0 thru 1.0; 1.0 == fully opaque
g) modified positioning to compensate for both line_spacing and character_spacing, to ensure proper
centering of the text envelope. Also ensure that centering occurs correctly even if no wrapping
occurs. Line spacing is uniform and consistent and compensates for errors between text_size and
the actual size (ci.height is inconsistent, depending on case and character); fixes issue with
multi-line text where some lines have a slight gap and others are compressed together.
2. Modified shield_symbolizer
a) added the attributes:
i) allow_overlap
ii) vertical_alignment
iii) horizontal_alignment
iv) justify_alignment
v) wrap_width
vi) wrap_character
vii) wrap_before
viii) text_convert
ix) line_spacing
x) character_spacing
xi) opacity
b) added new shield_symbolizer attribute: 'unlock_image', value range: true/false, default == false
i) false == image and text placement behaviour same as before
ii) true == image placement independant of text, image is always centered at geometry point, text placed per attributes,
dx/dy only affect text.
Allows user to create point markers with text, but both the text and image rendering collision detection are done
as a pair (they come and go together - solves problem if using point_symbolizer and text_symbolizers where one or the
other are omitted due to overlaps, but not both)
c) extended choices for the attribute 'placement' to include vertex; effect is limited to the shield_symbolizer
Allows an attempted placement at every vertex available, gives additional shield placement volume when using line geometry
d) ensured that the text placement was not updating the detector unless a shield image was actually placed.
e) added new shield_symbolizer attribute: 'no_text', value range: true/false, default = false
When set true, the text for the feature is ignored ('space' subsituted) so that pure graphic symbols can be used
and no text is rendered over top of them.
2009-10-19 15:52:53 +02:00
|
|
|
*
|
2006-10-03 10:39:43 +02:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2011-10-23 15:04:25 +02:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2006-10-03 10:39:43 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2009-12-16 21:02:06 +01:00
|
|
|
|
2007-10-08 19:42:41 +02:00
|
|
|
// mapnik
|
2013-01-04 05:06:10 +01:00
|
|
|
#include <mapnik/rule.hpp>
|
2014-07-23 08:36:54 +02:00
|
|
|
#include <mapnik/datasource.hpp>
|
2012-07-25 03:35:41 +02:00
|
|
|
#include <mapnik/layer.hpp>
|
|
|
|
#include <mapnik/feature_type_style.hpp>
|
2012-07-06 01:07:38 +02:00
|
|
|
#include <mapnik/debug.hpp>
|
2007-10-08 19:42:41 +02:00
|
|
|
#include <mapnik/save_map.hpp>
|
2010-07-19 02:21:53 +02:00
|
|
|
#include <mapnik/map.hpp>
|
2013-11-28 07:50:15 +01:00
|
|
|
#include <mapnik/symbolizer.hpp>
|
2007-10-08 19:42:41 +02:00
|
|
|
#include <mapnik/ptree_helpers.hpp>
|
2009-12-16 21:02:06 +01:00
|
|
|
#include <mapnik/expression_string.hpp>
|
2010-03-12 15:49:50 +01:00
|
|
|
#include <mapnik/raster_colorizer.hpp>
|
2013-11-08 05:09:22 +01:00
|
|
|
#include <mapnik/text/placements/simple.hpp>
|
|
|
|
#include <mapnik/text/placements/list.hpp>
|
|
|
|
#include <mapnik/text/placements/dummy.hpp>
|
2012-07-06 02:06:41 +02:00
|
|
|
#include <mapnik/image_compositing.hpp>
|
2012-07-07 01:45:58 +02:00
|
|
|
#include <mapnik/image_scaling.hpp>
|
2013-01-04 05:06:10 +01:00
|
|
|
#include <mapnik/image_filter.hpp>
|
2012-07-10 13:52:18 +02:00
|
|
|
#include <mapnik/image_filter_types.hpp>
|
2013-01-04 05:06:10 +01:00
|
|
|
#include <mapnik/parse_path.hpp>
|
2013-11-28 07:50:15 +01:00
|
|
|
#include <mapnik/symbolizer_utils.hpp>
|
|
|
|
#include <mapnik/transform_processor.hpp>
|
2014-04-29 18:08:05 +02:00
|
|
|
#include <mapnik/group/group_rule.hpp>
|
|
|
|
#include <mapnik/group/group_layout.hpp>
|
|
|
|
#include <mapnik/group/group_symbolizer_properties.hpp>
|
2014-08-11 14:24:53 +02:00
|
|
|
#include <mapnik/util/variant.hpp>
|
2014-10-22 01:37:27 +02:00
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
// boost
|
2014-10-22 01:37:27 +02:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-local-typedef"
|
2006-10-03 10:39:43 +02:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2014-10-22 01:37:27 +02:00
|
|
|
#pragma GCC diagnostic pop
|
2007-09-25 20:47:12 +02:00
|
|
|
#include <boost/optional.hpp>
|
2014-08-19 18:07:30 +02:00
|
|
|
#include <boost/version.hpp>
|
2006-10-03 10:39:43 +02:00
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
#include <boost/property_tree/xml_parser.hpp>
|
2014-08-08 22:15:57 +02:00
|
|
|
|
2007-10-08 19:42:41 +02:00
|
|
|
// stl
|
|
|
|
#include <iostream>
|
2006-10-03 10:39:43 +02:00
|
|
|
|
Patch from David Eastcott :
1. Modified Text Symbolizer
a) corrected line fragment centering (for 2nd and subsequent lines, when line breaks occur).
b) adjusted vertical alignment calculation so that:
i) middle -> has the center of the text line(s) at the point origin
ii) bottom -> has the text line(s) below the point origin
iii) top -> has the text line(s) above the point origin
c) added new text_symbolizer attribute: 'wrap_before', value range: true/false, default == false
allows line breaks at first wrap_char before wrap_width as an alternative to the original
which was to create the line break at the first wrap_char after wrap_width
d) added new text_symbolizer attribute: 'horizontal_alignment', value range: left/middle/right, default == middle
i) left -> has all text line(s) to left of the point origin
ii) middle -> has all text line(s) centered on the the point origin
iii) right -> has all text line(s) to the right of the point origin
NOTE: dx, dy position adjustments are applied after alignments and before Justify.
e) added new text_symbolizer attribute: 'justify_alignment', value range: left/middle/right, default == middle
i) left -> after alignments, has all text line(s) are left justified (left to right reading)
ii) middle -> after alignments, has all text line(s) center justified
iii) right -> after alignments, has all text line(s) right justified (right to left reading)
f) added new text_symbolizer attribute: 'opacity', value range: 0.0 thru 1.0; 1.0 == fully opaque
g) modified positioning to compensate for both line_spacing and character_spacing, to ensure proper
centering of the text envelope. Also ensure that centering occurs correctly even if no wrapping
occurs. Line spacing is uniform and consistent and compensates for errors between text_size and
the actual size (ci.height is inconsistent, depending on case and character); fixes issue with
multi-line text where some lines have a slight gap and others are compressed together.
2. Modified shield_symbolizer
a) added the attributes:
i) allow_overlap
ii) vertical_alignment
iii) horizontal_alignment
iv) justify_alignment
v) wrap_width
vi) wrap_character
vii) wrap_before
viii) text_convert
ix) line_spacing
x) character_spacing
xi) opacity
b) added new shield_symbolizer attribute: 'unlock_image', value range: true/false, default == false
i) false == image and text placement behaviour same as before
ii) true == image placement independant of text, image is always centered at geometry point, text placed per attributes,
dx/dy only affect text.
Allows user to create point markers with text, but both the text and image rendering collision detection are done
as a pair (they come and go together - solves problem if using point_symbolizer and text_symbolizers where one or the
other are omitted due to overlaps, but not both)
c) extended choices for the attribute 'placement' to include vertex; effect is limited to the shield_symbolizer
Allows an attempted placement at every vertex available, gives additional shield placement volume when using line geometry
d) ensured that the text placement was not updating the detector unless a shield image was actually placed.
e) added new shield_symbolizer attribute: 'no_text', value range: true/false, default = false
When set true, the text for the feature is ignored ('space' subsituted) so that pure graphic symbols can be used
and no text is rendered over top of them.
2009-10-19 15:52:53 +02:00
|
|
|
namespace mapnik
|
2006-10-03 10:39:43 +02:00
|
|
|
{
|
2010-04-09 20:46:25 +02:00
|
|
|
using boost::property_tree::ptree;
|
|
|
|
using boost::optional;
|
|
|
|
|
2014-07-29 18:38:39 +02:00
|
|
|
void serialize_text_placements(ptree & node, text_placements_ptr const& p, bool explicit_defaults)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2014-10-07 01:59:49 +02:00
|
|
|
text_symbolizer_properties dfl;
|
|
|
|
p->defaults.to_xml(node, explicit_defaults, dfl);
|
2013-11-28 07:50:15 +01:00
|
|
|
// Known types:
|
|
|
|
// - text_placements_dummy: no handling required
|
|
|
|
// - text_placements_simple: positions string
|
|
|
|
// - text_placements_list: list string
|
2010-04-09 20:46:25 +02:00
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
text_placements_simple *simple = dynamic_cast<text_placements_simple *>(p.get());
|
|
|
|
if (simple)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
set_attr(node, "placement-type", "simple");
|
|
|
|
set_attr(node, "placements", simple->get_positions());
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2014-07-22 17:15:21 +02:00
|
|
|
|
|
|
|
text_placements_list *list = dynamic_cast<text_placements_list *>(p.get());
|
2013-11-28 07:50:15 +01:00
|
|
|
if (list)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
set_attr(node, "placement-type", "list");
|
|
|
|
//dfl = last properties passed as default so only attributes that change are actually written
|
|
|
|
text_symbolizer_properties *dfl = &(list->defaults);
|
|
|
|
for (unsigned i=0; i < list->size(); ++i)
|
2012-09-12 14:23:49 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
ptree & placement_node = node.push_back(ptree::value_type("Placement", ptree()))->second;
|
|
|
|
list->get(i).to_xml(placement_node, explicit_defaults, *dfl);
|
|
|
|
dfl = &(list->get(i));
|
2012-09-12 14:23:49 +02:00
|
|
|
}
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2013-11-28 07:50:15 +01:00
|
|
|
}
|
2010-04-09 20:46:25 +02:00
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
void serialize_raster_colorizer(ptree & sym_node,
|
|
|
|
raster_colorizer_ptr const& colorizer,
|
2014-07-29 18:38:39 +02:00
|
|
|
bool explicit_defaults)
|
2013-11-28 07:50:15 +01:00
|
|
|
{
|
|
|
|
ptree & col_node = sym_node.push_back(
|
|
|
|
ptree::value_type("RasterColorizer", ptree() ))->second;
|
|
|
|
raster_colorizer dfl;
|
|
|
|
if (colorizer->get_default_mode() != dfl.get_default_mode() || explicit_defaults)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
set_attr(col_node, "default-mode", colorizer->get_default_mode());
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2013-11-28 07:50:15 +01:00
|
|
|
if (colorizer->get_default_color() != dfl.get_default_color() || explicit_defaults)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
set_attr(col_node, "default-color", colorizer->get_default_color());
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2013-11-28 07:50:15 +01:00
|
|
|
if (colorizer->get_epsilon() != dfl.get_epsilon() || explicit_defaults)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
set_attr(col_node, "epsilon", colorizer->get_epsilon());
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
|
|
|
|
2014-07-22 17:15:21 +02:00
|
|
|
colorizer_stops const& stops = colorizer->get_stops();
|
|
|
|
for (auto const& stop : stops)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2014-07-22 17:15:21 +02:00
|
|
|
ptree & stop_node = col_node.push_back( ptree::value_type("stop", ptree()) )->second;
|
|
|
|
set_attr(stop_node, "value", stop.get_value());
|
|
|
|
set_attr(stop_node, "color", stop.get_color());
|
|
|
|
set_attr(stop_node, "mode", stop.get_mode().as_string());
|
|
|
|
if (!stop.get_label().empty())
|
|
|
|
{
|
|
|
|
set_attr(stop_node, "label", stop.get_label());
|
|
|
|
}
|
2013-11-28 07:50:15 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2014-04-29 18:08:05 +02:00
|
|
|
void serialize_group_symbolizer_properties(ptree & sym_node,
|
|
|
|
group_symbolizer_properties_ptr const& properties,
|
2014-07-29 18:38:39 +02:00
|
|
|
bool explicit_defaults);
|
2014-04-29 18:08:05 +02:00
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
template <typename Meta>
|
2014-08-12 14:40:45 +02:00
|
|
|
class serialize_symbolizer_property : public util::static_visitor<>
|
2013-11-28 07:50:15 +01:00
|
|
|
{
|
|
|
|
public:
|
2013-12-05 17:25:56 +01:00
|
|
|
serialize_symbolizer_property(Meta const& meta,
|
2014-07-29 18:38:39 +02:00
|
|
|
boost::property_tree::ptree & node,
|
|
|
|
bool explicit_defaults)
|
2013-11-28 07:50:15 +01:00
|
|
|
: meta_(meta),
|
2014-07-29 18:38:39 +02:00
|
|
|
node_(node),
|
|
|
|
explicit_defaults_(explicit_defaults) {}
|
2012-07-25 00:20:58 +02:00
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
void operator() ( mapnik::enumeration_wrapper const& e) const
|
|
|
|
{
|
2014-10-17 21:45:15 +02:00
|
|
|
auto const& convert_fun_ptr(std::get<1>(meta_));
|
2013-11-28 07:50:15 +01:00
|
|
|
if ( convert_fun_ptr )
|
2012-07-31 20:23:53 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
node_.put("<xmlattr>." + std::string(std::get<0>(meta_)), convert_fun_ptr(e));
|
2012-07-31 20:23:53 +02:00
|
|
|
}
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
void operator () ( path_expression_ptr const& expr) const
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
if (expr)
|
2013-03-09 05:32:39 +01:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
node_.put("<xmlattr>." + std::string(std::get<0>(meta_)), path_processor::to_string(*expr));
|
2013-03-09 05:32:39 +01:00
|
|
|
}
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
void operator () (text_placements_ptr const& expr) const
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
if (expr)
|
2012-05-27 23:50:09 +02:00
|
|
|
{
|
2014-07-29 18:38:39 +02:00
|
|
|
serialize_text_placements(node_, expr, explicit_defaults_);
|
2012-05-27 23:50:09 +02:00
|
|
|
}
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
void operator () (raster_colorizer_ptr const& expr) const
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
if (expr)
|
2011-04-18 03:17:57 +02:00
|
|
|
{
|
2014-07-29 18:38:39 +02:00
|
|
|
serialize_raster_colorizer(node_, expr, explicit_defaults_);
|
2011-04-18 03:17:57 +02:00
|
|
|
}
|
2013-07-24 00:46:54 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
void operator () (transform_type const& expr) const
|
2012-07-06 02:23:48 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
if (expr)
|
2012-07-06 02:23:48 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
node_.put("<xmlattr>." + std::string(std::get<0>(meta_)), transform_processor_type::to_string(*expr));
|
2012-07-06 02:23:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
void operator () (expression_ptr const& expr) const
|
2011-05-04 02:20:17 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
if (expr)
|
2013-07-24 00:46:54 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
node_.put("<xmlattr>." + std::string(std::get<0>(meta_)), mapnik::to_expression_string(*expr));
|
2011-05-04 02:20:17 +02:00
|
|
|
}
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
void operator () (dash_array const& dash) const
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
std::ostringstream os;
|
|
|
|
for (std::size_t i = 0; i < dash.size(); ++i)
|
2010-12-11 03:07:47 +01:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
os << dash[i].first << ", " << dash[i].second;
|
|
|
|
if ( i + 1 < dash.size() ) os << ",";
|
2010-12-11 03:07:47 +01:00
|
|
|
}
|
2013-11-28 07:50:15 +01:00
|
|
|
node_.put("<xmlattr>." + std::string(std::get<0>(meta_)), os.str());
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2012-05-27 23:50:09 +02:00
|
|
|
|
2014-04-29 18:08:05 +02:00
|
|
|
void operator () (group_symbolizer_properties_ptr const& properties) const
|
|
|
|
{
|
|
|
|
if (properties)
|
|
|
|
{
|
2014-07-29 18:38:39 +02:00
|
|
|
serialize_group_symbolizer_properties(node_, properties, explicit_defaults_);
|
2014-04-29 18:08:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
template <typename T>
|
|
|
|
void operator () ( T const& val ) const
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
node_.put("<xmlattr>." + std::string(std::get<0>(meta_)), val );
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2010-08-12 02:11:01 +02:00
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
private:
|
2013-12-05 17:25:56 +01:00
|
|
|
Meta const& meta_;
|
2013-11-28 07:50:15 +01:00
|
|
|
boost::property_tree::ptree & node_;
|
2014-07-29 18:38:39 +02:00
|
|
|
bool explicit_defaults_;
|
2013-11-28 07:50:15 +01:00
|
|
|
};
|
|
|
|
|
2014-08-12 14:40:45 +02:00
|
|
|
class serialize_symbolizer : public util::static_visitor<>
|
2013-11-28 07:50:15 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
serialize_symbolizer( ptree & r , bool explicit_defaults)
|
|
|
|
: rule_(r),
|
|
|
|
explicit_defaults_(explicit_defaults) {}
|
|
|
|
|
|
|
|
template <typename Symbolizer>
|
|
|
|
void operator () ( Symbolizer const& sym)
|
2010-08-19 17:45:53 +02:00
|
|
|
{
|
2013-11-28 07:50:15 +01:00
|
|
|
ptree & sym_node = rule_.push_back(
|
|
|
|
ptree::value_type(symbolizer_traits<Symbolizer>::name(), ptree()))->second;
|
|
|
|
serialize_symbolizer_properties(sym_node,sym);
|
|
|
|
}
|
2010-08-19 17:45:53 +02:00
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
private:
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
void serialize_symbolizer_properties( ptree & sym_node, symbolizer_base const& sym)
|
|
|
|
{
|
|
|
|
for (auto const& prop : sym.properties)
|
2010-08-19 17:45:53 +02:00
|
|
|
{
|
2014-08-11 14:24:53 +02:00
|
|
|
util::apply_visitor(serialize_symbolizer_property<property_meta_type>(
|
|
|
|
get_meta(prop.first), sym_node, explicit_defaults_),
|
|
|
|
prop.second);
|
2010-08-19 17:45:53 +02:00
|
|
|
}
|
|
|
|
}
|
2010-04-09 20:46:25 +02:00
|
|
|
ptree & rule_;
|
|
|
|
bool explicit_defaults_;
|
|
|
|
};
|
|
|
|
|
2014-08-12 14:40:45 +02:00
|
|
|
class serialize_group_layout : public util::static_visitor<>
|
2014-04-29 18:08:05 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
serialize_group_layout(ptree & parent_node, bool explicit_defaults)
|
|
|
|
: parent_node_(parent_node),
|
|
|
|
explicit_defaults_(explicit_defaults) {}
|
|
|
|
|
|
|
|
void operator() ( simple_row_layout const& layout) const
|
|
|
|
{
|
|
|
|
ptree & layout_node = parent_node_.push_back(
|
|
|
|
ptree::value_type("SimpleLayout", ptree() ))->second;
|
|
|
|
|
|
|
|
simple_row_layout dfl;
|
|
|
|
if (explicit_defaults_ || layout.get_item_margin() != dfl.get_item_margin())
|
|
|
|
{
|
|
|
|
set_attr(layout_node, "item-margin", layout.get_item_margin());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator () ( pair_layout const& layout) const
|
|
|
|
{
|
|
|
|
ptree & layout_node = parent_node_.push_back(
|
|
|
|
ptree::value_type("PairLayout", ptree() ))->second;
|
|
|
|
|
|
|
|
pair_layout dfl;
|
|
|
|
if (explicit_defaults_ || layout.get_item_margin() != dfl.get_item_margin())
|
|
|
|
{
|
|
|
|
set_attr(layout_node, "item-margin", layout.get_item_margin());
|
|
|
|
}
|
|
|
|
if (explicit_defaults_ || layout.get_max_difference() != dfl.get_max_difference())
|
|
|
|
{
|
|
|
|
set_attr(layout_node, "max-difference", layout.get_max_difference());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2014-10-21 07:28:40 +02:00
|
|
|
void operator () ( T const& ) const {}
|
2014-04-29 18:08:05 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
ptree & parent_node_;
|
|
|
|
bool explicit_defaults_;
|
|
|
|
};
|
|
|
|
|
|
|
|
void serialize_group_rule( ptree & parent_node, const group_rule & r, bool explicit_defaults)
|
|
|
|
{
|
|
|
|
ptree & rule_node = parent_node.push_back(
|
|
|
|
ptree::value_type("GroupRule", ptree() ))->second;
|
|
|
|
|
|
|
|
group_rule dfl;
|
|
|
|
std::string filter = mapnik::to_expression_string(*r.get_filter());
|
|
|
|
std::string default_filter = mapnik::to_expression_string(*dfl.get_filter());
|
|
|
|
|
|
|
|
if (filter != default_filter)
|
|
|
|
{
|
|
|
|
rule_node.push_back( ptree::value_type(
|
|
|
|
"Filter", ptree()))->second.put_value( filter );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r.get_repeat_key())
|
|
|
|
{
|
|
|
|
std::string repeat_key = mapnik::to_expression_string(*r.get_repeat_key());
|
|
|
|
rule_node.push_back( ptree::value_type(
|
|
|
|
"RepeatKey", ptree()))->second.put_value( repeat_key );
|
|
|
|
}
|
|
|
|
|
|
|
|
rule::symbolizers::const_iterator begin = r.get_symbolizers().begin();
|
|
|
|
rule::symbolizers::const_iterator end = r.get_symbolizers().end();
|
|
|
|
serialize_symbolizer serializer( rule_node, explicit_defaults);
|
2014-08-12 14:40:45 +02:00
|
|
|
std::for_each( begin, end , [&serializer](symbolizer const& sym) { util::apply_visitor( std::ref(serializer), sym);} );
|
2014-04-29 18:08:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void serialize_group_symbolizer_properties(ptree & sym_node,
|
|
|
|
group_symbolizer_properties_ptr const& properties,
|
|
|
|
bool explicit_defaults)
|
|
|
|
{
|
2014-08-12 14:40:45 +02:00
|
|
|
util::apply_visitor(serialize_group_layout(sym_node, explicit_defaults), properties->get_layout());
|
2014-04-29 18:08:05 +02:00
|
|
|
|
|
|
|
for (auto const& rule : properties->get_rules())
|
|
|
|
{
|
|
|
|
serialize_group_rule(sym_node, *rule, explicit_defaults);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-22 17:15:21 +02:00
|
|
|
void serialize_rule( ptree & style_node, rule const& r, bool explicit_defaults)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
|
|
|
ptree & rule_node = style_node.push_back(
|
2010-06-02 13:03:30 +02:00
|
|
|
ptree::value_type("Rule", ptree() ))->second;
|
2010-04-09 20:46:25 +02:00
|
|
|
|
2011-01-13 22:35:01 +01:00
|
|
|
rule dfl;
|
|
|
|
if ( r.get_name() != dfl.get_name() )
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2011-01-13 22:35:01 +01:00
|
|
|
set_attr(rule_node, "name", r.get_name());
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-01-13 22:35:01 +01:00
|
|
|
if ( r.has_else_filter() )
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
rule_node.push_back( ptree::value_type(
|
|
|
|
"ElseFilter", ptree()));
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2011-08-30 19:38:27 +02:00
|
|
|
else if ( r.has_also_filter() )
|
|
|
|
{
|
|
|
|
rule_node.push_back( ptree::value_type(
|
|
|
|
"AlsoFilter", ptree()));
|
|
|
|
}
|
2010-04-09 20:46:25 +02:00
|
|
|
else
|
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
// filters were not comparable, perhaps should now compare expressions?
|
2011-01-13 22:35:01 +01:00
|
|
|
expression_ptr const& expr = r.get_filter();
|
2010-06-02 13:03:30 +02:00
|
|
|
std::string filter = mapnik::to_expression_string(*expr);
|
|
|
|
std::string default_filter = mapnik::to_expression_string(*dfl.get_filter());
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
if ( filter != default_filter)
|
|
|
|
{
|
|
|
|
rule_node.push_back( ptree::value_type(
|
|
|
|
"Filter", ptree()))->second.put_value( filter );
|
|
|
|
}
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2007-09-25 20:47:12 +02:00
|
|
|
|
2011-01-13 22:35:01 +01:00
|
|
|
if (r.get_min_scale() != dfl.get_min_scale() )
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
ptree & min_scale = rule_node.push_back( ptree::value_type(
|
|
|
|
"MinScaleDenominator", ptree()))->second;
|
2011-01-13 22:35:01 +01:00
|
|
|
min_scale.put_value( r.get_min_scale() );
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2007-09-25 20:47:12 +02:00
|
|
|
|
2011-01-13 22:35:01 +01:00
|
|
|
if (r.get_max_scale() != dfl.get_max_scale() )
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
ptree & max_scale = rule_node.push_back( ptree::value_type(
|
|
|
|
"MaxScaleDenominator", ptree()))->second;
|
2011-01-13 22:35:01 +01:00
|
|
|
max_scale.put_value( r.get_max_scale() );
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
|
|
|
|
2012-10-10 19:51:06 +02:00
|
|
|
rule::symbolizers::const_iterator begin = r.get_symbolizers().begin();
|
|
|
|
rule::symbolizers::const_iterator end = r.get_symbolizers().end();
|
2010-04-09 20:46:25 +02:00
|
|
|
serialize_symbolizer serializer( rule_node, explicit_defaults);
|
2014-08-12 14:40:45 +02:00
|
|
|
std::for_each( begin, end , [&serializer](symbolizer const& sym) { util::apply_visitor( std::ref(serializer), sym);});
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 22:05:25 +02:00
|
|
|
void serialize_style( ptree & map_node, std::string const& name, feature_type_style const& style, bool explicit_defaults )
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
|
|
|
ptree & style_node = map_node.push_back(
|
2010-06-02 13:03:30 +02:00
|
|
|
ptree::value_type("Style", ptree()))->second;
|
2010-04-09 20:46:25 +02:00
|
|
|
|
|
|
|
set_attr(style_node, "name", name);
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-02-01 23:55:50 +01:00
|
|
|
feature_type_style dfl;
|
2012-06-19 21:10:28 +02:00
|
|
|
filter_mode_e filter_mode = style.get_filter_mode();
|
2011-02-01 23:55:50 +01:00
|
|
|
if (filter_mode != dfl.get_filter_mode() || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(style_node, "filter-mode", filter_mode);
|
|
|
|
}
|
2007-09-25 20:47:12 +02:00
|
|
|
|
2012-06-19 21:10:28 +02:00
|
|
|
double opacity = style.get_opacity();
|
|
|
|
if (opacity != dfl.get_opacity() || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(style_node, "opacity", opacity);
|
|
|
|
}
|
|
|
|
|
2014-02-27 19:11:17 +01:00
|
|
|
bool image_filters_inflate = style.image_filters_inflate();
|
|
|
|
if (image_filters_inflate != dfl.image_filters_inflate() || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(style_node, "image-filters-inflate", image_filters_inflate);
|
|
|
|
}
|
|
|
|
|
2012-07-06 02:06:41 +02:00
|
|
|
boost::optional<composite_mode_e> comp_op = style.comp_op();
|
|
|
|
if (comp_op)
|
|
|
|
{
|
|
|
|
set_attr(style_node, "comp-op", *comp_op_to_string(*comp_op));
|
|
|
|
}
|
|
|
|
else if (explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(style_node, "comp-op", "src-over");
|
|
|
|
}
|
|
|
|
|
2012-07-10 13:52:18 +02:00
|
|
|
if (style.image_filters().size() > 0)
|
|
|
|
{
|
|
|
|
std::string filters_str;
|
|
|
|
std::back_insert_iterator<std::string> sink(filters_str);
|
|
|
|
if (generate_image_filters(sink, style.image_filters()))
|
|
|
|
{
|
|
|
|
set_attr(style_node, "image-filters", filters_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style.direct_image_filters().size() > 0)
|
|
|
|
{
|
|
|
|
std::string filters_str;
|
|
|
|
std::back_insert_iterator<std::string> sink(filters_str);
|
|
|
|
if (generate_image_filters(sink, style.direct_image_filters()))
|
|
|
|
{
|
|
|
|
set_attr(style_node, "direct-image-filters", filters_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-02 13:10:47 +01:00
|
|
|
for (auto const& r : style.get_rules())
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-12-02 13:10:47 +01:00
|
|
|
serialize_rule( style_node, r , explicit_defaults);
|
2007-09-25 20:47:12 +02:00
|
|
|
}
|
|
|
|
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
|
|
|
|
2013-12-02 13:10:47 +01:00
|
|
|
void serialize_fontset( ptree & map_node, std::string const& name, font_set const& fontset)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
|
|
|
ptree & fontset_node = map_node.push_back(
|
2010-06-02 13:03:30 +02:00
|
|
|
ptree::value_type("FontSet", ptree()))->second;
|
2010-04-09 20:46:25 +02:00
|
|
|
|
|
|
|
set_attr(fontset_node, "name", name);
|
|
|
|
|
2013-12-02 13:10:47 +01:00
|
|
|
for (auto const& name : fontset.get_face_names())
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
ptree & font_node = fontset_node.push_back(
|
|
|
|
ptree::value_type("Font", ptree()))->second;
|
2013-12-02 13:10:47 +01:00
|
|
|
set_attr(font_node, "face-name", name);
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
Patch from David Eastcott :
1. Modified Text Symbolizer
a) corrected line fragment centering (for 2nd and subsequent lines, when line breaks occur).
b) adjusted vertical alignment calculation so that:
i) middle -> has the center of the text line(s) at the point origin
ii) bottom -> has the text line(s) below the point origin
iii) top -> has the text line(s) above the point origin
c) added new text_symbolizer attribute: 'wrap_before', value range: true/false, default == false
allows line breaks at first wrap_char before wrap_width as an alternative to the original
which was to create the line break at the first wrap_char after wrap_width
d) added new text_symbolizer attribute: 'horizontal_alignment', value range: left/middle/right, default == middle
i) left -> has all text line(s) to left of the point origin
ii) middle -> has all text line(s) centered on the the point origin
iii) right -> has all text line(s) to the right of the point origin
NOTE: dx, dy position adjustments are applied after alignments and before Justify.
e) added new text_symbolizer attribute: 'justify_alignment', value range: left/middle/right, default == middle
i) left -> after alignments, has all text line(s) are left justified (left to right reading)
ii) middle -> after alignments, has all text line(s) center justified
iii) right -> after alignments, has all text line(s) right justified (right to left reading)
f) added new text_symbolizer attribute: 'opacity', value range: 0.0 thru 1.0; 1.0 == fully opaque
g) modified positioning to compensate for both line_spacing and character_spacing, to ensure proper
centering of the text envelope. Also ensure that centering occurs correctly even if no wrapping
occurs. Line spacing is uniform and consistent and compensates for errors between text_size and
the actual size (ci.height is inconsistent, depending on case and character); fixes issue with
multi-line text where some lines have a slight gap and others are compressed together.
2. Modified shield_symbolizer
a) added the attributes:
i) allow_overlap
ii) vertical_alignment
iii) horizontal_alignment
iv) justify_alignment
v) wrap_width
vi) wrap_character
vii) wrap_before
viii) text_convert
ix) line_spacing
x) character_spacing
xi) opacity
b) added new shield_symbolizer attribute: 'unlock_image', value range: true/false, default == false
i) false == image and text placement behaviour same as before
ii) true == image placement independant of text, image is always centered at geometry point, text placed per attributes,
dx/dy only affect text.
Allows user to create point markers with text, but both the text and image rendering collision detection are done
as a pair (they come and go together - solves problem if using point_symbolizer and text_symbolizers where one or the
other are omitted due to overlaps, but not both)
c) extended choices for the attribute 'placement' to include vertex; effect is limited to the shield_symbolizer
Allows an attempted placement at every vertex available, gives additional shield placement volume when using line geometry
d) ensured that the text placement was not updating the detector unless a shield image was actually placed.
e) added new shield_symbolizer attribute: 'no_text', value range: true/false, default = false
When set true, the text for the feature is ignored ('space' subsituted) so that pure graphic symbols can be used
and no text is rendered over top of them.
2009-10-19 15:52:53 +02:00
|
|
|
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2007-09-25 20:47:12 +02:00
|
|
|
|
2010-04-09 20:46:25 +02:00
|
|
|
void serialize_datasource( ptree & layer_node, datasource_ptr datasource)
|
|
|
|
{
|
|
|
|
ptree & datasource_node = layer_node.push_back(
|
2010-06-02 13:03:30 +02:00
|
|
|
ptree::value_type("Datasource", ptree()))->second;
|
2007-09-25 20:47:12 +02:00
|
|
|
|
2013-12-02 13:10:47 +01:00
|
|
|
for ( auto const& p : datasource->params())
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
boost::property_tree::ptree & param_node = datasource_node.push_back(
|
|
|
|
boost::property_tree::ptree::value_type("Parameter",
|
|
|
|
boost::property_tree::ptree()))->second;
|
2013-12-02 13:10:47 +01:00
|
|
|
param_node.put("<xmlattr>.name", p.first );
|
|
|
|
param_node.put_value( p.second );
|
2007-09-25 20:47:12 +02:00
|
|
|
|
|
|
|
}
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2007-09-25 20:47:12 +02:00
|
|
|
|
2011-12-03 02:48:09 +01:00
|
|
|
void serialize_parameters( ptree & map_node, mapnik::parameters const& params)
|
|
|
|
{
|
2011-12-06 03:22:25 +01:00
|
|
|
if (params.size()) {
|
|
|
|
ptree & params_node = map_node.push_back(
|
|
|
|
ptree::value_type("Parameters", ptree()))->second;
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2013-12-02 13:10:47 +01:00
|
|
|
for (auto const& p : params)
|
2011-12-06 03:22:25 +01:00
|
|
|
{
|
|
|
|
boost::property_tree::ptree & param_node = params_node.push_back(
|
|
|
|
boost::property_tree::ptree::value_type("Parameter",
|
|
|
|
boost::property_tree::ptree()))->second;
|
2013-12-02 13:10:47 +01:00
|
|
|
param_node.put("<xmlattr>.name", p.first );
|
|
|
|
param_node.put_value( p.second );
|
2011-12-06 03:22:25 +01:00
|
|
|
}
|
2011-12-03 02:48:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-09 20:46:25 +02:00
|
|
|
void serialize_layer( ptree & map_node, const layer & layer, bool explicit_defaults )
|
|
|
|
{
|
|
|
|
ptree & layer_node = map_node.push_back(
|
2010-06-02 13:03:30 +02:00
|
|
|
ptree::value_type("Layer", ptree()))->second;
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-04-09 20:46:25 +02:00
|
|
|
if ( layer.name() != "" )
|
2009-01-17 21:18:41 +01:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
set_attr( layer_node, "name", layer.name() );
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-04-09 20:46:25 +02:00
|
|
|
if ( layer.srs() != "" )
|
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
set_attr( layer_node, "srs", layer.srs() );
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
if ( !layer.active() || explicit_defaults )
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2012-03-12 16:39:59 +01:00
|
|
|
set_attr/*<bool>*/( layer_node, "status", layer.active() );
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-04-09 20:46:25 +02:00
|
|
|
if ( layer.clear_label_cache() || explicit_defaults )
|
2012-02-02 02:53:35 +01:00
|
|
|
{
|
2011-02-05 04:11:09 +01:00
|
|
|
set_attr/*<bool>*/( layer_node, "clear-label-cache", layer.clear_label_cache() );
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2009-01-17 21:18:41 +01:00
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
if ( layer.min_zoom() )
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2012-03-12 16:39:59 +01:00
|
|
|
set_attr( layer_node, "minzoom", layer.min_zoom() );
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2009-01-17 21:18:41 +01:00
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
if ( layer.max_zoom() != std::numeric_limits<double>::max() )
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2012-03-12 16:39:59 +01:00
|
|
|
set_attr( layer_node, "maxzoom", layer.max_zoom() );
|
2009-01-17 21:18:41 +01:00
|
|
|
}
|
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
if ( layer.queryable() || explicit_defaults )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
2012-03-12 16:39:59 +01:00
|
|
|
set_attr( layer_node, "queryable", layer.queryable() );
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2007-09-25 20:47:12 +02:00
|
|
|
|
2011-03-01 18:09:29 +01:00
|
|
|
if ( layer.cache_features() || explicit_defaults )
|
2012-02-02 02:53:35 +01:00
|
|
|
{
|
2011-03-01 18:09:29 +01:00
|
|
|
set_attr/*<bool>*/( layer_node, "cache-features", layer.cache_features() );
|
|
|
|
}
|
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
if ( layer.group_by() != "" || explicit_defaults )
|
|
|
|
{
|
|
|
|
set_attr( layer_node, "group-by", layer.group_by() );
|
|
|
|
}
|
|
|
|
|
2012-10-29 10:50:37 +01:00
|
|
|
boost::optional<int> const& buffer_size = layer.buffer_size();
|
2012-08-01 16:44:36 +02:00
|
|
|
if ( buffer_size || explicit_defaults)
|
|
|
|
{
|
2012-10-29 10:50:37 +01:00
|
|
|
set_attr( layer_node, "buffer-size", *buffer_size );
|
2012-08-01 16:44:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
optional<box2d<double> > const& maximum_extent = layer.maximum_extent();
|
|
|
|
if ( maximum_extent)
|
|
|
|
{
|
|
|
|
std::ostringstream s;
|
|
|
|
s << std::setprecision(16)
|
|
|
|
<< maximum_extent->minx() << "," << maximum_extent->miny() << ","
|
|
|
|
<< maximum_extent->maxx() << "," << maximum_extent->maxy();
|
|
|
|
set_attr( layer_node, "maximum-extent", s.str() );
|
|
|
|
}
|
|
|
|
|
2013-12-02 13:10:47 +01:00
|
|
|
for (auto const& name : layer.styles())
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
boost::property_tree::ptree & style_node = layer_node.push_back(
|
|
|
|
boost::property_tree::ptree::value_type("StyleName",
|
|
|
|
boost::property_tree::ptree()))->second;
|
2013-12-02 13:10:47 +01:00
|
|
|
style_node.put_value(name);
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
Patch from David Eastcott :
1. Modified Text Symbolizer
a) corrected line fragment centering (for 2nd and subsequent lines, when line breaks occur).
b) adjusted vertical alignment calculation so that:
i) middle -> has the center of the text line(s) at the point origin
ii) bottom -> has the text line(s) below the point origin
iii) top -> has the text line(s) above the point origin
c) added new text_symbolizer attribute: 'wrap_before', value range: true/false, default == false
allows line breaks at first wrap_char before wrap_width as an alternative to the original
which was to create the line break at the first wrap_char after wrap_width
d) added new text_symbolizer attribute: 'horizontal_alignment', value range: left/middle/right, default == middle
i) left -> has all text line(s) to left of the point origin
ii) middle -> has all text line(s) centered on the the point origin
iii) right -> has all text line(s) to the right of the point origin
NOTE: dx, dy position adjustments are applied after alignments and before Justify.
e) added new text_symbolizer attribute: 'justify_alignment', value range: left/middle/right, default == middle
i) left -> after alignments, has all text line(s) are left justified (left to right reading)
ii) middle -> after alignments, has all text line(s) center justified
iii) right -> after alignments, has all text line(s) right justified (right to left reading)
f) added new text_symbolizer attribute: 'opacity', value range: 0.0 thru 1.0; 1.0 == fully opaque
g) modified positioning to compensate for both line_spacing and character_spacing, to ensure proper
centering of the text envelope. Also ensure that centering occurs correctly even if no wrapping
occurs. Line spacing is uniform and consistent and compensates for errors between text_size and
the actual size (ci.height is inconsistent, depending on case and character); fixes issue with
multi-line text where some lines have a slight gap and others are compressed together.
2. Modified shield_symbolizer
a) added the attributes:
i) allow_overlap
ii) vertical_alignment
iii) horizontal_alignment
iv) justify_alignment
v) wrap_width
vi) wrap_character
vii) wrap_before
viii) text_convert
ix) line_spacing
x) character_spacing
xi) opacity
b) added new shield_symbolizer attribute: 'unlock_image', value range: true/false, default == false
i) false == image and text placement behaviour same as before
ii) true == image placement independant of text, image is always centered at geometry point, text placed per attributes,
dx/dy only affect text.
Allows user to create point markers with text, but both the text and image rendering collision detection are done
as a pair (they come and go together - solves problem if using point_symbolizer and text_symbolizers where one or the
other are omitted due to overlaps, but not both)
c) extended choices for the attribute 'placement' to include vertex; effect is limited to the shield_symbolizer
Allows an attempted placement at every vertex available, gives additional shield placement volume when using line geometry
d) ensured that the text placement was not updating the detector unless a shield image was actually placed.
e) added new shield_symbolizer attribute: 'no_text', value range: true/false, default = false
When set true, the text for the feature is ignored ('space' subsituted) so that pure graphic symbols can be used
and no text is rendered over top of them.
2009-10-19 15:52:53 +02:00
|
|
|
|
2010-04-09 20:46:25 +02:00
|
|
|
datasource_ptr datasource = layer.datasource();
|
|
|
|
if ( datasource )
|
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
serialize_datasource( layer_node, datasource );
|
2007-09-25 20:47:12 +02:00
|
|
|
}
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
|
|
|
|
2014-07-22 17:15:21 +02:00
|
|
|
void serialize_map(ptree & pt, Map const& map, bool explicit_defaults)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
ptree & map_node = pt.push_back(ptree::value_type("Map", ptree() ))->second;
|
2007-09-25 20:47:12 +02:00
|
|
|
|
2010-04-09 20:46:25 +02:00
|
|
|
set_attr( map_node, "srs", map.srs() );
|
|
|
|
|
2010-07-19 13:10:03 +02:00
|
|
|
optional<color> const& c = map.background();
|
2010-04-09 20:46:25 +02:00
|
|
|
if ( c )
|
2007-09-25 20:47:12 +02:00
|
|
|
{
|
2010-07-19 14:01:34 +02:00
|
|
|
set_attr( map_node, "background-color", * c );
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2009-01-11 19:55:29 +01:00
|
|
|
|
2014-09-27 04:54:07 +02:00
|
|
|
optional<std::string> const& font_directory = map.font_directory();
|
|
|
|
if ( font_directory )
|
|
|
|
{
|
|
|
|
set_attr( map_node, "font-directory", *font_directory );
|
|
|
|
}
|
|
|
|
|
2010-07-19 13:10:03 +02:00
|
|
|
optional<std::string> const& image_filename = map.background_image();
|
|
|
|
if ( image_filename )
|
|
|
|
{
|
|
|
|
set_attr( map_node, "background-image", *image_filename );
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2013-07-25 07:00:38 +02:00
|
|
|
composite_mode_e comp_op = map.background_image_comp_op();
|
|
|
|
if (comp_op != src_over || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(map_node, "background-image-comp-op", *comp_op_to_string(comp_op));
|
|
|
|
}
|
|
|
|
|
|
|
|
double opacity = map.background_image_opacity();
|
|
|
|
if (opacity != 1.0 || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(map_node, "background-image-opacity", opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-01 16:44:36 +02:00
|
|
|
int buffer_size = map.buffer_size();
|
2010-04-09 20:46:25 +02:00
|
|
|
if ( buffer_size || explicit_defaults)
|
|
|
|
{
|
2012-02-02 02:53:35 +01:00
|
|
|
set_attr( map_node, "buffer-size", buffer_size );
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2011-05-26 01:48:07 +02:00
|
|
|
|
|
|
|
std::string const& base_path = map.base_path();
|
|
|
|
if ( !base_path.empty() || explicit_defaults)
|
|
|
|
{
|
2012-02-02 02:53:35 +01:00
|
|
|
set_attr( map_node, "base", base_path );
|
2011-05-26 01:48:07 +02:00
|
|
|
}
|
2009-01-11 19:55:29 +01:00
|
|
|
|
2011-04-14 04:32:51 +02:00
|
|
|
optional<box2d<double> > const& maximum_extent = map.maximum_extent();
|
|
|
|
if ( maximum_extent)
|
|
|
|
{
|
|
|
|
std::ostringstream s;
|
|
|
|
s << std::setprecision(16)
|
|
|
|
<< maximum_extent->minx() << "," << maximum_extent->miny() << ","
|
|
|
|
<< maximum_extent->maxx() << "," << maximum_extent->maxy();
|
2012-02-02 02:53:35 +01:00
|
|
|
set_attr( map_node, "maximum-extent", s.str() );
|
2011-04-14 04:32:51 +02:00
|
|
|
}
|
|
|
|
|
2013-12-02 13:10:47 +01:00
|
|
|
|
|
|
|
for (auto const& kv : map.fontsets())
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2013-12-02 13:10:47 +01:00
|
|
|
serialize_fontset( map_node, kv.first, kv.second);
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
2009-01-11 19:55:29 +01:00
|
|
|
|
2011-12-03 02:48:09 +01:00
|
|
|
serialize_parameters( map_node, map.get_extra_parameters());
|
2010-10-07 21:34:36 +02:00
|
|
|
|
2014-07-18 22:05:25 +02:00
|
|
|
for ( auto const& kv : map.styles())
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2014-07-18 22:05:25 +02:00
|
|
|
serialize_style( map_node, kv.first, kv.second, explicit_defaults);
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
Patch from David Eastcott :
1. Modified Text Symbolizer
a) corrected line fragment centering (for 2nd and subsequent lines, when line breaks occur).
b) adjusted vertical alignment calculation so that:
i) middle -> has the center of the text line(s) at the point origin
ii) bottom -> has the text line(s) below the point origin
iii) top -> has the text line(s) above the point origin
c) added new text_symbolizer attribute: 'wrap_before', value range: true/false, default == false
allows line breaks at first wrap_char before wrap_width as an alternative to the original
which was to create the line break at the first wrap_char after wrap_width
d) added new text_symbolizer attribute: 'horizontal_alignment', value range: left/middle/right, default == middle
i) left -> has all text line(s) to left of the point origin
ii) middle -> has all text line(s) centered on the the point origin
iii) right -> has all text line(s) to the right of the point origin
NOTE: dx, dy position adjustments are applied after alignments and before Justify.
e) added new text_symbolizer attribute: 'justify_alignment', value range: left/middle/right, default == middle
i) left -> after alignments, has all text line(s) are left justified (left to right reading)
ii) middle -> after alignments, has all text line(s) center justified
iii) right -> after alignments, has all text line(s) right justified (right to left reading)
f) added new text_symbolizer attribute: 'opacity', value range: 0.0 thru 1.0; 1.0 == fully opaque
g) modified positioning to compensate for both line_spacing and character_spacing, to ensure proper
centering of the text envelope. Also ensure that centering occurs correctly even if no wrapping
occurs. Line spacing is uniform and consistent and compensates for errors between text_size and
the actual size (ci.height is inconsistent, depending on case and character); fixes issue with
multi-line text where some lines have a slight gap and others are compressed together.
2. Modified shield_symbolizer
a) added the attributes:
i) allow_overlap
ii) vertical_alignment
iii) horizontal_alignment
iv) justify_alignment
v) wrap_width
vi) wrap_character
vii) wrap_before
viii) text_convert
ix) line_spacing
x) character_spacing
xi) opacity
b) added new shield_symbolizer attribute: 'unlock_image', value range: true/false, default == false
i) false == image and text placement behaviour same as before
ii) true == image placement independant of text, image is always centered at geometry point, text placed per attributes,
dx/dy only affect text.
Allows user to create point markers with text, but both the text and image rendering collision detection are done
as a pair (they come and go together - solves problem if using point_symbolizer and text_symbolizers where one or the
other are omitted due to overlaps, but not both)
c) extended choices for the attribute 'placement' to include vertex; effect is limited to the shield_symbolizer
Allows an attempted placement at every vertex available, gives additional shield placement volume when using line geometry
d) ensured that the text placement was not updating the detector unless a shield image was actually placed.
e) added new shield_symbolizer attribute: 'no_text', value range: true/false, default = false
When set true, the text for the feature is ignored ('space' subsituted) so that pure graphic symbols can be used
and no text is rendered over top of them.
2009-10-19 15:52:53 +02:00
|
|
|
|
2014-07-18 22:05:25 +02:00
|
|
|
for (auto const& layer : map.layers())
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
2014-07-18 22:05:25 +02:00
|
|
|
serialize_layer( map_node, layer, explicit_defaults );
|
2009-07-24 08:15:58 +02:00
|
|
|
}
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
|
|
|
|
2014-07-22 17:15:21 +02:00
|
|
|
void save_map(Map const& map, std::string const& filename, bool explicit_defaults)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
|
|
|
ptree pt;
|
|
|
|
serialize_map(pt,map,explicit_defaults);
|
2014-08-19 18:07:30 +02:00
|
|
|
#if BOOST_VERSION >= 105600
|
|
|
|
write_xml(filename,pt,std::locale(),boost::property_tree::xml_writer_make_settings<ptree::key_type>(' ',2));
|
|
|
|
#else
|
|
|
|
write_xml(filename,pt,std::locale(),boost::property_tree::xml_writer_make_settings(' ',2));
|
|
|
|
#endif
|
2010-04-09 20:46:25 +02:00
|
|
|
}
|
|
|
|
|
2014-07-22 17:15:21 +02:00
|
|
|
std::string save_map_to_string(Map const& map, bool explicit_defaults)
|
2010-04-09 20:46:25 +02:00
|
|
|
{
|
|
|
|
ptree pt;
|
|
|
|
serialize_map(pt,map,explicit_defaults);
|
|
|
|
std::ostringstream ss;
|
2014-08-19 18:07:30 +02:00
|
|
|
#if BOOST_VERSION >= 105600
|
|
|
|
write_xml(ss,pt,boost::property_tree::xml_writer_make_settings<ptree::key_type>(' ',2));
|
|
|
|
#else
|
|
|
|
write_xml(ss,pt,boost::property_tree::xml_writer_make_settings(' ',2));
|
|
|
|
#endif
|
2010-04-09 20:46:25 +02:00
|
|
|
return ss.str();
|
|
|
|
}
|
2009-07-24 08:15:58 +02:00
|
|
|
|
2006-10-03 10:39:43 +02:00
|
|
|
}
|