@@ -86,6 +86,85 @@ GlobePlugin::~GlobePlugin()
86
86
{
87
87
}
88
88
89
+ struct PanControlHandler : public NavigationControlHandler
90
+ {
91
+ PanControlHandler ( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
92
+ virtual void onMouseDown ( Control* control, int mouseButtonMask )
93
+ {
94
+ _manip->pan ( _dx, _dy );
95
+ }
96
+ private:
97
+ osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
98
+ double _dx;
99
+ double _dy;
100
+ };
101
+
102
+ struct RotateControlHandler : public NavigationControlHandler
103
+ {
104
+ RotateControlHandler ( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
105
+ virtual void onMouseDown ( Control* control, int mouseButtonMask )
106
+ {
107
+ if ( 0 == _dx && 0 == _dy )
108
+ {
109
+ _manip->setRotation ( osg::Quat () );
110
+ }
111
+ else
112
+ {
113
+ _manip->rotate ( _dx, _dy );
114
+ }
115
+ }
116
+ private:
117
+ osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
118
+ double _dx;
119
+ double _dy;
120
+ };
121
+
122
+ struct ZoomControlHandler : public NavigationControlHandler
123
+ {
124
+ ZoomControlHandler ( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
125
+ virtual void onMouseDown ( Control* control, int mouseButtonMask )
126
+ {
127
+ _manip->zoom ( _dx, _dy );
128
+ }
129
+ private:
130
+ osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
131
+ double _dx;
132
+ double _dy;
133
+ };
134
+
135
+ struct HomeControlHandler : public NavigationControlHandler
136
+ {
137
+ HomeControlHandler ( osgEarthUtil::EarthManipulator* manip ) : _manip( manip ) { }
138
+ virtual void onClick ( Control* control, int mouseButtonMask, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
139
+ {
140
+ _manip->home ( ea, aa );
141
+ }
142
+ private:
143
+ osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
144
+ };
145
+
146
+ struct RefreshControlHandler : public ControlEventHandler
147
+ {
148
+ RefreshControlHandler ( GlobePlugin* globe ) : mGlobe ( globe ) { }
149
+ virtual void onClick ( Control* control, int mouseButtonMask )
150
+ {
151
+ mGlobe ->layersChanged ();
152
+ }
153
+ private:
154
+ GlobePlugin* mGlobe ;
155
+ };
156
+
157
+ struct SyncExtentControlHandler : public ControlEventHandler
158
+ {
159
+ SyncExtentControlHandler ( GlobePlugin* globe ) : mGlobe ( globe ) { }
160
+ virtual void onClick ( Control* control, int mouseButtonMask )
161
+ {
162
+ mGlobe ->syncExtent ();
163
+ }
164
+ private:
165
+ GlobePlugin* mGlobe ;
166
+ };
167
+
89
168
void GlobePlugin::initGui ()
90
169
{
91
170
// Create the action for tool
@@ -163,7 +242,7 @@ void GlobePlugin::run()
163
242
viewer.addEventHandler ( new FlyToExtentHandler ( this ) );
164
243
viewer.addEventHandler ( new KeyboardControlHandler ( manip, mQGisIface ) );
165
244
166
- viewer.addEventHandler ( new QueryCoordinatesHandler ( this ,
245
+ viewer.addEventHandler ( new QueryCoordinatesHandler ( this , mElevationManager ,
167
246
mMapNode ->getMap ()->getProfile ()->getSRS () )
168
247
);
169
248
@@ -261,131 +340,15 @@ void GlobePlugin::projectReady()
261
340
262
341
void GlobePlugin::blankProjectReady ()
263
342
{ // TODO now i patched the source against from http://trac.osgeo.org/qgis/changeset/14452
264
- // when we use a newer code base we should need to patch
343
+ // when we use a newer code base we do not need to patch
265
344
mSettingsDialog .elevationDatasources ()->clearContents ();
266
345
mSettingsDialog .elevationDatasources ()->setRowCount (0 );
267
346
}
268
347
269
- struct PanControlHandler : public NavigationControlHandler
270
- {
271
- PanControlHandler ( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
272
- virtual void onMouseDown ( Control* control, int mouseButtonMask )
273
- {
274
- _manip->pan ( _dx, _dy );
275
- }
276
- private:
277
- osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
278
- double _dx;
279
- double _dy;
280
- };
281
-
282
- struct RotateControlHandler : public NavigationControlHandler
283
- {
284
- RotateControlHandler ( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
285
- virtual void onMouseDown ( Control* control, int mouseButtonMask )
286
- {
287
- if ( 0 == _dx && 0 == _dy )
288
- {
289
- _manip->setRotation ( osg::Quat () );
290
- }
291
- else
292
- {
293
- _manip->rotate ( _dx, _dy );
294
- }
295
- }
296
- private:
297
- osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
298
- double _dx;
299
- double _dy;
300
- };
301
-
302
- struct ZoomControlHandler : public NavigationControlHandler
303
- {
304
- ZoomControlHandler ( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
305
- virtual void onMouseDown ( Control* control, int mouseButtonMask )
306
- {
307
- _manip->zoom ( _dx, _dy );
308
- }
309
- private:
310
- osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
311
- double _dx;
312
- double _dy;
313
- };
314
-
315
- struct HomeControlHandler : public NavigationControlHandler
316
- {
317
- HomeControlHandler ( osgEarthUtil::EarthManipulator* manip ) : _manip( manip ) { }
318
- virtual void onClick ( Control* control, int mouseButtonMask, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
319
- {
320
- _manip->home ( ea, aa );
321
- }
322
- private:
323
- osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
324
- };
325
-
326
- struct RefreshControlHandler : public ControlEventHandler
327
- {
328
- RefreshControlHandler ( GlobePlugin* globe ) : mGlobe ( globe ) { }
329
- virtual void onClick ( Control* control, int mouseButtonMask )
330
- {
331
- mGlobe ->layersChanged ();
332
- }
333
- private:
334
- GlobePlugin* mGlobe ;
335
- };
336
-
337
- struct SyncExtentControlHandler : public ControlEventHandler
338
- {
339
- SyncExtentControlHandler ( GlobePlugin* globe ) : mGlobe ( globe ) { }
340
- virtual void onClick ( Control* control, int mouseButtonMask )
341
- {
342
- mGlobe ->syncExtent ();
343
- }
344
- private:
345
- GlobePlugin* mGlobe ;
346
- };
347
-
348
- bool FlyToExtentHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
349
- {
350
- if ( ea.getEventType () == ea.KEYDOWN && ea.getKey () == ' 1' )
351
- {
352
- mGlobe ->syncExtent ();
353
- }
354
- return false ;
355
- }
356
-
357
- bool QueryCoordinatesHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
358
- {
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)
367
- {
368
- osgViewer::View* view = static_cast <osgViewer::View*>(aa.asView ());
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
- }
380
- }
381
-
382
- return false ;
383
- }
384
-
385
348
void GlobePlugin::showCurrentCoordinates (double lon, double lat)
386
349
{
387
350
// show x y on status bar
388
- OE_NOTICE << " lon: " << lon << " lat: " << lat <<std::endl;
351
+ // OE_NOTICE << "lon: " << lon << " lat: " << lat <<std::endl;
389
352
QgsPoint coord = QgsPoint ( lon, lat );
390
353
emit xyCoordinates ( coord );
391
354
}
@@ -395,6 +358,8 @@ void GlobePlugin::setSelectedCoordinates( osg::Vec3d coords)
395
358
mSelectedLon = coords.x ();
396
359
mSelectedLat = coords.y ();
397
360
mSelectedElevation = coords.z ();
361
+ QgsPoint coord = QgsPoint ( mSelectedLon , mSelectedLat );
362
+ emit newCoordinatesSelected ( coord );
398
363
}
399
364
400
365
osg::Vec3d GlobePlugin::getSelectedCoordinates ()
@@ -429,48 +394,6 @@ double GlobePlugin::getSelectedElevation()
429
394
return mSelectedElevation ;
430
395
}
431
396
432
- osg::Vec3d QueryCoordinatesHandler::getCoords ( float x, float y, osgViewer::View* view )
433
- {
434
- osgUtil::LineSegmentIntersector::Intersections results;
435
- if ( view->computeIntersections ( x, y, results, 0x01 ) )
436
- {
437
- // find the first hit under the mouse:
438
- osgUtil::LineSegmentIntersector::Intersection first = *(results.begin ());
439
- osg::Vec3d point = first.getWorldIntersectPoint ();
440
-
441
- // transform it to map coordinates:
442
- double lat_rad, lon_rad, height;
443
- _mapSRS->getEllipsoid ()->convertXYZToLatLongHeight ( point.x (), point.y (), point.z (), lat_rad, lon_rad, height );
444
-
445
- // query the elevation at the map point:
446
- double lon_deg = osg::RadiansToDegrees ( lon_rad );
447
- double lat_deg = osg::RadiansToDegrees ( lat_rad );
448
- double elevation = 0.0 ;
449
-
450
- /* TODO IMPLEMENT ELEVATION
451
- osg::Matrixd out_mat;
452
- double query_resolution = 0.1; // 1/10th of a degree
453
- double out_resolution = 0.0;
454
-
455
- if ( _elevMan->getPlacementMatrix(
456
- lon_deg, lat_deg, 0,
457
- query_resolution, NULL,
458
- out_mat, elevation, out_resolution ) )
459
- {
460
- OE_NOTICE << "Elevation at " << lat_deg << ", " << lon_deg
461
- << " is " << elevation << std::endl;
462
- }
463
- else
464
- {
465
- OE_NOTICE
466
- << "getElevation FAILED! at (" << lat_deg << ", " << lon_deg << ")" << std::endl;
467
- }
468
- */
469
- osg::Vec3d coords = osg::Vec3d (lon_deg, lat_deg, elevation);
470
- return coords;
471
- }
472
- }
473
-
474
397
void GlobePlugin::syncExtent ()
475
398
{
476
399
osgEarthUtil::EarthManipulator* manip = dynamic_cast <osgEarthUtil::EarthManipulator*>( viewer.getCameraManipulator () );
@@ -999,6 +922,91 @@ bool KeyboardControlHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GU
999
922
return false ;
1000
923
}
1001
924
925
+ bool FlyToExtentHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
926
+ {
927
+ if ( ea.getEventType () == ea.KEYDOWN && ea.getKey () == ' 1' )
928
+ {
929
+ mGlobe ->syncExtent ();
930
+ }
931
+ return false ;
932
+ }
933
+
934
+ bool QueryCoordinatesHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
935
+ {
936
+ if ( ea.getEventType () == osgGA::GUIEventAdapter::MOVE)
937
+ {
938
+ osgViewer::View* view = static_cast <osgViewer::View*>(aa.asView ());
939
+ osg::Vec3d coords = getCoords ( ea.getX (), ea.getY (), view, false );
940
+ mGlobe ->showCurrentCoordinates ( coords.x (), coords.y () );
941
+ }
942
+ if ( ea.getEventType () == osgGA::GUIEventAdapter::PUSH
943
+ && ea.getButtonMask () == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
944
+ {
945
+ osgViewer::View* view = static_cast <osgViewer::View*>(aa.asView ());
946
+ osg::Vec3d coords = getCoords ( ea.getX (), ea.getY (), view, false );
947
+
948
+ OE_NOTICE << " SelectedCoordinates set to:\n Lon: " << coords.x () << " Lat: " << coords.y ()
949
+ << " Ele: " << coords.z () << std::endl;
950
+
951
+ mGlobe ->setSelectedCoordinates ( coords );
952
+
953
+ if (ea.getModKeyMask () == osgGA::GUIEventAdapter::MODKEY_CTRL)
954
+ // ctrl + rightclick pops up a QMessageBox
955
+ {
956
+ mGlobe ->showSelectedCoordinates ();
957
+ }
958
+ }
959
+
960
+ return false ;
961
+ }
962
+
963
+ osg::Vec3d QueryCoordinatesHandler::getCoords ( float x, float y, osgViewer::View* view, bool getElevation)
964
+ {
965
+ osgUtil::LineSegmentIntersector::Intersections results;
966
+ if ( view->computeIntersections ( x, y, results, 0x01 ) )
967
+ {
968
+ // find the first hit under the mouse:
969
+ osgUtil::LineSegmentIntersector::Intersection first = *(results.begin ());
970
+ osg::Vec3d point = first.getWorldIntersectPoint ();
971
+
972
+ // transform it to map coordinates:
973
+ double lat_rad, lon_rad, height;
974
+ _mapSRS->getEllipsoid ()->convertXYZToLatLongHeight ( point.x (), point.y (), point.z (), lat_rad, lon_rad, height );
975
+
976
+ // query the elevation at the map point:
977
+ double lon_deg = osg::RadiansToDegrees ( lon_rad );
978
+ double lat_deg = osg::RadiansToDegrees ( lat_rad );
979
+ double elevation = -99999 ;
980
+
981
+ if (getElevation)
982
+ {
983
+ osg::Matrixd out_mat;
984
+ double query_resolution = 0.1 ; // 1/10th of a degree
985
+ double out_resolution = 0.0 ;
986
+
987
+ // TODO test elevation calculation
988
+ // @see https://github.com/gwaldron/osgearth/blob/master/src/applications/osgearth_elevation/osgearth_elevation.cpp
989
+ if (_elevMan->getPlacementMatrix (
990
+ lon_deg, lat_deg, 0 ,
991
+ query_resolution, _mapSRS,
992
+ // query_resolution, NULL,
993
+ out_mat, elevation, out_resolution ) )
994
+ {
995
+ OE_NOTICE << " Elevation at " << lon_deg << " , " << lat_deg
996
+ << " is " << elevation << std::endl;
997
+ }
998
+ else
999
+ {
1000
+ OE_NOTICE << " getElevation FAILED! at (" << lon_deg << " , "
1001
+ << lat_deg << " )" << std::endl;
1002
+ }
1003
+ }
1004
+
1005
+ osg::Vec3d coords = osg::Vec3d (lon_deg, lat_deg, elevation);
1006
+ return coords;
1007
+ }
1008
+ }
1009
+
1002
1010
/* *
1003
1011
* Required extern functions needed for every plugin
1004
1012
* These functions can be called prior to creating an instance
0 commit comments