Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 320596f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
14 changes: 14 additions & 0 deletions python/core/auto_generated/qgslegendsettings.sip.in
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgslegendsettings.cpp
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/core/qgslegendsettings.h
Expand Up @@ -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; }

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

0 comments on commit 320596f

Please sign in to comment.