Skip to content
Permalink
Browse files

Applied patch from ticket #1478 to trunk

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9940 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux
timlinux committed Jan 7, 2009
1 parent 4a51f64 commit 1cc04413f625c5c34d7d740612c632ff783e5bd6
@@ -80,7 +80,14 @@ CoordinateCapture::~CoordinateCapture()
*/
void CoordinateCapture::initGui()
{
mEpsgId = GEO_EPSG_CRS_ID;
mCrs.createFromSrsId( GEOCRS_ID ); // initialize the CRS object

connect( mQGisIface->mapCanvas()->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( setSourceCrs() ) );

setSourceCrs(); //set up the source CRS
mTransform.setDestCRS( mCrs ); // set the CRS in the transform
mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 8 : 3; // precision depends on CRS units

// Create the action for tool
mQActionPointer = new QAction( QIcon( ":/coordinatecapture/coordinate_capture.png" ), tr( "Coordinate Capture" ), this );
// Set the what's this text
@@ -158,14 +165,21 @@ void CoordinateCapture::help()
void CoordinateCapture::setCRS()
{
QgsGenericProjectionSelector mySelector( mQGisIface->mainWindow() );
mySelector.setSelectedEpsg( mEpsgId );
mySelector.setSelectedCrsId( mCrs.srsid() );
if ( mySelector.exec() )
{
mEpsgId = mySelector.selectedEpsg();
mProj4Str = mySelector.selectedProj4String();
mCrs.createFromSrsId( mySelector.selectedCrsId() );
mTransform.setDestCRS( mCrs );
mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 8 : 3; //precision depends on CRS units
}
}

void CoordinateCapture::setSourceCrs()
{
mTransform.setSourceCrs( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs() );
mCanvasDisplayPrecision = ( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs().mapUnits() == QGis::Degrees ) ? 8 : 3; // for the map canvas coordinate display
}

void CoordinateCapture::mouseClicked( QgsPoint thePoint )
{
//clicking on the canvas will update the widgets and then disable
@@ -185,15 +199,12 @@ void CoordinateCapture::mouseMoved( QgsPoint thePoint )
void CoordinateCapture::update( QgsPoint thePoint )
{
//this is the coordinate resolved back to lat / lon
QgsCoordinateReferenceSystem mySrs;
mySrs.createFromProj4( mProj4Str );
QgsCoordinateTransform myTransform( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs(), mySrs );
QgsPoint myUserCrsPoint = myTransform.transform( thePoint );
mpUserCrsEdit->setText( QString::number( myUserCrsPoint.x(), 'f', 3 ) + "," +
QString::number( myUserCrsPoint.y(), 'f', 3 ) );
QgsPoint myUserCrsPoint = mTransform.transform( thePoint );
mpUserCrsEdit->setText( QString::number( myUserCrsPoint.x(), 'f', mUserCrsDisplayPrecision ) + "," +
QString::number( myUserCrsPoint.y(), 'f', mUserCrsDisplayPrecision ) );
// This is the coordinate space of the map canvas
mpCanvasEdit->setText( QString::number( thePoint.x(), 'f', 3 ) + "," +
QString::number( thePoint.y(), 'f', 3 ) );
mpCanvasEdit->setText( QString::number( thePoint.x(), 'f', mCanvasDisplayPrecision ) + "," +
QString::number( thePoint.y(), 'f', mCanvasDisplayPrecision ) );
}
void CoordinateCapture::copy()
{
@@ -43,6 +43,8 @@
//QGIS includes
#include "../qgisplugin.h"
#include "coordinatecapturemaptool.h"
#include <qgscoordinatereferencesystem.h>
#include <qgscoordinatetransform.h>

//forward declarations
class QAction;
@@ -99,7 +101,8 @@ class CoordinateCapture: public QObject, public QgisPlugin
void update( QgsPoint thePoint );
//! Called when user clicks the copy button
void copy();

//! called when the project's CRS is changed
void setSourceCrs();

private:
//! Container for the coordinate info
@@ -117,10 +120,17 @@ class CoordinateCapture: public QObject, public QgisPlugin
//!A toolbutton to keep track whether mouse tracking is enabled
QToolButton * mpTrackMouseButton;

//!epsg id for showin in geoedit box
long mEpsgId;
//!proj4 string for coordinate translation
QString mProj4Str;
//! transform object
QgsCoordinateTransform mTransform;

//! map coordinate display precision
int mCanvasDisplayPrecision;

//! user CRS object
QgsCoordinateReferenceSystem mCrs;

//! user coordinate display precision
int mUserCrsDisplayPrecision;

////////////////////////////////////////////////////////////////////
//

0 comments on commit 1cc0441

Please sign in to comment.
You can’t perform that action at this time.