Skip to content
Permalink
Browse files

Fly to extent handler

  • Loading branch information
pka committed Oct 6, 2010
1 parent 1a7a7ab commit 2fa95c411cbd91ee7f2a07b03ff7dfda284b274e
Showing with 32 additions and 31 deletions.
  1. +1 −3 src/plugins/globe/globe.earth
  2. +14 −28 src/plugins/globe/globe_plugin.cpp
  3. +17 −0 src/plugins/globe/globe_plugin.h
@@ -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>
@@ -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" );
@@ -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());
@@ -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
@@ -26,6 +26,7 @@
#include <QDockWidget>
#include <osgEarth/MapNode>
#include <osgEarth/MapLayer>
#include <osgEarthUtil/EarthManipulator>

class QAction;
class QToolBar;
@@ -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.
You can’t perform that action at this time.