@@ -80,7 +80,14 @@ CoordinateCapture::~CoordinateCapture()
80
80
*/
81
81
void CoordinateCapture::initGui ()
82
82
{
83
- mEpsgId = GEO_EPSG_CRS_ID;
83
+ mCrs .createFromSrsId ( GEOCRS_ID ); // initialize the CRS object
84
+
85
+ connect ( mQGisIface ->mapCanvas ()->mapRenderer (), SIGNAL ( destinationSrsChanged () ), this , SLOT ( setSourceCrs () ) );
86
+
87
+ setSourceCrs (); // set up the source CRS
88
+ mTransform .setDestCRS ( mCrs ); // set the CRS in the transform
89
+ mUserCrsDisplayPrecision = ( mCrs .mapUnits () == QGis::Degrees ) ? 8 : 3 ; // precision depends on CRS units
90
+
84
91
// Create the action for tool
85
92
mQActionPointer = new QAction ( QIcon ( " :/coordinatecapture/coordinate_capture.png" ), tr ( " Coordinate Capture" ), this );
86
93
// Set the what's this text
@@ -158,14 +165,21 @@ void CoordinateCapture::help()
158
165
void CoordinateCapture::setCRS ()
159
166
{
160
167
QgsGenericProjectionSelector mySelector ( mQGisIface ->mainWindow () );
161
- mySelector.setSelectedEpsg ( mEpsgId );
168
+ mySelector.setSelectedCrsId ( mCrs . srsid () );
162
169
if ( mySelector.exec () )
163
170
{
164
- mEpsgId = mySelector.selectedEpsg ();
165
- mProj4Str = mySelector.selectedProj4String ();
171
+ mCrs .createFromSrsId ( mySelector.selectedCrsId () );
172
+ mTransform .setDestCRS ( mCrs );
173
+ mUserCrsDisplayPrecision = ( mCrs .mapUnits () == QGis::Degrees ) ? 8 : 3 ; // precision depends on CRS units
166
174
}
167
175
}
168
176
177
+ void CoordinateCapture::setSourceCrs ()
178
+ {
179
+ mTransform .setSourceCrs ( mQGisIface ->mapCanvas ()->mapRenderer ()->destinationSrs () );
180
+ mCanvasDisplayPrecision = ( mQGisIface ->mapCanvas ()->mapRenderer ()->destinationSrs ().mapUnits () == QGis::Degrees ) ? 8 : 3 ; // for the map canvas coordinate display
181
+ }
182
+
169
183
void CoordinateCapture::mouseClicked ( QgsPoint thePoint )
170
184
{
171
185
// clicking on the canvas will update the widgets and then disable
@@ -185,15 +199,12 @@ void CoordinateCapture::mouseMoved( QgsPoint thePoint )
185
199
void CoordinateCapture::update ( QgsPoint thePoint )
186
200
{
187
201
// this is the coordinate resolved back to lat / lon
188
- QgsCoordinateReferenceSystem mySrs;
189
- mySrs.createFromProj4 ( mProj4Str );
190
- QgsCoordinateTransform myTransform ( mQGisIface ->mapCanvas ()->mapRenderer ()->destinationSrs (), mySrs );
191
- QgsPoint myUserCrsPoint = myTransform.transform ( thePoint );
192
- mpUserCrsEdit->setText ( QString::number ( myUserCrsPoint.x (), ' f' , 3 ) + " ," +
193
- QString::number ( myUserCrsPoint.y (), ' f' , 3 ) );
202
+ QgsPoint myUserCrsPoint = mTransform .transform ( thePoint );
203
+ mpUserCrsEdit->setText ( QString::number ( myUserCrsPoint.x (), ' f' , mUserCrsDisplayPrecision ) + " ," +
204
+ QString::number ( myUserCrsPoint.y (), ' f' , mUserCrsDisplayPrecision ) );
194
205
// This is the coordinate space of the map canvas
195
- mpCanvasEdit->setText ( QString::number ( thePoint.x (), ' f' , 3 ) + " ," +
196
- QString::number ( thePoint.y (), ' f' , 3 ) );
206
+ mpCanvasEdit->setText ( QString::number ( thePoint.x (), ' f' , mCanvasDisplayPrecision ) + " ," +
207
+ QString::number ( thePoint.y (), ' f' , mCanvasDisplayPrecision ) );
197
208
}
198
209
void CoordinateCapture::copy ()
199
210
{
0 commit comments