Index: src/plugins/coordinate_capture/coordinatecapture.cpp =================================================================== --- src/plugins/coordinate_capture/coordinatecapture.cpp (revision 9913) +++ src/plugins/coordinate_capture/coordinatecapture.cpp (working copy) @@ -80,7 +80,14 @@ */ 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::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::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() { Index: src/plugins/coordinate_capture/coordinatecapture.h =================================================================== --- src/plugins/coordinate_capture/coordinatecapture.h (revision 9913) +++ src/plugins/coordinate_capture/coordinatecapture.h (working copy) @@ -43,6 +43,8 @@ //QGIS includes #include "../qgisplugin.h" #include "coordinatecapturemaptool.h" +#include +#include //forward declarations class QAction; @@ -99,8 +101,9 @@ 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 QPointer mpDockWidget; @@ -117,11 +120,18 @@ //!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; + //////////////////////////////////////////////////////////////////// // // MANDATORY PLUGIN PROPERTY DECLARATIONS .....