From f571cd976366ddfd7540f2584be917b5776d71f3 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 3 May 2012 16:45:40 -0400 Subject: [PATCH] fixup clamping logic for markers symbolizer and sync with agg implementation --- src/grid/process_markers_symbolizer.cpp | 48 ++++++++++++++++++------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/grid/process_markers_symbolizer.cpp b/src/grid/process_markers_symbolizer.cpp index 7c57b80b4..ca094af0d 100644 --- a/src/grid/process_markers_symbolizer.cpp +++ b/src/grid/process_markers_symbolizer.cpp @@ -71,7 +71,8 @@ void grid_renderer::process(markers_symbolizer const& sym, agg::trans_affine tr; boost::array const& m = sym.get_transform(); tr.load_from(&m[0]); - tr = agg::trans_affine_scaling(scale_factor_*(1.0/pixmap_.get_resolution())) * tr; + unsigned int res = pixmap_.get_resolution(); + tr = agg::trans_affine_scaling(scale_factor_*(1.0/res)) * tr; std::string filename = path_processor_type::evaluate(*sym.get_filename(), *feature); marker_placement_e placement_method = sym.get_marker_placement(); marker_type_e marker_type = sym.get_marker_type(); @@ -87,6 +88,11 @@ void grid_renderer::process(markers_symbolizer const& sym, double y1 = bbox.miny(); double x2 = bbox.maxx(); double y2 = bbox.maxy(); + double w = (*mark)->width(); + double h = (*mark)->height(); + // clamp sizes + w = std::max(w,4.0); + h = std::max(w,4.0); agg::trans_affine recenter = agg::trans_affine_translation(-0.5*(x1+x2),-0.5*(y1+y2)); tr.transform(&x1,&y1); @@ -104,11 +110,27 @@ void grid_renderer::process(markers_symbolizer const& sym, for (unsigned i=0; inum_geometries(); ++i) { geometry_type & geom = feature->get_geometry(i); - if (geom.num_points() <= 1) + if (placement_method == MARKER_POINT_PLACEMENT || geom.num_points() <= 1) { - MAPNIK_LOG_WARN(grid_renderer) << "grid_renderer: markers_symbolizer points do not yet support SVG markers"; + double x; + double y; + double z=0; + geom.label_interior_position(&x, &y); + prj_trans.backward(x,y,z); + t_.forward(&x,&y); + extent.re_center(x,y); - continue; + if (sym.get_allow_overlap() || + detector_.has_placement(extent)) + { + + render_marker(feature, + pixmap_.get_resolution(), + pixel_position(x - 0.5 * w, y - 0.5 * h), + **mark, + tr, + sym.get_opacity()); + } } path_type path(t_,geom,prj_trans); @@ -131,20 +153,17 @@ void grid_renderer::process(markers_symbolizer const& sym, } else { - stroke const& stroke_ = sym.get_stroke(); - double strk_width = stroke_.get_width(); double w; double h; - unsigned int res = pixmap_.get_resolution(); - if (res != 1) { - // clamp to at least 4 px otherwise interactive pixels can be too small - double min = static_cast(4/pixmap_.get_resolution()); + // 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); + } else { + double min = static_cast(4.0/res); w = std::max(sym.get_width()/res,min); h = std::max(sym.get_height()/res,min); - } else { - w = sym.get_width()/res; - h = sym.get_height()/res; } double rx = w/2.0; @@ -153,6 +172,9 @@ void grid_renderer::process(markers_symbolizer const& sym, arrow arrow_; box2d extent; + stroke const& stroke_ = sym.get_stroke(); + double strk_width = stroke_.get_width(); + double dx = w + (2*strk_width); double dy = h + (2*strk_width);