Skip to content

Commit

Permalink
Fly to extent handler
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Jul 5, 2011
1 parent 1a7a7ab commit 2fa95c4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/plugins/globe/globe.earth
@@ -1,8 +1,6 @@
<map name="QGIS Map" type="geocentric">

<!--
<loading_policy mode="preemptive"/>
-->
<loading_policy mode="sequential"/>

<image name="world" driver="gdal">
<url>/usr/share/osgearth/data/world.tif</url>
Expand Down
42 changes: 14 additions & 28 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -40,39 +40,12 @@
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/Viewpoint>
#include <osgEarth/TileSource>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/tms/TMSOptions>

using namespace osgEarth::Drivers;

// some preset viewpoints.
static osgEarthUtil::Viewpoint VPs[] = {
osgEarthUtil::Viewpoint( "Africa", osg::Vec3d( 0.0, 0.0, 0.0 ), 0.0, -90.0, 10e6 ),
osgEarthUtil::Viewpoint( "California", osg::Vec3d( -121.0, 34.0, 0.0 ), 0.0, -90.0, 6e6 ),
osgEarthUtil::Viewpoint( "Europe", osg::Vec3d( 0.0, 45.0, 0.0 ), 0.0, -90.0, 4e6 ),
osgEarthUtil::Viewpoint( "Lech", osg::Vec3d( 10.14, 47.21, 0.0 ), 0.0, -90.0, 1e4 ),
osgEarthUtil::Viewpoint( "Australia", osg::Vec3d( 135.0, -20.0, 0.0 ), 0.0, -90.0, 2e6 )
};

// a simple handler that demonstrates the "viewpoint" functionality in
// osgEarthUtil::EarthManipulator. Press a number key to fly to a viewpoint.
struct FlyToViewpointHandler : public osgGA::GUIEventHandler
{
FlyToViewpointHandler( osgEarthUtil::EarthManipulator* manip ) : _manip(manip) { }

bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() >= '1' && ea.getKey() <= '5' )
{
_manip->setViewpoint( VPs[ea.getKey()-'1'], 4.0 );
}
return false;
}

osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
};

//static const char * const sIdent = "$Id: plugin.cpp 9327 2008-09-14 11:18:44Z jef $";
static const QString sName = QObject::tr( "Globe" );
Expand Down Expand Up @@ -156,7 +129,7 @@ void GlobePlugin::run()
osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON );

// add our fly-to handler
viewer.addEventHandler(new FlyToViewpointHandler( manip ));
viewer.addEventHandler(new FlyToExtentHandler( manip, mQGisIface ));

// add some stock OSG handlers:
viewer.addEventHandler(new osgViewer::StatsHandler());
Expand Down Expand Up @@ -213,6 +186,19 @@ void GlobePlugin::help()
{
}


bool FlyToExtentHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '1' )
{
QgsPoint center = mQGisIface->mapCanvas()->extent().center();
osgEarthUtil::Viewpoint viewpoint( osg::Vec3d( center.x(), center.y(), 0.0 ), 0.0, -90.0, 1e4 );
_manip->setViewpoint( viewpoint, 4.0 );
}
return false;
}


/**
* Required extern functions needed for every plugin
* These functions can be called prior to creating an instance
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/globe/globe_plugin.h
Expand Up @@ -26,6 +26,7 @@
#include <QDockWidget>
#include <osgEarth/MapNode>
#include <osgEarth/MapLayer>
#include <osgEarthUtil/EarthManipulator>

class QAction;
class QToolBar;
Expand Down Expand Up @@ -76,4 +77,20 @@ class GlobePlugin : public QObject, public QgisPlugin
osgEarth::Drivers::QgsOsgEarthTileSource* mTileSource;
};


class FlyToExtentHandler : public osgGA::GUIEventHandler
{
public:
FlyToExtentHandler( osgEarthUtil::EarthManipulator* manip, QgisInterface *qGisIface ) : _manip(manip), mQGisIface(qGisIface) { }

bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa );

private:
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;

//! Pointer to the QGIS interface object
QgisInterface *mQGisIface;
};


#endif // QGS_GLOBE_PLUGIN_H

0 comments on commit 2fa95c4

Please sign in to comment.