Skip to content

Commit

Permalink
use scale and mapUnitsPerPixel from map parameters bbox and size. in …
Browse files Browse the repository at this point in the history
…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.

calculate mMmPerMapUnit with mapUnitsPerPixel to avoid to have redundant info
fixes #21309

(cherry-picked from a04f91b 7de50a0 3e86163)
  • Loading branch information
signedav committed Feb 26, 2019
1 parent 96b25ab commit 9552777
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/core/auto_generated/qgslegendsettings.sip.in
Expand Up @@ -192,6 +192,24 @@ Sets the legend map ``scale``.
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

.. seealso:: :py:func:`mapScale`
%End

double mapUnitsPerPixel() const;
%Docstring
Returns the factor of map units per pixel for symbols with size given in map units calculated by dpi and mmPerMapUnit

.. seealso:: :py:func:`setMapUnitsPerPixel`

.. versionadded:: 3.6
%End

void setMapUnitsPerPixel( double mapUnitsPerPixel );
%Docstring
Sets the the mmPerMapUnit calculated by ``mapUnitsPerPixel`` mostly taken from the map settings.

.. seealso:: :py:func:`mapUnitsPerPixel`

.. versionadded:: 3.6
%End

int dpi() const;
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgslegendsettings.cpp
Expand Up @@ -37,6 +37,16 @@ QgsLegendSettings::QgsLegendSettings()
rstyle( QgsLegendStyle::SymbolLabel ).rfont().setPointSizeF( 12.0 );
}

double QgsLegendSettings::mapUnitsPerPixel() const
{
return 1 / ( mMmPerMapUnit * ( mDpi / 25.4 ) );
}

void QgsLegendSettings::setMapUnitsPerPixel( double mapUnitsPerPixel )
{
mMmPerMapUnit = 1 / mapUnitsPerPixel / ( mDpi / 25.4 );
}

QStringList QgsLegendSettings::evaluateItemText( const QString &text, const QgsExpressionContext &context ) const
{
const QString textToRender = QgsExpression::replaceExpressionText( text, &context );
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgslegendsettings.h
Expand Up @@ -178,6 +178,20 @@ class CORE_EXPORT QgsLegendSettings
*/
void setMapScale( double scale ) { mMapScale = scale; }

/**
* Returns the factor of map units per pixel for symbols with size given in map units calculated by dpi and mmPerMapUnit
* \see setMapUnitsPerPixel()
* \since QGIS 3.6
*/
double mapUnitsPerPixel() const;

/**
* Sets the the mmPerMapUnit calculated by \a mapUnitsPerPixel mostly taken from the map settings.
* \see mapUnitsPerPixel()
* \since QGIS 3.6
*/
void setMapUnitsPerPixel( double mapUnitsPerPixel );

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

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 9552777

Please sign in to comment.