26#include "moc_qgsmapoverlaytexturegenerator_p.cpp"
28using namespace Qt::StringLiterals;
32QgsMapOverlayTextureGenerator::QgsMapOverlayTextureGenerator(
const Qgs3DMapSettings &mapSettings,
int size )
33 : m3DMapSettings( mapSettings )
34 , 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 );
102 << QPoint( 0, -arrowSize )
103 << QPoint( -arrowSize / 3, 0 )
104 << QPoint( arrowSize / 3, 0 );
106 painter.translate( center );
108 painter.rotate( -mRotation );
109 painter.drawPolygon( arrow );
114 painter.rotate( mRotation );
115 painter.translate( -center );
116 painter.setBrush( QColor::fromRgba( qRgba( 0, 0, 255, 50 ) ) );
118 double sizeX = mSize.width() / mExtent.width();
119 double sizeY = mSize.height() / mExtent.height();
120 for (
const QgsPointXY &frustumPoint : mFrustumExtent )
122 frustum << QPointF( ( frustumPoint.x() - mExtent.xMinimum() ) * sizeX, mSize.height() - ( frustumPoint.y() - mExtent.yMinimum() ) * sizeY );
125 painter.drawPolygon( frustum );
130 mActiveJob->deleteLater();
131 mActiveJob =
nullptr;
133 QgsEventTracing::addEvent( QgsEventTracing::AsyncEnd, u
"3D"_s, u
"Texture"_s, QString::number( mLastJobId ) );
136 emit textureReady( renderedImage );
139QgsMapSettings QgsMapOverlayTextureGenerator::baseMapSettings()
const
150 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.