QgsRectangle QgsMapSettings::computeExtentForScale( const QgsPointXY &point, double scale, const QgsCoordinateReferenceSystem &sourceCrs ) const { QgsPointXY center = QgsCoordinateTransform( sourceCrs, destinationCrs(), mTransformContext ).transform( point ); // Output width in inches double outWIn = outputSize().width() / double( outputDpi() ); // Desired visible width (honouring scale) double scaledWIn = outWIn * scale; if ( mapUnits() == QgsUnitTypes::DistanceDegrees ) { // Start with an 1x1 extent around the center QgsRectangle ext( center.x() - 0.5, center.y() - 0.5, center.x() + 0.5, center.y() + 0.5 ); // Get scale at extent, and then scale extent to the desired scale double testScale = mScaleCalculator.calculate( ext, outputSize().width() ); ext.scale( scale / testScale ); return ext; } // Conversion from inches to mapUnits double conversionFactor = 12 * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::DistanceFeet, mapUnits() ); double delta = 0.5 * scaledWIn * conversionFactor; return QgsRectangle( center.x() - delta, center.y() - delta, center.x() + delta, center.y() + delta ); }
void QgsMapSettings::setMagnificationFactor( double factor ) { double ratio = mMagnificationFactor / factor; mMagnificationFactor = factor; double rot = rotation(); setRotation( 0.0 ); QgsRectangle ext = visibleExtent(); ext.scale( ratio ); mRotation = rot; mExtent = ext; mDpi = outputDpi() / ratio; updateDerived(); }