Combining TextSymbol/LabelNode into FeatureNode

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

Combining TextSymbol/LabelNode into FeatureNode

Hi, in this thread: http://forum.osgearth.org/OSGEarth-Symbology-Classes-td5699108.html#a6862257

i read that: "The FeatureNode, on the other hand, renders a whole feature and honors all style information (including labels)."

And what i do in my code is drawing some geometry and rendering this as a FeatureNode and i want to also compose inside text label, i tried creating Feature's style as TextSymbol but i get runtime errors while building FeatureNode, what is the solution?
iyigitel iyigitel
Reply | Threaded
Open this post in threaded view
|

Re: Combining TextSymbol/LabelNode into FeatureNode

Hi, I have a problem similar to this. I am trying to add a FeatureNode with code. I add TextSymbol to the style of my annotation. Although I set the properties of TextSymbol like the code given below, the FeatureNode displays the feature but does not display my text? What may be the problem?
NOTE: I am using osgearth version 2.9

Style style;
std::string myStr("My sample text");
style.getOrCreate<TextSymbol>()->content() = myStr;
style.getOrCreate<TextSymbol>()->fill()->color() = Color(Color::Yellow);
style.getOrCreate<TextSymbol>()->font() = "arial.ttf";
style.getOrCreate<TextSymbol>()->size() = 18;
style.getOrCreate<TextSymbol>()->halo()->color() = Color(Color::White);
style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_CENTER_CENTER;

regards,
Iskender.
Iskender Yigitel
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Combining TextSymbol/LabelNode into FeatureNode

What does the rest of your styling look like. Some things, especially altitude clamping, can cause the text not to function properly.
Glenn Waldron / Pelican Mapping
iyigitel iyigitel
Reply | Threaded
Open this post in threaded view
|

Re: Combining TextSymbol/LabelNode into FeatureNode

Good guess. I have also AltitudeSymbol for my feature; clamping set to CLAMP_TO_TERRAIN and technique set do TECHNIQUE_DRAPE. What should I do to make it function properly?
Iskender Yigitel
krzysief krzysief
Reply | Threaded
Open this post in threaded view
|

Re: Combining TextSymbol/LabelNode into FeatureNode

In reply to this post by gwaldron
My code causing runtime error:

Symbology::GeometryFactory geometry_factory(mapNode->getMapSRS());
ref_ptr<osgEarth::Geometry> geometry = geometry_factory.createCircle(position, osgEarth::Linear(radius, osgEarth::Units::METERS));
       
        ref_ptr<Features::Feature> feature = new osgEarth::Features::Feature(geometry, mapNode->getMapSRS());

        ref_ptr<TextSymbol> text_symbol   = feature->style()->getOrCreateSymbol<TextSymbol>();
        text_symbol->fill()->color()  = color;
        text_symbol->halo()->color()  = Color::White;
        text_symbol->halo()->width()  = 50;
        text_symbol->halo()->widthUnits() = Units::PIXELS;
        text_symbol->haloOffset()  = .15f;
        text_symbol->haloBackdropType()   = osgText::Text::OUTLINE;
        text_symbol->content()  = std::to_string(radius);
        text_symbol->size()  = 14;
        text_symbol->alignment()  = TextSymbol::ALIGN_CENTER_CENTER;
        text_symbol->declutter() = true;
       
        ref_ptr<AltitudeSymbol> altitude = feature->style()->getOrCreate<osgEarth::Symbology::AltitudeSymbol>();
        altitude->clamping()    = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN;
        altitude->binding()    = osgEarth::Symbology::AltitudeSymbol::BINDING_VERTEX;
        altitude->technique()    = osgEarth::AltitudeSymbol::TECHNIQUE_SCENE;

        ref_ptr<Annotation::FeatureNode> featureNode = new osgEarth::Annotation::FeatureNode(mapNode, feature);
       
iyigitel iyigitel
Reply | Threaded
Open this post in threaded view
|

Re: Combining TextSymbol/LabelNode into FeatureNode

Hi, you can try this (at least it worked for me).

Style featureStyle;

featureStyle.getOrCreate<TextSymbol>()->fill()->color() = color;
featureStyle.getOrCreate<TextSymbol>()->halo()->color() = haloColor;
...
...
featureStyle.getOrCreate<AltitudeSymbol>()->clamping()= osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN;
...
...
 ref_ptr<Annotation::FeatureNode> featureNode = new osgEarth::Annotation::FeatureNode(mapNode, feature, featureStyle);

Iskender.
Iskender Yigitel
krzysief krzysief
Reply | Threaded
Open this post in threaded view
|

Re: Combining TextSymbol/LabelNode into FeatureNode

Thank you for reply, but unfortunately the error is still occurring.