@@ -256,29 +256,12 @@ void GlobePlugin::setupMap()
256
256
#endif
257
257
}
258
258
259
- struct MyClickHandler : public ControlEventHandler
260
- {
261
- void onClick ( Control* control, int mouseButtonMask )
262
- {
263
- OE_NOTICE << " Thank you for clicking on " << typeid ( control ).name ()
264
- << std::endl;
265
- }
266
- };
267
-
268
259
struct PanControlHandler : public NavigationControlHandler
269
260
{
270
261
PanControlHandler ( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip ( manip ), _dx ( dx ), _dy ( dy ) { }
271
262
virtual void onMouseDown ( Control* control, int mouseButtonMask )
272
263
{
273
- if ( 0 == _dx && 0 == _dy)
274
- {
275
- // TODO
276
- OE_NOTICE << " ZOOM reset" << _manip->getDistance ();
277
- }
278
- else
279
- {
280
- _manip->pan ( _dx, _dy );
281
- }
264
+ _manip->pan ( _dx, _dy );
282
265
}
283
266
private:
284
267
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
@@ -328,37 +311,88 @@ struct ZoomControlHandler : public NavigationControlHandler
328
311
double _dx;
329
312
double _dy;
330
313
};
314
+
315
+ struct RefreshControlHandler : public NavigationControlHandler
316
+ {
317
+ RefreshControlHandler ( osgEarthUtil::EarthManipulator* manip, QgisInterface* mQGisIface ) : _manip ( manip ), _mQGisIface ( mQGisIface ) { }
318
+ virtual void onMouseDown ( Control* control, int mouseButtonMask )
319
+ {
320
+ // TODO
321
+ OE_NOTICE << " refresh layers" << std::endl;
322
+ }
323
+ private:
324
+ osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
325
+ QgisInterface* _mQGisIface;
326
+ };
327
+
328
+ struct SyncExtentControlHandler : public NavigationControlHandler
329
+ {
330
+ SyncExtentControlHandler ( osgEarthUtil::EarthManipulator* manip, QgisInterface* mQGisIface ) : _manip ( manip ), _mQGisIface ( mQGisIface ) { }
331
+ virtual void onMouseDown ( Control* control, int mouseButtonMask )
332
+ {
333
+ // TODO use GlobePlugin::syncExtent instead of duplicating code
334
+ _manip->setRotation (osg::Quat ());
335
+ QgsRectangle extent = _mQGisIface->mapCanvas ()->extent ();
336
+ QgsCoordinateReferenceSystem* destSrs = new QgsCoordinateReferenceSystem (31254 , QgsCoordinateReferenceSystem::EpsgCrsId );
337
+ QgsCoordinateTransform* trans = new QgsCoordinateTransform ( _mQGisIface->mapCanvas ()->mapRenderer ()->destinationSrs (), *destSrs);
338
+ QgsRectangle projectedExtent = trans->transformBoundingBox ( extent );
339
+ double viewAngle = 30 ;
340
+ double height = projectedExtent.height ();
341
+ double distance = height / tan ( viewAngle * osg::PI / 180 ); // c = b*cotan(B(rad))
342
+ osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( extent.center ().x (), extent.center ().y (), 0.0 ), 0.0 , -90.0 , distance );
343
+ _manip->setViewpoint ( viewpoint, 4.0 );
344
+ }
345
+ private:
346
+ osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
347
+ QgisInterface* _mQGisIface;
348
+ };
331
349
332
350
bool FlyToExtentHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
333
351
{
334
352
if ( ea.getEventType () == ea.KEYDOWN && ea.getKey () == ' 1' )
335
353
{
354
+ // TODO use GlobePlugin::syncExtent instead of duplicating code
336
355
_manip->setRotation (osg::Quat ());
337
-
338
- // get actual mapCanvas->extent().height in meters
339
356
QgsRectangle extent = mQGisIface ->mapCanvas ()->extent ();
340
357
QgsCoordinateReferenceSystem* destSrs = new QgsCoordinateReferenceSystem (31254 , QgsCoordinateReferenceSystem::EpsgCrsId );
341
358
QgsCoordinateTransform* trans = new QgsCoordinateTransform ( mQGisIface ->mapCanvas ()->mapRenderer ()->destinationSrs (), *destSrs);
342
359
QgsRectangle projectedExtent = trans->transformBoundingBox ( extent );
343
-
344
- const double PI = 3.141592 ;
345
360
double viewAngle = 30 ;
346
361
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
-
362
+ double distance = height / tan ( viewAngle * osg::PI / 180 ); // c = b*cotan(B(rad))
356
363
osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( extent.center ().x (), extent.center ().y (), 0.0 ), 0.0 , -90.0 , distance );
357
364
_manip->setViewpoint ( viewpoint, 4.0 );
358
365
}
359
366
return false ;
360
367
}
361
368
369
+ void GlobePlugin::syncExtent ( osgEarthUtil::EarthManipulator* manip )
370
+ {
371
+ // rotate earth to north and perpendicular to camera
372
+ manip->setRotation (osg::Quat ());
373
+
374
+ // get actual mapCanvas->extent().height in meters
375
+ QgsRectangle extent = mQGisIface ->mapCanvas ()->extent ();
376
+ // TODO: implement a stronger solution ev look at http://www.uwgb.edu/dutchs/usefuldata/utmformulas.htm
377
+ QgsCoordinateReferenceSystem* destSrs = new QgsCoordinateReferenceSystem (31254 , QgsCoordinateReferenceSystem::EpsgCrsId );
378
+ QgsCoordinateTransform* trans = new QgsCoordinateTransform ( mQGisIface ->mapCanvas ()->mapRenderer ()->destinationSrs (), *destSrs);
379
+ QgsRectangle projectedExtent = trans->transformBoundingBox ( extent );
380
+
381
+ double viewAngle = 30 ;
382
+ double height = projectedExtent.height ();
383
+ double distance = height / tan ( viewAngle * osg::PI / 180 ); // c = b*cotan(B(rad))
384
+
385
+ // QString md, me;
386
+ // md.setNum(height);
387
+ // me.setNum(distance);
388
+ // QMessageBox msgBox;
389
+ // msgBox.setText(md + " " + me );
390
+ // msgBox.exec();
391
+
392
+ osgEarthUtil::Viewpoint viewpoint ( osg::Vec3d ( extent.center ().x (), extent.center ().y (), 0.0 ), 0.0 , -90.0 , distance );
393
+ manip->setViewpoint ( viewpoint, 4.0 );
394
+ }
395
+
362
396
void GlobePlugin::setupControls ()
363
397
{
364
398
@@ -370,10 +404,11 @@ void GlobePlugin::setupControls()
370
404
moveHControls->setFrame ( new RoundedFrame () );
371
405
// moveHControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
372
406
moveHControls->setMargin ( 10 );
373
- moveHControls->setSpacing ( 10 );
407
+ moveHControls->setSpacing ( 15 );
374
408
moveHControls->setVertAlign ( Control::ALIGN_CENTER );
375
409
moveHControls->setHorizAlign ( Control::ALIGN_CENTER );
376
- moveHControls->setPosition ( 5 , 35 );
410
+ moveHControls->setPosition ( 20 , 26 );
411
+ moveHControls->setPadding (3 );
377
412
378
413
osgEarthUtil::EarthManipulator* manip = dynamic_cast <osgEarthUtil::EarthManipulator*> ( viewer.getCameraManipulator () );
379
414
// Move Left
@@ -386,21 +421,16 @@ void GlobePlugin::setupControls()
386
421
ImageControl* moveRight = new NavigationControl ( moveRightImg );
387
422
moveRight->addEventHandler ( new PanControlHandler ( manip, MOVE_OFFSET, 0 ) );
388
423
389
- // Move Reset
390
- osg::Image* moveResetImg = osgDB::readImageFile ( imgDir + " /move-reset.png" );
391
- ImageControl* moveReset = new NavigationControl ( moveResetImg );
392
- moveReset->addEventHandler ( new PanControlHandler ( manip, 0 , 0 ) );
393
-
394
-
395
424
// Vertical container
396
425
VBox* moveVControls = new VBox ();
397
426
moveVControls->setFrame ( new RoundedFrame () );
398
427
// moveVControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
399
428
moveVControls->setMargin ( 10 );
400
- moveVControls->setSpacing ( 30 );
429
+ moveVControls->setSpacing ( 20 );
401
430
moveVControls->setVertAlign ( Control::ALIGN_CENTER );
402
431
moveVControls->setHorizAlign ( Control::ALIGN_CENTER );
403
432
moveVControls->setPosition ( 40 , 5 );
433
+ moveVControls->setPadding (3 );
404
434
405
435
// Move Up
406
436
osg::Image* moveUpImg = osgDB::readImageFile ( imgDir + " /move-up.png" );
@@ -414,7 +444,6 @@ void GlobePlugin::setupControls()
414
444
415
445
// add controls to moveControls group
416
446
moveHControls->addControl ( moveLeft );
417
- moveHControls->addControl ( moveReset );
418
447
moveHControls->addControl ( moveRight );
419
448
moveVControls->addControl ( moveUp );
420
449
moveVControls->addControl ( moveDown );
@@ -431,6 +460,7 @@ void GlobePlugin::setupControls()
431
460
rotateControls->setVertAlign ( Control::ALIGN_CENTER );
432
461
rotateControls->setHorizAlign ( Control::ALIGN_CENTER );
433
462
rotateControls->setPosition ( 5 , 120 );
463
+ rotateControls->setPadding (3 );
434
464
435
465
// Rotate CCW
436
466
osg::Image* rotateCCWImg = osgDB::readImageFile ( imgDir + " /rotate-ccw.png" );
@@ -447,7 +477,7 @@ void GlobePlugin::setupControls()
447
477
ImageControl* rotateReset = new NavigationControl ( rotateResetImg );
448
478
rotateReset->addEventHandler ( new RotateControlHandler ( manip, 0 , 0 ) );
449
479
450
- // add controls to moveControls group
480
+ // add controls to rotateControls group
451
481
rotateControls->addControl ( rotateCCW );
452
482
rotateControls->addControl ( rotateReset );
453
483
rotateControls->addControl ( rotateCW );
@@ -464,6 +494,7 @@ void GlobePlugin::setupControls()
464
494
tiltControls->setVertAlign ( Control::ALIGN_CENTER );
465
495
tiltControls->setHorizAlign ( Control::ALIGN_CENTER );
466
496
tiltControls->setPosition ( 40 , 90 );
497
+ tiltControls->setPadding (3 );
467
498
468
499
// tilt Up
469
500
osg::Image* tiltUpImg = osgDB::readImageFile ( imgDir + " /tilt-up.png" );
@@ -487,10 +518,11 @@ void GlobePlugin::setupControls()
487
518
zoomControls->setFrame ( new RoundedFrame () );
488
519
// zoomControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
489
520
zoomControls->setMargin ( 10 );
490
- zoomControls->setSpacing ( 5 );
521
+ zoomControls->setSpacing ( 0 );
491
522
zoomControls->setVertAlign ( Control::ALIGN_CENTER );
492
523
zoomControls->setHorizAlign ( Control::ALIGN_CENTER );
493
524
zoomControls->setPosition ( 40 , 180 );
525
+ zoomControls->setPadding (3 );
494
526
495
527
// Zoom In
496
528
osg::Image* zoomInImg = osgDB::readImageFile ( imgDir + " /zoom-in.png" );
@@ -502,24 +534,53 @@ void GlobePlugin::setupControls()
502
534
ImageControl* zoomOut = new NavigationControl ( zoomOutImg );
503
535
zoomOut->addEventHandler ( new ZoomControlHandler ( manip, 0 , MOVE_OFFSET ) );
504
536
505
- // Zoom Reset
506
- osg::Image* zoomResetImg = osgDB::readImageFile ( imgDir + " /zoom-reset.png" );
507
- ImageControl* zoomReset = new NavigationControl ( zoomResetImg );
508
- zoomReset->addEventHandler ( new ZoomControlHandler ( manip, 0 , 0 ) );
509
-
510
537
// add controls to zoomControls group
511
538
zoomControls->addControl ( zoomIn );
512
- zoomControls->addControl ( zoomReset );
513
539
zoomControls->addControl ( zoomOut );
514
540
515
541
// END ZOOM CONTROLS
542
+
543
+ // EXTRA CONTROLS
544
+ // Horizontal container
545
+ HBox* extraControls = new HBox ();
546
+ extraControls->setFrame ( new RoundedFrame () );
547
+ // extraControls->getFrame()->setBackColor(0.5,0.5,0.5,0.1);
548
+ extraControls->setMargin ( 10 );
549
+ extraControls->setSpacing ( 10 );
550
+ extraControls->setVertAlign ( Control::ALIGN_CENTER );
551
+ extraControls->setHorizAlign ( Control::ALIGN_CENTER );
552
+ extraControls->setPosition ( 5 , 240 );
553
+ extraControls->setPadding (3 );
554
+
555
+ // Zoom Reset
556
+ osg::Image* extraHomeImg = osgDB::readImageFile ( imgDir + " /zoom-home.png" );
557
+ ImageControl* extraHome = new NavigationControl ( extraHomeImg );
558
+ extraHome->addEventHandler ( new ZoomControlHandler ( manip, 0 , 0 ) );
559
+
560
+ // Sync Extent
561
+ osg::Image* extraSyncImg = osgDB::readImageFile ( imgDir + " /sync-extent.png" );
562
+ ImageControl* extraSync = new NavigationControl ( extraSyncImg );
563
+ extraSync->addEventHandler ( new SyncExtentControlHandler ( manip, mQGisIface ) );
564
+
565
+ // refresh layers
566
+ osg::Image* extraRefreshImg = osgDB::readImageFile ( imgDir + " /refresh-view.png" );
567
+ ImageControl* extraRefresh = new NavigationControl ( extraRefreshImg );
568
+ extraRefresh->addEventHandler ( new RefreshControlHandler ( manip, mQGisIface ) );
569
+
570
+ // add controls to extraControls group
571
+ extraControls->addControl ( extraSync );
572
+ extraControls->addControl ( extraHome );
573
+ extraControls->addControl ( extraRefresh );
574
+
575
+ // END EXTRA CONTROLS
516
576
517
577
// add controls groups to canavas
518
578
mControlCanvas ->addControl ( moveVControls );
519
579
mControlCanvas ->addControl ( moveHControls );
520
580
mControlCanvas ->addControl ( rotateControls );
521
581
mControlCanvas ->addControl ( tiltControls );
522
582
mControlCanvas ->addControl ( zoomControls );
583
+ mControlCanvas ->addControl ( extraControls );
523
584
524
585
}
525
586
@@ -667,7 +728,6 @@ bool NavigationControl::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIAct
667
728
668
729
bool KeyboardControlHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
669
730
{
670
- float deg = 3.14159 / 180 ;
671
731
/*
672
732
osgEarthUtil::EarthManipulator::Settings* _manipSettings = _manip->getSettings();
673
733
_manip->getSettings()->bindKey(osgEarthUtil::EarthManipulator::ACTION_ZOOM_IN, osgGA::GUIEventAdapter::KEY_Space);
0 commit comments