make shield_symbolizer to work with point geometries (TODO!!)
This commit is contained in:
parent
85e713f4c7
commit
3b85ebad9b
3 changed files with 90 additions and 26 deletions
|
@ -476,29 +476,69 @@ 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);
|
faces->get_string_info(info);
|
||||||
|
|
||||||
placement_finder<label_collision_detector4> finder(detector_);
|
|
||||||
|
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();
|
||||||
|
if (sym.get_label_placement() == POINT_PLACEMENT)
|
||||||
|
{
|
||||||
|
double label_x;
|
||||||
|
double label_y;
|
||||||
|
double z=0.0;
|
||||||
|
geom.label_position(&label_x, &label_y);
|
||||||
|
prj_trans.backward(label_x,label_y, z);
|
||||||
|
t_.forward(&label_x,&label_y);
|
||||||
|
finder.find_point_placement(text_placement,label_x,label_y);
|
||||||
|
|
||||||
|
for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii)
|
||||||
|
{
|
||||||
|
double x = text_placement.placements[ii].starting_x;
|
||||||
|
double y = text_placement.placements[ii].starting_y;
|
||||||
|
// remove displacement from image label
|
||||||
|
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));
|
||||||
|
|
||||||
|
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);
|
finder.find_point_placements<path_type>(text_placement,path);
|
||||||
|
|
||||||
for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii)
|
for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii)
|
||||||
{
|
{
|
||||||
int w = data->width();
|
int w = data->width();
|
||||||
int h = data->height();
|
int h = data->height();
|
||||||
|
|
||||||
double x = text_placement.placements[ii].starting_x;
|
double x = text_placement.placements[ii].starting_x;
|
||||||
double y = text_placement.placements[ii].starting_y;
|
double y = text_placement.placements[ii].starting_y;
|
||||||
|
|
||||||
|
@ -508,9 +548,10 @@ namespace mapnik
|
||||||
pixmap_.set_rectangle_alpha(px,py,*data);
|
pixmap_.set_rectangle_alpha(px,py,*data);
|
||||||
|
|
||||||
Envelope<double> dim = ren.prepare_glyphs(&text_placement.placements[ii]);
|
Envelope<double> dim = ren.prepare_glyphs(&text_placement.placements[ii]);
|
||||||
|
|
||||||
ren.render(x,y);
|
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
|
||||||
{
|
{
|
||||||
|
|
|
@ -849,6 +849,28 @@ 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 =
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue