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.

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 9552777d6ad4a0043a05a3061ebae646f6df3dd9
@@ -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;
@@ -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 );
@@ -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; }

@@ -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 9552777

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