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 t$

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

(cherry-picked from a04f91b 7de50a0 3e86163) and resolved conflicts
  • Loading branch information
signedav committed Feb 26, 2019
1 parent fb81ce6 commit 320596fa0010c47c36716bbf8cb6162b9efe7103
@@ -192,6 +192,20 @@ 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 mDpi and mMmPerMapUnit

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

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

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

int dpi() const;
@@ -35,6 +35,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::splitStringForWrapping( const QString &stringToSplt ) const
{
QStringList list;
@@ -177,6 +177,18 @@ 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 mDpi and mMmPerMapUnit
* \see setMapUnitsPerPixel()
*/
double mapUnitsPerPixel() const;

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

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

@@ -193,6 +193,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 320596f

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