Skip to content

Commit a04f91b

Browse files
committed
use scale and mapUnitsPerPixel from map parameters bbox and size
in case bbox and size is given in the GetLegendGraphics request, the size of symbols defined by map units is calculated regarding the scale of that. fixes #21309
1 parent 24c09d1 commit a04f91b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/core/layertree/qgslayertreemodellegendnode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ QSizeF QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemC
395395
QgsRenderContext context;
396396
context.setScaleFactor( settings.dpi() / 25.4 );
397397
context.setRendererScale( settings.mapScale() );
398-
context.setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) ) );
398+
context.setMapToPixel( QgsMapToPixel( settings.mapUnitsPerPixel() == 1 ? 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) : settings.mapUnitsPerPixel() ) );
399399
context.setForceVectorOutput( true );
400400
context.setPainter( ctx ? ctx->painter : nullptr );
401401

src/core/qgslegendsettings.h

+15
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ class CORE_EXPORT QgsLegendSettings
178178
*/
179179
void setMapScale( double scale ) { mMapScale = scale; }
180180

181+
/**
182+
* Returns the factor of map units per pixel used for symbol sized by map units.
183+
* \see setMapScale()
184+
*/
185+
double mapUnitsPerPixel() const { return mMapUnitsPerPixel; }
186+
187+
/**
188+
* Sets the map units per pixel \a mapUnitsPerPixel mostly taken from the map settings.
189+
* \see mapUnitsPerPixel()
190+
*/
191+
void setMapUnitsPerPixel( double mapUnitsPerPixel ) { mMapUnitsPerPixel = mapUnitsPerPixel; }
192+
181193
int dpi() const { return mDpi; }
182194
void setDpi( int dpi ) { mDpi = dpi; }
183195

@@ -290,6 +302,9 @@ class CORE_EXPORT QgsLegendSettings
290302
//! Denominator of map's scale
291303
double mMapScale = 1;
292304

305+
//! the map units per pixel given by the map parameters - for symbols with size given in map units
306+
double mMapUnitsPerPixel = 1;
307+
293308
//! DPI to be used when rendering legend
294309
int mDpi = 96;
295310
};

src/server/services/wms/qgswmsrenderer.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ namespace QgsWms
183183
std::unique_ptr<QImage> image;
184184
std::unique_ptr<QPainter> painter;
185185

186+
// getting scale from bbox
187+
if( !mWmsParameters.bbox().isEmpty() )
188+
{
189+
QgsMapSettings mapSettings;
190+
image.reset( createImage( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) );
191+
configureMapSettings( image.get(), mapSettings );
192+
legendSettings.setMapScale( mapSettings.scale() );
193+
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
194+
}
195+
186196
if ( !mWmsParameters.rule().isEmpty() )
187197
{
188198
QString rule = mWmsParameters.rule();

0 commit comments

Comments
 (0)