void QgsMapSettings::writeXML( QDomNode& theNode, QDomDocument& theDoc ) { // units theNode.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), theDoc ) ); // Write current view extents theNode.appendChild( QgsXmlUtils::writeRectangle( extent(), theDoc ) ); // Write current view rotation QDomElement rotNode = theDoc.createElement( "rotation" ); rotNode.appendChild( theDoc.createTextNode( qgsDoubleToString( rotation() ) ) ); theNode.appendChild( rotNode ); // projections enabled QDomElement projNode = theDoc.createElement( "projections" ); projNode.appendChild( theDoc.createTextNode( QString::number( hasCrsTransformEnabled() ) ) ); theNode.appendChild( projNode ); // destination CRS QDomElement srsNode = theDoc.createElement( "destinationsrs" ); theNode.appendChild( srsNode ); destinationCrs().writeXML( srsNode, theDoc ); //render map tile QDomElement renderMapTileElem = theDoc.createElement( "rendermaptile" ); QDomText renderMapTileText = theDoc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" ); renderMapTileElem.appendChild( renderMapTileText ); theNode.appendChild( renderMapTileElem ); mDatumTransformStore.writeXML( theNode, theDoc ); }
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 ); }
QgsPointLocator *QgsSnappingUtils::temporaryLocatorForLayer( QgsVectorLayer *vl, const QgsPointXY &pointMap, double tolerance ) { if ( mTemporaryLocators.contains( vl ) ) delete mTemporaryLocators.take( vl ); QgsRectangle rect( pointMap.x() - tolerance, pointMap.y() - tolerance, pointMap.x() + tolerance, pointMap.y() + tolerance ); QgsPointLocator *vlpl = new QgsPointLocator( vl, destinationCrs(), mMapSettings.transformContext(), &rect ); mTemporaryLocators.insert( vl, vlpl ); return mTemporaryLocators.value( vl ); }
QgsPointLocator *QgsSnappingUtils::locatorForLayer( QgsVectorLayer *vl ) { if ( !vl ) return nullptr; if ( !mLocators.contains( vl ) ) { QgsPointLocator *vlpl = new QgsPointLocator( vl, destinationCrs(), mMapSettings.transformContext() ); mLocators.insert( vl, vlpl ); } return mLocators.value( vl ); }