25#include "moc_qgsmapoverlaytexturegenerator_p.cpp"
27using namespace Qt::StringLiterals;
31QgsMapOverlayTextureGenerator::QgsMapOverlayTextureGenerator(
const Qgs3DMapSettings &mapSettings,
int size )
32 : m3DMapSettings( mapSettings )
33 , mSize( QSize( size, size ) )
38QgsMapOverlayTextureGenerator::~QgsMapOverlayTextureGenerator()
43int QgsMapOverlayTextureGenerator::render(
const QgsRectangle &extent,
const QVector<QgsPointXY> &frustumExtent,
double azimuthDegrees,
bool showFrustum )
47 mapSettings.setExtent( extent );
50 mRotation = azimuthDegrees;
51 mFrustumExtent = frustumExtent;
52 mShowFrustum = showFrustum;
54 QgsEventTracing::addEvent( QgsEventTracing::AsyncBegin, u
"3D"_s, u
"Texture"_s, QString::number( mLastJobId ) );
64void QgsMapOverlayTextureGenerator::cancelActiveJob()
73 mActiveJob->cancelWithoutBlocking();
77void QgsMapOverlayTextureGenerator::onRenderingFinished()
79 QImage renderedImage = mActiveJob->renderedImage();
80 const QPoint center = renderedImage.rect().center();
82 QPainter painter( &renderedImage );
83 painter.setRenderHint( QPainter::Antialiasing );
84 painter.setPen( QPen( Qt::black, 2 ) );
87 painter.setBackgroundMode( Qt::OpaqueMode );
88 painter.drawRect( renderedImage.rect().adjusted( 1, 1, -1, -1 ) );
91 const int arrowSize = 16;
92 painter.setBrush( QColor( 0, 0, 0, 50 ) );
93 painter.setPen( QPen( QColor( 0, 0, 0, 120 ), 1 ) );
94 painter.drawEllipse( center, arrowSize, arrowSize );
97 painter.setBrush( QColor( 0, 0, 0, 160 ) );
98 painter.setPen( Qt::NoPen );
101 arrow << QPoint( 0, -arrowSize )
102 << QPoint( -arrowSize / 3, 0 )
103 << QPoint( arrowSize / 3, 0 );
105 painter.translate( center );
107 painter.rotate( -mRotation );
108 painter.drawPolygon( arrow );
113 painter.rotate( mRotation );
114 painter.translate( -center );
115 painter.setBrush( QColor::fromRgba( qRgba( 0, 0, 255, 50 ) ) );
117 double sizeX = mSize.width() / mExtent.width();
118 double sizeY = mSize.height() / mExtent.height();
119 for (
const QgsPointXY &frustumPoint : mFrustumExtent )
121 frustum << QPointF( ( frustumPoint.x() - mExtent.xMinimum() ) * sizeX, mSize.height() - ( frustumPoint.y() - mExtent.yMinimum() ) * sizeY );
124 painter.drawPolygon( frustum );
129 mActiveJob->deleteLater();
130 mActiveJob =
nullptr;
132 QgsEventTracing::addEvent( QgsEventTracing::AsyncEnd, u
"3D"_s, u
"Texture"_s, QString::number( mLastJobId ) );
135 emit textureReady( renderedImage );
138QgsMapSettings QgsMapOverlayTextureGenerator::baseMapSettings()
const
149 mapSettings.
setLayers( m3DMapSettings.layers() );
@ Globe
Scene is represented as a globe using a geocentric CRS.
@ DrawLabeling
Enable drawing of labels on top of the map.
void finished()
emitted when asynchronous rendering is finished (or canceled).
Job implementation that renders all layers in parallel.
Contains configuration for rendering maps.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers to render in the map.
void setRendererUsage(Qgis::RendererUsage rendererUsage)
Sets the rendering usage.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
void setOutputSize(QSize size)
Sets the size of the resulting map image, in pixels.
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
void setFlag(Qgis::MapSettingsFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected).
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Sets the destination crs (coordinate reference system) for the map render.
A rectangle specified with double values.