make shield_symbolizer to work with point geometries (TODO!!)

This commit is contained in:
Artem Pavlenko 2008-09-15 08:48:21 +00:00
parent 85e713f4c7
commit 3b85ebad9b
3 changed files with 90 additions and 26 deletions

View file

@ -476,40 +476,81 @@ namespace mapnik
ren.set_pixel_size(sym.get_text_size()); ren.set_pixel_size(sym.get_text_size());
ren.set_fill(sym.get_fill()); ren.set_fill(sym.get_fill());
ren.set_halo_fill(sym.get_halo_fill());
ren.set_halo_radius(sym.get_halo_radius());
placement_finder<label_collision_detector4> finder(detector_);
string_info info(text); string_info info(text);
faces->get_string_info(info);
placement_finder<label_collision_detector4> finder(detector_); faces->get_string_info(info);
int w = data->width();
int h = data->height();
unsigned num_geom = feature.num_geometries(); unsigned num_geom = feature.num_geometries();
for (unsigned i=0;i<num_geom;++i) for (unsigned i=0;i<num_geom;++i)
{ {
geometry2d const& geom = feature.get_geometry(i); geometry2d const& geom = feature.get_geometry(i);
if (geom.num_points() > 0) // don't bother with empty geometries if (geom.num_points() > 0 )
{ {
path_type path(t_,geom,prj_trans); path_type path(t_,geom,prj_trans);
placement text_placement(info, sym); placement text_placement(info, sym);
text_placement.avoid_edges = sym.get_avoid_edges(); text_placement.avoid_edges = sym.get_avoid_edges();
finder.find_point_placements<path_type>(text_placement,path); if (sym.get_label_placement() == POINT_PLACEMENT)
{
for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii) double label_x;
{ double label_y;
int w = data->width(); double z=0.0;
int h = data->height(); geom.label_position(&label_x, &label_y);
prj_trans.backward(label_x,label_y, z);
double x = text_placement.placements[ii].starting_x; t_.forward(&label_x,&label_y);
double y = text_placement.placements[ii].starting_y; finder.find_point_placement(text_placement,label_x,label_y);
int px=int(x - (w/2)); for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii)
int py=int(y - (h/2)); {
double x = text_placement.placements[ii].starting_x;
pixmap_.set_rectangle_alpha(px,py,*data); double y = text_placement.placements[ii].starting_y;
// remove displacement from image label
Envelope<double> dim = ren.prepare_glyphs(&text_placement.placements[ii]); position pos = sym.get_displacement();
double lx = x - boost::get<0>(pos);
double ly = y - boost::get<1>(pos);
int px=int(lx - (0.5 * w)) ;
int py=int(ly - (0.5 * h)) ;
Envelope<double> label_ext (floor(lx - 0.5 * w), floor(ly - 0.5 * h), ceil (lx + 0.5 * w), ceil (ly + 0.5 * h));
ren.render(x,y); if ( detector_.has_placement(label_ext))
{
pixmap_.set_rectangle_alpha(px,py,*data);
Envelope<double> dim = ren.prepare_glyphs(&text_placement.placements[ii]);
ren.render(x,y);
detector_.insert(label_ext);
}
}
finder.update_detector(text_placement);
}
else if (geom.num_points() > 1 && sym.get_label_placement() == LINE_PLACEMENT)
{
finder.find_point_placements<path_type>(text_placement,path);
for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii)
{
int w = data->width();
int h = data->height();
double x = text_placement.placements[ii].starting_x;
double y = text_placement.placements[ii].starting_y;
int px=int(x - (w/2));
int py=int(y - (h/2));
pixmap_.set_rectangle_alpha(px,py,*data);
Envelope<double> dim = ren.prepare_glyphs(&text_placement.placements[ii]);
ren.render(x,y);
}
finder.update_detector(text_placement);
} }
} }
} }
@ -722,6 +763,7 @@ namespace mapnik
prj_trans.backward(label_x,label_y, z); prj_trans.backward(label_x,label_y, z);
t_.forward(&label_x,&label_y); t_.forward(&label_x,&label_y);
finder.find_point_placement(text_placement,label_x,label_y); finder.find_point_placement(text_placement,label_x,label_y);
finder.update_detector(text_placement);
} }
else //LINE_PLACEMENT else //LINE_PLACEMENT
{ {

View file

@ -849,7 +849,29 @@ namespace mapnik
{ {
throw config_error(std::string("Must have face_name or fontset_name")); throw config_error(std::string("Must have face_name or fontset_name"));
} }
// text displacement
int dx = get_attr(sym, "dx", 0);
int dy = get_attr(sym, "dy", 0);
shield_symbol.set_displacement(dx,dy);
label_placement_e placement =
get_attr<label_placement_e>(sym, "placement", POINT_PLACEMENT);
shield_symbol.set_label_placement( placement );
// halo fill and radius
optional<Color> halo_fill = get_opt_attr<Color>(sym, "halo_fill");
if (halo_fill)
{
shield_symbol.set_halo_fill( * halo_fill );
}
optional<unsigned> halo_radius =
get_opt_attr<unsigned>(sym, "halo_radius");
if (halo_radius)
{
shield_symbol.set_halo_radius(*halo_radius);
}
// minimum distance between labels // minimum distance between labels
optional<unsigned> min_distance = optional<unsigned> min_distance =
get_opt_attr<unsigned>(sym, "min_distance"); get_opt_attr<unsigned>(sym, "min_distance");

View file

@ -62,7 +62,7 @@ namespace mapnik
max_char_angle_delta(sym.get_max_char_angle_delta()), max_char_angle_delta(sym.get_max_char_angle_delta()),
minimum_distance(sym.get_minimum_distance()), minimum_distance(sym.get_minimum_distance()),
avoid_edges(sym.get_avoid_edges()), avoid_edges(sym.get_avoid_edges()),
has_dimensions(true), has_dimensions(false),
dimensions(std::make_pair(sym.get_image()->width(), dimensions(std::make_pair(sym.get_image()->width(),
sym.get_image()->height())) sym.get_image()->height()))
{ {
@ -309,7 +309,7 @@ namespace mapnik
for (unsigned i = 0; i < p.info.num_characters(); i++) for (unsigned i = 0; i < p.info.num_characters(); i++)
{ {
character_info ci;; character_info ci;
ci = p.info.at(i); ci = p.info.at(i);
unsigned c = ci.character; unsigned c = ci.character;
@ -325,7 +325,7 @@ namespace mapnik
else else
{ {
current_placement->add_node(c, x, y, 0.0); current_placement->add_node(c, x, y, 0.0);
Envelope<double> e; Envelope<double> e;
if (p.has_dimensions) if (p.has_dimensions)
{ {
@ -355,7 +355,7 @@ namespace mapnik
x += ci.width; x += ci.width;
} }
p.placements.push_back(current_placement.release()); p.placements.push_back(current_placement.release());
update_detector(p); //update_detector(p);
} }