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 - getting the field name #121

Closed millapet closed 5 years ago

millapet commented 5 years ago

Hello, I am using Mapnik 3 and attempting to get back the values I set using the Text Symbolizer and I am having trouble with getting the field name.

I set it like this (same as in the demo): placement_finder->defaults.set_format_tree(std::make_shared<mapnik::formatting::text_node>(parse_expression("[FIELD_NAME]")));

And now I would like to get _[FIELDNAME] back, ideally as a string. Is there such a way?

With the other properties it's pretty straightforward, but I would appreciate a nudge in the right direction for this. Petra

talaj commented 5 years ago

The placement_finder->defaults has format_tree() member which should return the text_node with get_text() method, which returns the expression instance of [FIELD_NAME]. There is to_expression_string() function to convert the expression instance back to string.

The format_tree() returns a smart pointer to base class, so the pointer has to be dynamic-casted to text_node to be able to call get_text() on it.

millapet commented 5 years ago

Excellent! Thank you very much!