implement style-level opacity - closes #314
This commit is contained in:
parent
4e16618771
commit
48a543b5d5
6 changed files with 73 additions and 32 deletions
|
@ -11,6 +11,8 @@ For a complete change history, see the git log.
|
|||
|
||||
Not yet released
|
||||
|
||||
- Added style-level 'opacity' (#314)
|
||||
|
||||
- PostGIS: Added 'simplify_geometries' option - will trigger ST_Simplify on geometries before returning to Mapnik (#1179)
|
||||
|
||||
- Improved error feedback for invalid values passed to map.query_point
|
||||
|
|
|
@ -63,6 +63,7 @@ private:
|
|||
rule_ptrs if_rules_;
|
||||
rule_ptrs else_rules_;
|
||||
rule_ptrs also_rules_;
|
||||
float opacity_;
|
||||
public:
|
||||
feature_type_style();
|
||||
|
||||
|
@ -90,6 +91,8 @@ public:
|
|||
// compositing
|
||||
void set_comp_op(composite_mode_e comp_op);
|
||||
boost::optional<composite_mode_e> comp_op() const;
|
||||
void set_opacity(float opacity);
|
||||
float get_opacity() const;
|
||||
|
||||
~feature_type_style() {}
|
||||
|
||||
|
|
|
@ -197,15 +197,25 @@ template <typename T>
|
|||
void agg_renderer<T>::start_style_processing(feature_type_style const& st)
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(agg_renderer) << "agg_renderer: Start processing style";
|
||||
if (st.comp_op()) style_level_compositing_ = true;
|
||||
else style_level_compositing_ = false;
|
||||
if (st.comp_op() || st.image_filters().size() > 0 || st.get_opacity() < 1)
|
||||
{
|
||||
style_level_compositing_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
style_level_compositing_ = false;
|
||||
}
|
||||
|
||||
if (style_level_compositing_ || st.image_filters().size() > 0)
|
||||
if (style_level_compositing_)
|
||||
{
|
||||
if (!internal_buffer_)
|
||||
{
|
||||
internal_buffer_ = boost::make_shared<buffer_type>(pixmap_.width(),pixmap_.height());
|
||||
}
|
||||
else
|
||||
{
|
||||
internal_buffer_->set_background(color(0,0,0,0)); // fill with transparent colour
|
||||
}
|
||||
current_buffer_ = internal_buffer_.get();
|
||||
}
|
||||
else
|
||||
|
@ -217,6 +227,8 @@ void agg_renderer<T>::start_style_processing(feature_type_style const& st)
|
|||
template <typename T>
|
||||
void agg_renderer<T>::end_style_processing(feature_type_style const& st)
|
||||
{
|
||||
if (style_level_compositing_)
|
||||
{
|
||||
bool blend_from = false;
|
||||
if (st.image_filters().size() > 0)
|
||||
{
|
||||
|
@ -230,11 +242,11 @@ void agg_renderer<T>::end_style_processing(feature_type_style const& st)
|
|||
|
||||
if (st.comp_op())
|
||||
{
|
||||
composite(pixmap_.data(),current_buffer_->data(), *st.comp_op(), 1.0f, 0, 0, false);
|
||||
composite(pixmap_.data(),current_buffer_->data(), *st.comp_op(), st.get_opacity(), 0, 0, false);
|
||||
}
|
||||
else if (blend_from)
|
||||
else if (blend_from || st.get_opacity() < 1)
|
||||
{
|
||||
composite(pixmap_.data(),current_buffer_->data(), src_over, 1.0f, 0, 0, false);
|
||||
composite(pixmap_.data(),current_buffer_->data(), src_over, st.get_opacity(), 0, 0, false);
|
||||
}
|
||||
|
||||
// apply any 'direct' image filters
|
||||
|
@ -243,7 +255,7 @@ void agg_renderer<T>::end_style_processing(feature_type_style const& st)
|
|||
{
|
||||
boost::apply_visitor(visitor, filter_tag);
|
||||
}
|
||||
|
||||
}
|
||||
MAPNIK_LOG_DEBUG(agg_renderer) << "agg_renderer: End processing style";
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ feature_type_style::feature_type_style()
|
|||
: filter_mode_(FILTER_ALL),
|
||||
filters_(),
|
||||
direct_filters_(),
|
||||
scale_denom_validity_(-1)
|
||||
scale_denom_validity_(-1),
|
||||
opacity_(1.0f)
|
||||
{}
|
||||
|
||||
feature_type_style::feature_type_style(feature_type_style const& rhs, bool deep_copy)
|
||||
|
@ -46,7 +47,8 @@ feature_type_style::feature_type_style(feature_type_style const& rhs, bool deep_
|
|||
filters_(rhs.filters_),
|
||||
direct_filters_(rhs.direct_filters_),
|
||||
comp_op_(rhs.comp_op_),
|
||||
scale_denom_validity_(-1)
|
||||
scale_denom_validity_(-1),
|
||||
opacity_(rhs.opacity_)
|
||||
{
|
||||
if (!deep_copy) {
|
||||
rules_ = rhs.rules_;
|
||||
|
@ -67,6 +69,7 @@ feature_type_style& feature_type_style::operator=(feature_type_style const& rhs)
|
|||
direct_filters_ = rhs.direct_filters_;
|
||||
comp_op_ = rhs.comp_op_;
|
||||
scale_denom_validity_ = -1;
|
||||
opacity_= rhs.opacity_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -126,6 +129,16 @@ boost::optional<composite_mode_e> feature_type_style::comp_op() const
|
|||
return comp_op_;
|
||||
}
|
||||
|
||||
void feature_type_style::set_opacity(float opacity)
|
||||
{
|
||||
opacity_ = opacity;
|
||||
}
|
||||
|
||||
float feature_type_style::get_opacity() const
|
||||
{
|
||||
return opacity_;
|
||||
}
|
||||
|
||||
void feature_type_style::update_rule_cache(double scale_denom)
|
||||
{
|
||||
if_rules_.clear();
|
||||
|
|
|
@ -433,8 +433,13 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
|
|||
}
|
||||
}
|
||||
|
||||
// image filters
|
||||
optional<float> opacity = sty.get_opt_attr<float>("opacity");
|
||||
if (opacity)
|
||||
{
|
||||
style.set_opacity(*opacity);
|
||||
}
|
||||
|
||||
// image filters
|
||||
mapnik::image_filter_grammar<std::string::const_iterator,
|
||||
std::vector<mapnik::filter::filter_type> > filter_grammar;
|
||||
|
||||
|
|
|
@ -518,7 +518,6 @@ void serialize_style( ptree & map_node, Map::const_style_iterator style_it, bool
|
|||
{
|
||||
feature_type_style const& style = style_it->second;
|
||||
std::string const& name = style_it->first;
|
||||
filter_mode_e filter_mode = style.get_filter_mode();
|
||||
|
||||
ptree & style_node = map_node.push_back(
|
||||
ptree::value_type("Style", ptree()))->second;
|
||||
|
@ -526,11 +525,18 @@ void serialize_style( ptree & map_node, Map::const_style_iterator style_it, bool
|
|||
set_attr(style_node, "name", name);
|
||||
|
||||
feature_type_style dfl;
|
||||
filter_mode_e filter_mode = style.get_filter_mode();
|
||||
if (filter_mode != dfl.get_filter_mode() || explicit_defaults)
|
||||
{
|
||||
set_attr(style_node, "filter-mode", filter_mode);
|
||||
}
|
||||
|
||||
double opacity = style.get_opacity();
|
||||
if (opacity != dfl.get_opacity() || explicit_defaults)
|
||||
{
|
||||
set_attr(style_node, "opacity", opacity);
|
||||
}
|
||||
|
||||
rules::const_iterator it = style.get_rules().begin();
|
||||
rules::const_iterator end = style.get_rules().end();
|
||||
for (; it != end; ++it)
|
||||
|
|
Loading…
Reference in a new issue