Skip to content

Commit c64de21

Browse files
mbernasocchipka
authored andcommittedJul 5, 2011
implemented a better syncExtent method using QgsDistanceArea
1 parent b697d13 commit c64de21

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed
 

‎src/plugins/globe/globe_plugin.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <qgsfeature.h>
3131
#include <qgsgeometry.h>
3232
#include <qgspoint.h>
33+
#include <qgsdistancearea.h>
3334

3435
#include <QAction>
3536
#include <QToolBar>
@@ -339,8 +340,7 @@ void GlobePlugin::projectReady()
339340
}
340341

341342
void GlobePlugin::blankProjectReady()
342-
{ //TODO now i patched the source against from http://trac.osgeo.org/qgis/changeset/14452
343-
//when we use a newer code base we do not need to patch
343+
{ //needs at least http://trac.osgeo.org/qgis/changeset/14452
344344
mSettingsDialog.elevationDatasources()->clearContents();
345345
mSettingsDialog.elevationDatasources()->setRowCount(0);
346346
}
@@ -400,15 +400,17 @@ void GlobePlugin::syncExtent()
400400
//rotate earth to north and perpendicular to camera
401401
manip->setRotation( osg::Quat() );
402402

403-
//get actual mapCanvas->extent().height in meters
403+
//get mapCanvas->extent().height() in meters
404404
QgsRectangle extent = mQGisIface->mapCanvas()->extent();
405-
//TODO: implement a stronger solution ev look at http://www.uwgb.edu/dutchs/usefuldata/utmformulas.htm
406-
QgsCoordinateReferenceSystem* destSrs = new QgsCoordinateReferenceSystem( 31254, QgsCoordinateReferenceSystem::EpsgCrsId );
407-
QgsCoordinateTransform* trans = new QgsCoordinateTransform( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs(), *destSrs );
408-
QgsRectangle projectedExtent = trans->transformBoundingBox( extent );
405+
QgsDistanceArea dist;
406+
dist.setProjectionsEnabled(true);
407+
QgsPoint ll = QgsPoint(extent.xMinimum(), extent.yMinimum());
408+
QgsPoint ul = QgsPoint(extent.xMinimum(), extent.yMaximum());
409+
double height = dist.measureLine(ll, ul);
409410

411+
//camera viewing angle
410412
double viewAngle = 30;
411-
double height = projectedExtent.height();
413+
//camera distance
412414
double distance = height / tan( viewAngle * osg::PI / 180 ); //c = b*cotan(B(rad))
413415

414416
OE_NOTICE << "map extent: " << height << " camera distance: " << distance << std::endl;

0 commit comments

Comments
 (0)
Please sign in to comment.