LineString overlaping on LabelNode

classic Classic list List threaded Threaded
4 messages Options
krzysief krzysief
Reply | Threaded
Open this post in threaded view
|

LineString overlaping on LabelNode

Hi,

I try to draw a simple FeatureNode containing line string and add a label to it, here is my code:

//line
ref_ptr<Symbology::LineString> measureLine = new osgEarth::Symbology::LineString;

measureLine->push_back(start_point);
measureLine->push_back(end_point);

ref_ptr<Features::Feature> feature = new osgEarth::Features::Feature(measureLine, mapNode->getMapSRS());

ref_ptr<Symbology::LineSymbol> line = feature->style()->getOrCreate<osgEarth::Symbology::LineSymbol>();
line->stroke()->color() = color;
line->stroke()->width() = width;
line->stroke()->widthUnits() = osgEarth::Units::PIXELS;

ref_ptr<RenderSymbol> line_render = feature->style()->getOrCreateSymbol<RenderSymbol>();
line_render->order()   = order_counter;

ref_ptr<Annotation::FeatureNode> featureNode = new osgEarth::Annotation::FeatureNode(mapNode, feature);
group->addChild(featureNode);

//label

Style label_style;

ref_ptr<RenderSymbol> label_render = label_style.getOrCreateSymbol<RenderSymbol>();
label_render->order()   = order_counter + 1;

ref_ptr<TextSymbol> text_symbol   = label_style.getOrCreateSymbol<TextSymbol>();
text_symbol->fill()->color()  = color;
text_symbol->halo()->color()  = Color::White;
text_symbol->halo()->width()  = 5;
text_symbol->halo()->widthUnits() = Units::PIXELS;
text_symbol->haloOffset()  = .15f;
text_symbol->haloBackdropType()   = osgText::Text::OUTLINE;
//text_symbol->haloImplementation() = osgText::Text::STENCIL_BUFFER;
ref_ptr<osgText::Font> font  = osgText::readFontFile("DejaVuSans.ttf");
text_symbol->font()  = font->getFileName();
text_symbol->content()  = label_str;
text_symbol->size()  = 14;
text_symbol->alignment()  = TextSymbol::ALIGN_CENTER_CENTER;

ref_ptr<Annotation::LabelNode> label_node = new Annotation::LabelNode(mapNode, midpoint, label_style);
group->addChild(label_node);

But for some reason despite setting the RenderSymbol line overlaps the label like in the picture:



Have you got any ideas how can i repair it?

~ Thanks, Kris
remoe remoe
Reply | Threaded
Open this post in threaded view
|

Re: LineString overlaping on LabelNode

krzysief krzysief
Reply | Threaded
Open this post in threaded view
|

Re: LineString overlaping on LabelNode

Hi,
yes i tried

ref_ptr<RenderSymbol> line_render = feature->style()->getOrCreateSymbol<RenderSymbol>();
line_render->order()   = order_counter;

and

ref_ptr<RenderSymbol> label_render = label_style.getOrCreateSymbol<RenderSymbol>();
label_render->order()   = order_counter + 1;

apllying this to both nodes but it makes no difference, also tried mixing the values but there was no good result neither.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: LineString overlaping on LabelNode

The render order for text labels is set to 13. Geometry with a higher render order will obscure the text. The normal "render-order" symbology doesn't work on labels.

You can change that 13 to another number by calling

ScreenSpaceLayoutOptions options = ScreenSpaceLayout::getOptions();
options.renderOrder() = 99; // for example
ScreenSpaceLayout::setOptions(options);

Hope this helps.
Glenn Waldron / Pelican Mapping