osgEarth 2.1.1
Public Member Functions | Public Attributes

QueryElevationHandler Struct Reference

Collaboration diagram for QueryElevationHandler:

List of all members.

Public Member Functions

 QueryElevationHandler (const Map *map, ObjectLocator *flagLocator)
void update (float x, float y, osgViewer::View *view)
bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)

Public Attributes

const Map_map
bool _mouseDown
ElevationQuery _query
ObjectLocator_flagLocator

Detailed Description

Definition at line 73 of file osgearth_elevation.cpp.


Constructor & Destructor Documentation

QueryElevationHandler::QueryElevationHandler ( const Map map,
ObjectLocator flagLocator 
) [inline]

Definition at line 75 of file osgearth_elevation.cpp.

        : _map(map),
          _mouseDown( false ), 
          _flagLocator(flagLocator), 
          _query(map)
    {
        _query.setMaxTilesToCache(10);
    }

Member Function Documentation

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

Definition at line 139 of file osgearth_elevation.cpp.

    {
        if ( ea.getEventType() == osgGA::GUIEventAdapter::MOVE )
        {
            osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
            update( ea.getX(), ea.getY(), view );
        }

        return false;
    }
void QueryElevationHandler::update ( float  x,
float  y,
osgViewer::View *  view 
) [inline]

Definition at line 84 of file osgearth_elevation.cpp.

    {
        osgUtil::LineSegmentIntersector::Intersections results;
        if ( view->computeIntersections( x, y, results, 0x01 ) )
        {
            // 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:
            _map->worldPointToMapPoint(point, lla);

            // find the elevation at that map point:
            osg::Matrixd out_mat;
            double query_resolution = 0.1; // 1/10th of a degree
            double out_elevation = 0.0;
            double out_resolution = 0.0;

            bool ok = _query.getElevation( 
                lla,
                _map->getProfile()->getSRS(),
                out_elevation, 
                query_resolution, 
                &out_resolution );

            if ( ok )
            {
                _flagLocator->setPosition( osg::Vec3d(lla.x(), lla.y(), out_elevation) );
                s_flagNode->setNodeMask( ~0 );

                std::stringstream buf;
                buf << std::fixed << std::setprecision(2) 
                    << "Pos: " << lla.x() << ", " << lla.y() << std::endl
                    << "Elv: " << out_elevation << "m" << std::endl
                    << "X:   " << point.x() << std::endl
                    << "Y:   " << point.y() << std::endl
                    << "Z:   " << point.z();
                s_flagText->setText( buf.str() );

                OE_NOTICE << buf.str() << std::endl;
            }
            else
            {
                OE_NOTICE
                    << "getElevation FAILED! at (" << point.x() << ", " << point.y() << ")" << std::endl;
            }

        }
        else
        {
            s_flagNode->setNodeMask(0);
        }
    }

Member Data Documentation

Definition at line 153 of file osgearth_elevation.cpp.

Definition at line 150 of file osgearth_elevation.cpp.

Definition at line 151 of file osgearth_elevation.cpp.

Definition at line 152 of file osgearth_elevation.cpp.


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