mapnik / mapnik-support

Use the issues queue here to ask questions and offer help on using Mapnik (maybe if this works well we can retire the mailing list at http://mapnik.org/contact/?)
6 stars 6 forks source link

C++ Text Symbolizer and checking label_placement #127

Open millapet opened 5 years ago

millapet commented 5 years ago

Hi! I am trying to print out the set values of various symbolizers and am having a hard time with getting enum as string from the TextSymbolizer. I would appreciate a nudge in the right direction as I have read through the mapnik code but I think I still don't fully understand this.

When I try getting a value that has previously been set in TextSymbolizer and label_placement, the resulting enum is always the default one (point), no matter to what I set it beforehand. Setting it up:

text_symbolizer text_sym;
text_placements_ptr placement_finder = std::make_shared<text_placements_dummy>();
placement_finder->defaults.format_defaults.face_name = "DejaVu Sans Book";
placement_finder->defaults.format_defaults.text_size = 24;
mapnik::label_placement_e e;
e.from_string("line");
placement_finder->defaults.expressions.label_placement = enumeration_wrapper(e);
mapnik::put<text_placements_ptr>(text_sym, keys::text_placements_, placement_finder);

Trying to get the set value back:

mapnik::label_placement_e plc = mapnik::get<mapnik::label_placement_enum>(text_sym, mapnik::keys::label_placement);
std::cout << plc.as_string() << std::endl;

The above code prints "point", even though I have set the value to "line" before. I assume the value is set correctly, since it renders the correct placement in the output file.

I also tried getting the value through the _text_placementsptr, but I am not sure how to convert the _symbolizer_base::valuetype into anything useful.

I had no trouble getting and printing the enum from MarkersSymbolizer like so :

markers_symbolizer is;
mapnik::marker_placement_e plc = mapnik::get<mapnik::marker_placement_enum>(is, mapnik::keys::markers_placement_type); 
std::cout<< plc.as_string() << std::endl;

Any help with this would be much appreciated, thank you!