osgEarth 2.1.1
Public Member Functions | Public Attributes

MouseCoordsHandler Struct Reference

Collaboration diagram for MouseCoordsHandler:

List of all members.

Public Member Functions

 MouseCoordsHandler (LabelControl *label, osgEarth::MapNode *mapNode)
bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)

Public Attributes

osg::ref_ptr< LabelControl_label
MapNode_mapNode
osg::NodePath _mapNodePath

Detailed Description

Definition at line 98 of file osgearth_viewer.cpp.


Constructor & Destructor Documentation

MouseCoordsHandler::MouseCoordsHandler ( LabelControl label,
osgEarth::MapNode mapNode 
) [inline]

Definition at line 100 of file osgearth_viewer.cpp.

        : _label( label ),
          _mapNode( mapNode )
    {
        _mapNodePath.push_back( mapNode->getTerrainEngine() );
    }

Here is the call graph for this function:


Member Function Documentation

bool MouseCoordsHandler::handle ( const osgGA::GUIEventAdapter &  ea,
osgGA::GUIActionAdapter &  aa 
) [inline]

Definition at line 107 of file osgearth_viewer.cpp.

    {
        osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
        if (ea.getEventType() == ea.MOVE || ea.getEventType() == ea.DRAG)
        {
            osgUtil::LineSegmentIntersector::Intersections results;
            if ( view->computeIntersections( ea.getX(), ea.getY(), _mapNodePath, results ) )
            {
                // find the first hit under the mouse:
                osgUtil::LineSegmentIntersector::Intersection first = *(results.begin());
                osg::Vec3d point = first.getWorldIntersectPoint();
                osg::Vec3d lla;

                // transform it to map coordinates:
                _mapNode->getMap()->worldPointToMapPoint(point, lla);

                std::stringstream ss;

                if ( s_mgrs )
                {
                    MGRSFormatter f( MGRSFormatter::PRECISION_1M );
                    ss << "MGRS: " << f.format(lla.y(), lla.x()) << "   ";
                }
                 // lat/long
                {
                    LatLongFormatter::AngularFormat fFormat = s_dms?
                        LatLongFormatter::FORMAT_DEGREES_MINUTES_SECONDS :
                        LatLongFormatter::FORMAT_DECIMAL_DEGREES;
                    
                    LatLongFormatter f( fFormat );

                    ss 
                        << "Lat: " << f.format( Angular(lla.y(),Units::DEGREES), 4 ) << "  "
                        << "Lon: " << f.format( Angular(lla.x(),Units::DEGREES), 5 );
                }

                _label->setText( ss.str() );
            }
            else
            {
                //Clear the text
                _label->setText( "" );
            }
        }
        return false;
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 154 of file osgearth_viewer.cpp.

Definition at line 155 of file osgearth_viewer.cpp.

Definition at line 156 of file osgearth_viewer.cpp.


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