Skip to content
Permalink
Browse files

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
  • Loading branch information
signedav committed Feb 21, 2019
1 parent 24c09d1 commit a04f91b840f8bce5cbcbd9d9211fa3aa6fe236c5
@@ -395,7 +395,7 @@ QSizeF QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemC
QgsRenderContext context;
context.setScaleFactor( settings.dpi() / 25.4 );
context.setRendererScale( settings.mapScale() );
context.setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) ) );
context.setMapToPixel( QgsMapToPixel( settings.mapUnitsPerPixel() == 1 ? 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) : settings.mapUnitsPerPixel() ) );
context.setForceVectorOutput( true );
context.setPainter( ctx ? ctx->painter : nullptr );

@@ -178,6 +178,18 @@ class CORE_EXPORT QgsLegendSettings
*/
void setMapScale( double scale ) { mMapScale = scale; }

/**
* Returns the factor of map units per pixel used for symbol sized by map units.
* \see setMapScale()
*/
double mapUnitsPerPixel() const { return mMapUnitsPerPixel; }

/**
* Sets the map units per pixel \a mapUnitsPerPixel mostly taken from the map settings.
* \see mapUnitsPerPixel()
*/
void setMapUnitsPerPixel( double mapUnitsPerPixel ) { mMapUnitsPerPixel = mapUnitsPerPixel; }

int dpi() const { return mDpi; }
void setDpi( int dpi ) { mDpi = dpi; }

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

//! the map units per pixel given by the map parameters - for symbols with size given in map units
double mMapUnitsPerPixel = 1;

//! DPI to be used when rendering legend
int mDpi = 96;
};
@@ -183,6 +183,16 @@ namespace QgsWms
std::unique_ptr<QImage> image;
std::unique_ptr<QPainter> painter;

// getting scale from bbox
if( !mWmsParameters.bbox().isEmpty() )
{
QgsMapSettings mapSettings;
image.reset( createImage( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) );
configureMapSettings( image.get(), mapSettings );
legendSettings.setMapScale( mapSettings.scale() );
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
}

if ( !mWmsParameters.rule().isEmpty() )
{
QString rule = mWmsParameters.rule();

0 comments on commit a04f91b

Please sign in to comment.
You can’t perform that action at this time.