@@ -117,6 +117,11 @@ void GlobePlugin::initGui()
117
117
SLOT ( blankProjectReady () ) );
118
118
connect ( &mQDockWidget , SIGNAL ( globeClosed () ), this ,
119
119
SLOT ( setGlobeNotRunning () ) );
120
+ connect ( this , SIGNAL ( xyCoordinates ( const QgsPoint & ) ),
121
+ mQGisIface ->mainWindow (), SLOT ( showMouseCoordinate ( const QgsPoint & ) ) );
122
+ // connect( this, SIGNAL( xyCoordinates( const QgsPoint & ) ),
123
+ // this, SLOT( showSelectedCoordinates() ) );
124
+
120
125
}
121
126
122
127
void GlobePlugin::run ()
@@ -351,16 +356,80 @@ bool FlyToExtentHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIAct
351
356
352
357
bool QueryCoordinatesHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
353
358
{
354
- if ( ea.getEventType () == osgGA::GUIEventAdapter::PUSH )
359
+ if ( ea.getEventType () == osgGA::GUIEventAdapter::MOVE)
360
+ {
361
+ osgViewer::View* view = static_cast <osgViewer::View*>(aa.asView ());
362
+ osg::Vec3d coords = getCoords ( ea.getX (), ea.getY (), view );
363
+ mGlobe ->showCurrentCoordinates ( coords.x (), coords.y () );
364
+ }
365
+ if ( ea.getEventType () == osgGA::GUIEventAdapter::PUSH
366
+ && ea.getButtonMask () == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
355
367
{
356
368
osgViewer::View* view = static_cast <osgViewer::View*>(aa.asView ());
357
- getCoords ( ea.getX (), ea.getY (), view );
369
+ osg::Vec3d coords = getCoords ( ea.getX (), ea.getY (), view );
370
+
371
+ OE_NOTICE << " Lon: " << coords.x () << " Lat: " << coords.y ()
372
+ << " Ele: " << coords.z () << std::endl;
373
+
374
+ mGlobe ->setSelectedCoordinates ( coords );
375
+
376
+ if (ea.getModKeyMask () == osgGA::GUIEventAdapter::MODKEY_CTRL)
377
+ {
378
+ mGlobe ->showSelectedCoordinates ();
379
+ }
358
380
}
359
381
360
382
return false ;
361
383
}
362
384
363
- void QueryCoordinatesHandler::getCoords ( float x, float y, osgViewer::View* view )
385
+ void GlobePlugin::showCurrentCoordinates (double lon, double lat)
386
+ {
387
+ // show x y on status bar
388
+ OE_NOTICE << " lon: " << lon << " lat: " << lat <<std::endl;
389
+ QgsPoint coord = QgsPoint ( lon, lat );
390
+ emit xyCoordinates ( coord );
391
+ }
392
+
393
+ void GlobePlugin::setSelectedCoordinates ( osg::Vec3d coords)
394
+ {
395
+ mSelectedLon = coords.x ();
396
+ mSelectedLat = coords.y ();
397
+ mSelectedElevation = coords.z ();
398
+ }
399
+
400
+ osg::Vec3d GlobePlugin::getSelectedCoordinates ()
401
+ {
402
+ osg::Vec3d coords = osg::Vec3d (mSelectedLon , mSelectedLat , mSelectedElevation );
403
+ return coords;
404
+ }
405
+
406
+ void GlobePlugin::showSelectedCoordinates ()
407
+ {
408
+ QString lon, lat, elevation;
409
+ lon.setNum (mSelectedLon );
410
+ lat.setNum (mSelectedLat );
411
+ elevation.setNum (mSelectedElevation );
412
+ QMessageBox m;
413
+ m.setText (" selected coordinates are:\n lon: " + lon + " \n lat: " + lat + " \n elevation: " + elevation);
414
+ m.exec ();
415
+ }
416
+
417
+ double GlobePlugin::getSelectedLon ()
418
+ {
419
+ return mSelectedLon ;
420
+ }
421
+
422
+ double GlobePlugin::getSelectedLat ()
423
+ {
424
+ return mSelectedLat ;
425
+ }
426
+
427
+ double GlobePlugin::getSelectedElevation ()
428
+ {
429
+ return mSelectedElevation ;
430
+ }
431
+
432
+ osg::Vec3d QueryCoordinatesHandler::getCoords ( float x, float y, osgViewer::View* view )
364
433
{
365
434
osgUtil::LineSegmentIntersector::Intersections results;
366
435
if ( view->computeIntersections ( x, y, results, 0x01 ) )
@@ -374,30 +443,31 @@ void QueryCoordinatesHandler::getCoords( float x, float y, osgViewer::View* view
374
443
_mapSRS->getEllipsoid ()->convertXYZToLatLongHeight ( point.x (), point.y (), point.z (), lat_rad, lon_rad, height );
375
444
376
445
// query the elevation at the map point:
377
- double lat_deg = osg::RadiansToDegrees ( lat_rad );
378
446
double lon_deg = osg::RadiansToDegrees ( lon_rad );
447
+ double lat_deg = osg::RadiansToDegrees ( lat_rad );
448
+ double elevation = 0.0 ;
379
449
380
- OE_NOTICE << " coords at " << lat_deg << " , " << lon_deg << std::endl ;
381
-
382
- /* osg::Matrixd out_mat;
450
+ /* TODO IMPLEMENT ELEVATION
451
+ osg::Matrixd out_mat;
383
452
double query_resolution = 0.1; // 1/10th of a degree
384
- double out_elevation = 0.0;
385
453
double out_resolution = 0.0;
386
454
387
455
if ( _elevMan->getPlacementMatrix(
388
456
lon_deg, lat_deg, 0,
389
457
query_resolution, NULL,
390
- out_mat, out_elevation , out_resolution ) )
458
+ out_mat, elevation , out_resolution ) )
391
459
{
392
460
OE_NOTICE << "Elevation at " << lat_deg << ", " << lon_deg
393
- << " is " << out_elevation << std::endl;
461
+ << " is " << elevation << std::endl;
394
462
}
395
463
else
396
464
{
397
465
OE_NOTICE
398
466
<< "getElevation FAILED! at (" << lat_deg << ", " << lon_deg << ")" << std::endl;
399
467
}
400
468
*/
469
+ osg::Vec3d coords = osg::Vec3d (lon_deg, lat_deg, elevation);
470
+ return coords;
401
471
}
402
472
}
403
473
0 commit comments