Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implemented a better syncExtent method using QgsDistanceArea
  • Loading branch information
mbernasocchi authored and pka committed Jul 5, 2011
1 parent b697d13 commit c64de21
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -30,6 +30,7 @@
#include <qgsfeature.h>
#include <qgsgeometry.h>
#include <qgspoint.h>
#include <qgsdistancearea.h>

#include <QAction>
#include <QToolBar>
Expand Down Expand Up @@ -339,8 +340,7 @@ void GlobePlugin::projectReady()
}

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

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

//camera viewing angle
double viewAngle = 30;
double height = projectedExtent.height();
//camera distance
double distance = height / tan( viewAngle * osg::PI / 180 ); //c = b*cotan(B(rad))

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

0 comments on commit c64de21

Please sign in to comment.