mapnik/src/symbolizer.cpp

149 lines
4 KiB
C++
Raw Normal View History

/*****************************************************************************
2012-02-02 02:53:35 +01:00
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2011 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
*
*****************************************************************************/
2009-12-16 21:02:06 +01:00
//mapnik
#include <mapnik/symbolizer.hpp>
#include <mapnik/map.hpp>
namespace mapnik {
2010-07-19 13:09:44 +02:00
void symbolizer_base::add_metawriter(std::string const& name, metawriter_properties const& properties)
{
writer_name_ = name;
2010-07-19 13:09:44 +02:00
properties_ = properties;
}
2011-07-29 00:59:05 +02:00
void symbolizer_base::add_metawriter(metawriter_ptr writer_ptr, metawriter_properties const& properties,
2012-02-02 02:53:35 +01:00
std::string const& name)
2011-07-29 00:59:05 +02:00
{
writer_ptr_ = writer_ptr;
properties_ = properties;
writer_name_ = name;
if (writer_ptr) {
properties_complete_ = writer_ptr->get_default_properties();
properties_complete_.insert(properties_.begin(), properties_.end());
} else {
properties_complete_.clear();
}
}
void symbolizer_base::cache_metawriters(Map const &m)
{
if (writer_name_.empty()) {
properties_complete_.clear();
writer_ptr_ = metawriter_ptr();
return; // No metawriter
}
writer_ptr_ = m.find_metawriter(writer_name_);
2010-07-31 12:20:56 +02:00
if (writer_ptr_) {
properties_complete_ = writer_ptr_->get_default_properties();
properties_complete_.insert(properties_.begin(), properties_.end());
} else {
properties_complete_.clear();
MAPNIK_LOG_WARN(symbolizer) << "Metawriter '" << writer_name_ << "' used but not defined.";
2010-07-31 12:20:56 +02:00
}
}
metawriter_with_properties symbolizer_base::get_metawriter() const
{
2010-07-31 12:20:56 +02:00
return metawriter_with_properties(writer_ptr_, properties_complete_);
}
void symbolizer_base::set_comp_op(composite_mode_e comp_op)
{
comp_op_ = comp_op;
}
boost::optional<composite_mode_e> symbolizer_base::comp_op() const
{
return comp_op_;
}
2012-04-18 10:42:19 +02:00
void symbolizer_base::set_transform(transform_type const& affine_transform)
{
affine_transform_ = affine_transform;
}
transform_type const& symbolizer_base::get_transform() const
{
return affine_transform_;
}
std::string symbolizer_base::get_transform_string() const
{
std::stringstream ss;
ss << "matrix(" << affine_transform_[0] << ", " << affine_transform_[1] << ", "
<< affine_transform_[2] << ", " << affine_transform_[3] << ", "
<< affine_transform_[4] << ", " << affine_transform_[5] << ")";
return ss.str();
}
void symbolizer_base::set_clip(bool clip)
{
clip_ = clip;
}
bool symbolizer_base::clip() const
{
return clip_;
}
///////////////////////////////////////////////////////////////////////////////////////
2009-12-16 21:02:06 +01:00
symbolizer_with_image::symbolizer_with_image(path_expression_ptr file)
2010-06-15 15:43:27 +02:00
: image_filename_( file ),
2012-01-20 22:45:47 +01:00
image_opacity_(1.0f)
2010-06-03 14:35:02 +02:00
{
}
2009-12-16 21:02:06 +01:00
symbolizer_with_image::symbolizer_with_image( symbolizer_with_image const& rhs)
2010-06-03 14:35:02 +02:00
: image_filename_(rhs.image_filename_),
2012-04-18 10:42:19 +02:00
image_opacity_(rhs.image_opacity_) {}
2012-02-02 02:53:35 +01:00
2009-12-16 21:02:06 +01:00
path_expression_ptr symbolizer_with_image::get_filename() const
{
return image_filename_;
}
2012-02-02 02:53:35 +01:00
void symbolizer_with_image::set_filename(path_expression_ptr image_filename)
2009-12-16 21:02:06 +01:00
{
image_filename_ = image_filename;
}
2012-02-02 02:53:35 +01:00
2010-06-15 14:27:50 +02:00
void symbolizer_with_image::set_opacity(float opacity)
{
2012-01-20 22:45:47 +01:00
image_opacity_ = opacity;
2010-06-15 14:27:50 +02:00
}
float symbolizer_with_image::get_opacity() const
{
2012-01-20 22:45:47 +01:00
return image_opacity_;
2010-06-15 14:27:50 +02:00
}
} // end of namespace mapnik