21
21
#include " globe_plugin_dialog.h"
22
22
#include " qgsosgearthtilesource.h"
23
23
24
+ #include < cmath>
25
+
24
26
#include < qgisinterface.h>
25
27
#include < qgisgui.h>
26
28
#include < qgslogger.h>
@@ -270,14 +272,12 @@ struct PanControlHandler : public NavigationControlHandler
270
272
{
271
273
if ( 0 == _dx && 0 == _dy)
272
274
{
273
- _manip->setRotation (osg::Quat ());
274
- // FIXME: instead of next 2 lines use _manip->home( control->ea, control->aa );
275
- osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( -90 , 0 , 0.0 ), 0.0 , -90.0 , 3e7 );
276
- _manip->setViewpoint ( viewpoint, 4.0 );
275
+ // TODO
276
+ OE_NOTICE << " ZOOM reset" << _manip->getDistance ();
277
277
}
278
278
else
279
279
{
280
- _manip->pan ( _dx, _dy );
280
+ _manip->pan ( _dx, _dy );
281
281
}
282
282
}
283
283
private:
@@ -313,14 +313,14 @@ struct ZoomControlHandler : public NavigationControlHandler
313
313
{
314
314
if ( 0 == _dx && 0 == _dy)
315
315
{
316
- _manip->setRotation (osg::Quat ());
317
- // FIXME: instead of next 2 lines use _manip->home( control->ea, control->aa );
318
- osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( -90 , 0 , 0.0 ), 0.0 , -90.0 , 3e7 );
319
- _manip->setViewpoint ( viewpoint, 4.0 );
316
+ _manip->setRotation (osg::Quat ());
317
+ // FIXME: instead of next 2 lines use _manip->home( control->ea, control->aa );
318
+ osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( -90 , 0 , 0.0 ), 0.0 , -90.0 , 3e7 );
319
+ _manip->setViewpoint ( viewpoint, 4.0 );
320
320
}
321
321
else
322
322
{
323
- _manip->zoom ( _dx, _dy );
323
+ _manip->zoom ( _dx, _dy );
324
324
}
325
325
}
326
326
private:
@@ -329,6 +329,36 @@ struct ZoomControlHandler : public NavigationControlHandler
329
329
double _dy;
330
330
};
331
331
332
+ bool FlyToExtentHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
333
+ {
334
+ if ( ea.getEventType () == ea.KEYDOWN && ea.getKey () == ' 1' )
335
+ {
336
+ _manip->setRotation (osg::Quat ());
337
+
338
+ // get actual mapCanvas->extent().height in meters
339
+ QgsRectangle extent = mQGisIface ->mapCanvas ()->extent ();
340
+ QgsCoordinateReferenceSystem* destSrs = new QgsCoordinateReferenceSystem (31254 , QgsCoordinateReferenceSystem::EpsgCrsId );
341
+ QgsCoordinateTransform* trans = new QgsCoordinateTransform ( mQGisIface ->mapCanvas ()->mapRenderer ()->destinationSrs (), *destSrs);
342
+ QgsRectangle projectedExtent = trans->transformBoundingBox ( extent );
343
+
344
+ const double PI = 3.141592 ;
345
+ double viewAngle = 30 ;
346
+ double height = projectedExtent.height ();
347
+ double distance = height / tan ( viewAngle*PI/180 ); // c = b*cotan(B)
348
+
349
+ QString md, me;
350
+ md.setNum (height);
351
+ me.setNum (distance);
352
+ QMessageBox msgBox;
353
+ msgBox.setText (md + " " + me );
354
+ msgBox.exec ();
355
+
356
+ osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( extent.center ().x (), extent.center ().y (), 0.0 ), 0.0 , -90.0 , distance );
357
+ _manip->setViewpoint ( viewpoint, 4.0 );
358
+ }
359
+ return false ;
360
+ }
361
+
332
362
void GlobePlugin::setupControls ()
333
363
{
334
364
@@ -358,8 +388,8 @@ void GlobePlugin::setupControls()
358
388
359
389
// Move Reset
360
390
osg::Image* moveResetImg = osgDB::readImageFile ( imgDir + " /move-reset.png" );
361
- ImageControl* moveReset = new ImageControl ( moveResetImg );
362
- moveReset->addEventHandler ( new MyClickHandler );
391
+ ImageControl* moveReset = new NavigationControl ( moveResetImg );
392
+ moveReset->addEventHandler ( new PanControlHandler ( manip, 0 , 0 ) );
363
393
364
394
365
395
// Vertical container
@@ -606,25 +636,6 @@ void GlobePlugin::copyFolder ( QString sourceFolder, QString destFolder )
606
636
}
607
637
}
608
638
609
- bool FlyToExtentHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
610
- {
611
- if ( ea.getEventType () == ea.KEYDOWN && ea.getKey () == ' 1' )
612
- {
613
- QgsRectangle extent = mQGisIface ->mapCanvas ()->extent ();
614
- QgsPoint center = extent.center ();
615
- double zoom = extent.width ();
616
- osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( center.x (), center.y (), 0.0 ), 0.0 , -90.0 , 10000 );
617
- _manip->setViewpoint ( viewpoint, 4.0 );
618
-
619
- /* QString text_double;
620
- text_double.setNum(center.y());
621
- QMessageBox msgBox;
622
- msgBox.setText(text_double);
623
- msgBox.exec();*/
624
- }
625
- return false ;
626
- }
627
-
628
639
bool NavigationControl::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx )
629
640
{
630
641
switch ( ea.getEventType () )
0 commit comments