osgEarth 2.1.1
Public Member Functions

OverlayLabelSource Class Reference

Inheritance diagram for OverlayLabelSource:
Collaboration diagram for OverlayLabelSource:

List of all members.

Public Member Functions

 OverlayLabelSource (const LabelSourceOptions &options)
osg::Node * createNode (const FeatureList &input, const TextSymbol *text, const FilterContext &context)

Detailed Description

Definition at line 34 of file OverlayLabelSource.cpp.


Constructor & Destructor Documentation

OverlayLabelSource::OverlayLabelSource ( const LabelSourceOptions options) [inline]

Definition at line 37 of file OverlayLabelSource.cpp.

                                                            :
      LabelSource( options )
    {
        //nop
    }

Member Function Documentation

osg::Node* OverlayLabelSource::createNode ( const FeatureList input,
const TextSymbol symbol,
const FilterContext context 
) [inline, virtual]

Subclass implements this method to create the labeling node.

Implements osgEarth::Features::LabelSource.

Definition at line 43 of file OverlayLabelSource.cpp.

    {
        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() );

        const MapInfo& mi = context.getSession()->getMapInfo();
        bool makeECEF = mi.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();
            //osg::Vec3d centroidWorld = context.toWorld(centroid);

            if ( makeECEF )
            {
                context.profile()->getSRS()->transformToECEF( centroid, centroid );
            }

#if 0
            if ( context.isGeocentric() && geom->getComponentType() != Geometry::TYPE_POINTSET )
            {
                // "clamp" the centroid to the ellipsoid
                osg::Vec3d centroidMap;
                mi.worldPointToMapPoint(centroidWorld, centroidMap);
                centroidMap.z() = 0.0;
                mi.mapPointToWorldPoint(centroidMap, centroidWorld);
                centroid = context.toLocal(centroidWorld);
            }
#endif

            const std::string& value = feature->eval( contentExpr );

            if ( !value.empty() && (!skipDupes || used.find(value) == used.end()) )
            {
                if ( !group )
                {
                    group = new osg::Group();
                }

                double priority = feature->eval( priorityExpr );

                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, mi.getProfile()->getSRS()->getEllipsoid()) );
                    group->addChild( xform );
                }
                else
                {
                    group->addChild( xform );
                }

                if ( skipDupes )
                    used.insert( value );
            }
        }

        return group;
    }

Here is the call graph for this function:


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines