File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -1796,7 +1796,24 @@ void QgsLegend::legendLayerZoomNative()
17961796 QgsDebugMsg ( " MapUnitsPerPixel before : " + QString::number ( mMapCanvas ->mapUnitsPerPixel () ) );
17971797
17981798 layer->setCacheImage ( NULL );
1799- mMapCanvas ->zoomByFactor ( qAbs ( layer->rasterUnitsPerPixel () / mMapCanvas ->mapUnitsPerPixel () ) );
1799+ if ( mMapCanvas ->hasCrsTransformEnabled () )
1800+ {
1801+ // get legth of central canvas pixel width in source raster crs
1802+ QgsRectangle e = mMapCanvas ->extent ();
1803+ QgsMapRenderer* r = mMapCanvas ->mapRenderer ();
1804+ QgsPoint p1 ( e.center ().x (), e.center ().y () );
1805+ QgsPoint p2 ( e.center ().x () + e.width () / r->width (), e.center ().y () + e.height () / r->height () );
1806+ QgsCoordinateTransform ct ( r->destinationCrs (), layer->crs () );
1807+ p1 = ct.transform ( p1 );
1808+ p2 = ct.transform ( p2 );
1809+ double width = sqrt ( p1.sqrDist ( p2 ) ); // width of reprojected pixel
1810+ // This is not perfect of course, we use the resolution in just one direction
1811+ mMapCanvas ->zoomByFactor ( qAbs ( layer->rasterUnitsPerPixel () / width ) );
1812+ }
1813+ else
1814+ {
1815+ mMapCanvas ->zoomByFactor ( qAbs ( layer->rasterUnitsPerPixel () / mMapCanvas ->mapUnitsPerPixel () ) );
1816+ }
18001817 mMapCanvas ->refresh ();
18011818 QgsDebugMsg ( " MapUnitsPerPixel after : " + QString::number ( mMapCanvas ->mapUnitsPerPixel () ) );
18021819 }
You can’t perform that action at this time.
0 commit comments