Permalink
Browse files

move marker width/height to expressions - closes #1102 and replaces #…

  • Loading branch information...
1 parent d9afce1 commit 67e9b0d616e9469d8ef9fa8f6c1f2cb8b5793d42 Dane Springmeyer committed Jun 29, 2012
@@ -171,6 +171,16 @@ struct symbolizer_attributes : public boost::static_visitor<>
void operator () (markers_symbolizer const& sym)
{
+ expression_ptr const& height_expr = sym.get_height();
+ if (height_expr)
+ {
+ boost::apply_visitor(f_attr,*height_expr);
+ }
+ expression_ptr const& width_expr = sym.get_width();
+ if (width_expr)
+ {
+ boost::apply_visitor(f_attr,*width_expr);
+ }
collect_metawriter(sym);
collect_transform(sym.get_image_transform());
collect_transform(sym.get_transform());
@@ -29,6 +29,7 @@
#include <mapnik/color.hpp>
#include <mapnik/stroke.hpp>
#include <mapnik/enumeration.hpp>
+#include <mapnik/expression.hpp>
namespace mapnik {
@@ -66,10 +67,10 @@ struct MAPNIK_DECL markers_symbolizer :
double get_max_error() const;
void set_fill(color fill);
color const& get_fill() const;
- void set_width(double width);
- double get_width() const;
- void set_height(double height);
- double get_height() const;
+ void set_width(expression_ptr width);
+ expression_ptr get_width() const;
+ void set_height(expression_ptr height);
+ expression_ptr get_height() const;
stroke const& get_stroke() const;
void set_stroke(stroke const& stroke);
void set_marker_placement(marker_placement_e marker_p);
@@ -83,8 +84,8 @@ struct MAPNIK_DECL markers_symbolizer :
color fill_;
double spacing_;
double max_error_;
- double width_;
- double height_;
+ expression_ptr width_;
+ expression_ptr height_;
stroke stroke_;
marker_placement_e marker_p_;
marker_type_e marker_type_;
@@ -196,8 +196,9 @@ void agg_renderer<T>::process(markers_symbolizer const& sym,
unsigned s_g=col.green();
unsigned s_b=col.blue();
unsigned s_a=col.alpha();
- double w = sym.get_width();
- double h = sym.get_height();
+ double w = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_width()))).to_double() * scale_factor_;
+ double h = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_height()))).to_double() * scale_factor_;
+
double rx = w/2.0;
double ry = h/2.0;
View
@@ -1480,8 +1480,8 @@ void cairo_renderer_base::start_map_processing(Map const& map)
stroke const& stroke_ = sym.get_stroke();
color const& col = stroke_.get_color();
double strk_width = stroke_.get_width();
- double w = sym.get_width();
- double h = sym.get_height();
+ double w = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_width()))).to_double() * scale_factor_;
+ double h = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_height()))).to_double() * scale_factor_;
double rx = w/2.0;
double ry = h/2.0;
@@ -152,16 +152,16 @@ void grid_renderer<T>::process(markers_symbolizer const& sym,
else
{
- double w;
- double h;
+ double w = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_width()))).to_double() * scale_factor_;
+ double h = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_height()))).to_double() * scale_factor_;
// clamp to at least 4 px otherwise interactive pixels can be too small
if (res == 1) {
- w = std::max(sym.get_width(),4.0);
- h = std::max(sym.get_height(),4.0);
+ w = std::max(w,4.0);
+ h = std::max(h,4.0);
} else {
double min = static_cast<double>(4.0/res);
- w = std::max(sym.get_width()/res,min);
- h = std::max(sym.get_height()/res,min);
+ w = std::max(w/res,min);
+ h = std::max(h/res,min);
}
double rx = w/2.0;
View
@@ -1045,8 +1045,9 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym)
if (allow_overlap) symbol.set_allow_overlap(*allow_overlap);
if (ignore_placement) symbol.set_ignore_placement(*ignore_placement);
- optional<double> w = sym.get_opt_attr<double>("width");
- optional<double> h = sym.get_opt_attr<double>("height");
+ optional<expression_ptr> w = sym.get_opt_attr<expression_ptr>("width");
+ optional<expression_ptr> h = sym.get_opt_attr<expression_ptr>("height");
+
if (w && h)
{
symbol.set_width(*w);
View
@@ -23,6 +23,9 @@
// mapnik
#include <mapnik/markers_symbolizer.hpp>
+// boost
+#include <boost/make_shared.hpp>
+
namespace mapnik {
static const char * marker_placement_strings[] = {
@@ -50,8 +53,8 @@ markers_symbolizer::markers_symbolizer()
fill_(color(0,0,255)),
spacing_(100.0),
max_error_(0.2),
- width_(10.0),
- height_(10.0),
+ width_(boost::make_shared<expr_node>(10.0)),
+ height_(boost::make_shared<expr_node>(10.0)),
stroke_(),
marker_p_(MARKER_LINE_PLACEMENT),
marker_type_(MARKER_ARROW) {}
@@ -64,8 +67,8 @@ markers_symbolizer::markers_symbolizer(path_expression_ptr filename)
fill_(color(0,0,255)),
spacing_(100.0),
max_error_(0.2),
- width_(10.0),
- height_(10.0),
+ width_(boost::make_shared<expr_node>(10.0)),
+ height_(boost::make_shared<expr_node>(10.0)),
stroke_(),
marker_p_(MARKER_LINE_PLACEMENT),
marker_type_(MARKER_ARROW) {}
@@ -134,22 +137,22 @@ color const& markers_symbolizer::get_fill() const
return fill_;
}
-void markers_symbolizer::set_width(double width)
+void markers_symbolizer::set_width(expression_ptr width)
{
width_ = width;
}
-double markers_symbolizer::get_width() const
+expression_ptr markers_symbolizer::get_width() const
{
return width_;
}
-void markers_symbolizer::set_height(double height)
+void markers_symbolizer::set_height(expression_ptr height)
{
height_ = height;
}
-double markers_symbolizer::get_height() const
+expression_ptr markers_symbolizer::get_height() const
{
return height_;
}
View
@@ -288,11 +288,11 @@ class serialize_symbolizer : public boost::static_visitor<>
}
if (sym.get_width() != dfl.get_width() || explicit_defaults_)
{
- set_attr( sym_node, "width", sym.get_width() );
+ set_attr( sym_node, "width", to_expression_string(*sym.get_width()) );
}
if (sym.get_height() != dfl.get_height() || explicit_defaults_)
{
- set_attr( sym_node, "height", sym.get_height() );
+ set_attr( sym_node, "height", to_expression_string(*sym.get_height()) );
}
if (sym.get_marker_type() != dfl.get_marker_type() || explicit_defaults_)
{
@@ -134,6 +134,18 @@ def test_markersymbolizer_init():
eq_(p.ignore_placement,False)
eq_(p.spacing,100)
eq_(p.max_error,0.2)
+ eq_(str(p.width),'10.0')
+ eq_(str(p.height),'10.0')
+
+ p.width = mapnik.Expression('12')
+ p.height = mapnik.Expression('12')
+ eq_(str(p.width),'12')
+ eq_(str(p.height),'12')
+
+ p.width = mapnik.Expression('[field] + 2')
+ p.height = mapnik.Expression('[field] + 2')
+ eq_(str(p.width),'([field]+2)')
+ eq_(str(p.height),'([field]+2)')
stroke = mapnik.Stroke()
stroke.color = mapnik.Color('black')
@@ -57,8 +57,8 @@ def create_grid_map(width,height):
s = mapnik.Style()
r = mapnik.Rule()
symb = mapnik.MarkersSymbolizer()
- symb.width = 10
- symb.height = 10
+ symb.width = mapnik.Expression('10')
+ symb.height = mapnik.Expression('10')
symb.allow_overlap = True
r.symbols.append(symb)
@@ -146,8 +146,8 @@ def test_render_grid():
s = mapnik.Style()
r = mapnik.Rule()
symb = mapnik.MarkersSymbolizer()
- symb.width = 10
- symb.height = 10
+ symb.width = mapnik.Expression('10')
+ symb.height = mapnik.Expression('10')
symb.allow_overlap = True
r.symbols.append(symb)
s.rules.append(r)

0 comments on commit 67e9b0d

Please sign in to comment.