Skip to content

Commit

Permalink
use scale and mapUnitsPerPixel from map parameters bbox and size
Browse files Browse the repository at this point in the history
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 a04f91b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -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 );

Expand Down
15 changes: 15 additions & 0 deletions src/core/qgslegendsettings.h
Expand Up @@ -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; }

Expand Down Expand Up @@ -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;
};
Expand Down
10 changes: 10 additions & 0 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit a04f91b

Please sign in to comment.