/** * Creates a simple label. The caller is responsible for placing it in the scene. */ osg::Node* createNode( const std::string& text, const TextSymbol* symbol ) { Controls::LabelControl* label = new Controls::LabelControl( text ); if ( symbol ) { if ( symbol->fill().isSet() ) label->setForeColor( symbol->fill()->color() ); if ( symbol->halo().isSet() ) label->setHaloColor( symbol->halo()->color() ); if ( symbol->size().isSet() ) label->setFontSize( *symbol->size() ); if ( symbol->font().isSet() ) label->setFont( osgText::readFontFile(*symbol->font()) ); if ( symbol->encoding().isSet() ) { osgText::String::Encoding enc; switch(symbol->encoding().value()) { case TextSymbol::ENCODING_ASCII: enc = osgText::String::ENCODING_ASCII; break; case TextSymbol::ENCODING_UTF8: enc = osgText::String::ENCODING_UTF8; break; case TextSymbol::ENCODING_UTF16: enc = osgText::String::ENCODING_UTF16; break; case TextSymbol::ENCODING_UTF32: enc = osgText::String::ENCODING_UTF32; break; default: enc = osgText::String::ENCODING_UNDEFINED; break; } label->setEncoding( enc ); } } Controls::ControlNode* node = new Controls::ControlNode( label ); return node; }
/** * Creates a simple label. The caller is responsible for placing it in the scene. */ osg::Node* createNode( const std::string& text, const Style& style ) { const TextSymbol* symbol = style.get<TextSymbol>(); Controls::LabelControl* label = new Controls::LabelControl( text ); if ( symbol ) { if ( symbol->fill().isSet() ) label->setForeColor( symbol->fill()->color() ); if ( symbol->halo().isSet() ) label->setHaloColor( symbol->halo()->color() ); //if ( symbol->size().isSet() ) // label->setFontSize( *symbol->size() ); if ( symbol->font().isSet() ) { osgText::Font* font = osgText::readFontFile(*symbol->font() ); // mitigates mipmapping issues that cause rendering artifacts for some fonts/placement if ( font ) font->setGlyphImageMargin( 2 ); label->setFont( font ); } if ( symbol->encoding().isSet() ) { osgText::String::Encoding enc; switch(symbol->encoding().value()) { case TextSymbol::ENCODING_ASCII: enc = osgText::String::ENCODING_ASCII; break; case TextSymbol::ENCODING_UTF8: enc = osgText::String::ENCODING_UTF8; break; case TextSymbol::ENCODING_UTF16: enc = osgText::String::ENCODING_UTF16; break; case TextSymbol::ENCODING_UTF32: enc = osgText::String::ENCODING_UTF32; break; default: enc = osgText::String::ENCODING_UNDEFINED; break; } label->setEncoding( enc ); } } Controls::ControlNode* node = new Controls::ControlNode( label ); return node; }
/** * Creates a complete set of positioned label nodes from a feature list. */ osg::Node* createNode( const FeatureList& input, const TextSymbol* text, const FilterContext& context ) { osg::Group* group = 0L; std::set<std::string> used; // to prevent dupes bool skipDupes = (text->removeDuplicateLabels() == true); StringExpression contentExpr ( *text->content() ); NumericExpression priorityExpr( *text->priority() ); bool makeECEF = false; if ( context.isGeoreferenced() ) { makeECEF = context.getSession()->getMapInfo().isGeocentric(); } for( FeatureList::const_iterator i = input.begin(); i != input.end(); ++i ) { const Feature* feature = i->get(); if ( !feature ) continue; const Geometry* geom = feature->getGeometry(); if ( !geom ) continue; osg::Vec3d centroid = geom->getBounds().center(); if ( makeECEF ) { context.profile()->getSRS()->transformToECEF( centroid, centroid ); } const std::string& value = feature->eval( contentExpr, &context ); if ( !value.empty() && (!skipDupes || used.find(value) == used.end()) ) { if ( !group ) { group = new osg::Group(); } double priority = feature->eval( priorityExpr, &context ); Controls::LabelControl* label = new Controls::LabelControl( value ); if ( text->fill().isSet() ) label->setForeColor( text->fill()->color() ); if ( text->halo().isSet() ) label->setHaloColor( text->halo()->color() ); if ( text->size().isSet() ) label->setFontSize( *text->size() ); if ( text->font().isSet() ) label->setFont( osgText::readFontFile(*text->font()) ); Controls::ControlNode* node = new Controls::ControlNode( label, priority ); osg::MatrixTransform* xform = new osg::MatrixTransform( osg::Matrixd::translate(centroid) ); xform->addChild( node ); // for a geocentric map, do a simple dot product cull. if ( makeECEF ) { xform->setCullCallback( new CullNodeByHorizon( centroid, context.getSession()->getMapInfo().getProfile()->getSRS()->getEllipsoid()) ); group->addChild( xform ); } else { group->addChild( xform ); } if ( skipDupes ) { used.insert( value ); } } } return group; }
/** * Creates a complete set of positioned label nodes from a feature list. */ osg::Node* createNode( const FeatureList& input, const Style& style, const FilterContext& context ) { const TextSymbol* text = style.get<TextSymbol>(); osg::Group* group = 0L; std::set<std::string> used; // to prevent dupes bool skipDupes = (text->removeDuplicateLabels() == true); StringExpression contentExpr ( *text->content() ); NumericExpression priorityExpr( *text->priority() ); //bool makeECEF = false; const SpatialReference* ecef = 0L; if ( context.isGeoreferenced() ) { //makeECEF = context.getSession()->getMapInfo().isGeocentric(); ecef = context.getSession()->getMapSRS()->getECEF(); } for( FeatureList::const_iterator i = input.begin(); i != input.end(); ++i ) { const Feature* feature = i->get(); if ( !feature ) continue; const Geometry* geom = feature->getGeometry(); if ( !geom ) continue; osg::Vec3d centroid = geom->getBounds().center(); if ( ecef ) { context.profile()->getSRS()->transform( centroid, ecef, centroid ); //context.profile()->getSRS()->transformToECEF( centroid, centroid ); } const std::string& value = feature->eval( contentExpr, &context ); if ( !value.empty() && (!skipDupes || used.find(value) == used.end()) ) { if ( !group ) { group = new osg::Group(); } double priority = feature->eval( priorityExpr, &context ); Controls::LabelControl* label = new Controls::LabelControl( value ); if ( text->fill().isSet() ) label->setForeColor( text->fill()->color() ); if ( text->halo().isSet() ) label->setHaloColor( text->halo()->color() ); //if ( text->size().isSet() ) // label->setFontSize( *text->size() ); if ( text->font().isSet() ) { // mitigates mipmapping issues that cause rendering artifacts for some fonts/placement osgText::Font* font = osgText::readFontFile(*text->font() ); // mitigates mipmapping issues that cause rendering artifacts for some fonts/placement if ( font ) font->setGlyphImageMargin( 2 ); label->setFont( font ); } Controls::ControlNode* node = new Controls::ControlNode( label, priority ); osg::MatrixTransform* xform = new osg::MatrixTransform( osg::Matrixd::translate(centroid) ); xform->addChild( node ); // for a geocentric map, do a simple dot product cull. if ( ecef ) { xform->setCullCallback( new HorizonCullCallback(*ecef->getEllipsoid()) ); group->addChild( xform ); } else { group->addChild( xform ); } if ( skipDupes ) { used.insert( value ); } } } return group; }