Skip to content

Commit 320596f

Browse files
committedFeb 26, 2019
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
1 parent fb81ce6 commit 320596f

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed
 

‎python/core/auto_generated/qgslegendsettings.sip.in

+14
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,20 @@ Sets the legend map ``scale``.
192192
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
193193

194194
.. seealso:: :py:func:`mapScale`
195+
%End
196+
197+
double mapUnitsPerPixel() const;
198+
%Docstring
199+
Returns the factor of map units per pixel for symbols with size given in map units calculated by mDpi and mMmPerMapUnit
200+
201+
.. seealso:: :py:func:`setMapUnitsPerPixel`
202+
%End
203+
204+
void setMapUnitsPerPixel( double mapUnitsPerPixel );
205+
%Docstring
206+
Sets the the mMmPerMapUnit calculated by ``mapUnitsPerPixel`` mostly taken from the map settings.
207+
208+
.. seealso:: :py:func:`mapUnitsPerPixel`
195209
%End
196210

197211
int dpi() const;

‎src/core/qgslegendsettings.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ QgsLegendSettings::QgsLegendSettings()
3535
rstyle( QgsLegendStyle::SymbolLabel ).rfont().setPointSizeF( 12.0 );
3636
}
3737

38+
double QgsLegendSettings::mapUnitsPerPixel() const
39+
{
40+
return 1 / ( mMmPerMapUnit * ( mDpi / 25.4 ) );
41+
}
42+
43+
void QgsLegendSettings::setMapUnitsPerPixel( double mapUnitsPerPixel )
44+
{
45+
mMmPerMapUnit = 1 / mapUnitsPerPixel / ( mDpi / 25.4 );
46+
}
47+
3848
QStringList QgsLegendSettings::splitStringForWrapping( const QString &stringToSplt ) const
3949
{
4050
QStringList list;

‎src/core/qgslegendsettings.h

+12
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ class CORE_EXPORT QgsLegendSettings
177177
*/
178178
void setMapScale( double scale ) { mMapScale = scale; }
179179

180+
/**
181+
* Returns the factor of map units per pixel for symbols with size given in map units calculated by mDpi and mMmPerMapUnit
182+
* \see setMapUnitsPerPixel()
183+
*/
184+
double mapUnitsPerPixel() const;
185+
186+
/**
187+
* Sets the the mMmPerMapUnit calculated by \a mapUnitsPerPixel mostly taken from the map settings.
188+
* \see mapUnitsPerPixel()
189+
*/
190+
void setMapUnitsPerPixel( double mapUnitsPerPixel );
191+
180192
int dpi() const { return mDpi; }
181193
void setDpi( int dpi ) { mDpi = dpi; }
182194

‎src/server/services/wms/qgswmsrenderer.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ namespace QgsWms
193193
std::unique_ptr<QImage> image;
194194
std::unique_ptr<QPainter> painter;
195195

196+
// getting scale from bbox
197+
if ( !mWmsParameters.bbox().isEmpty() )
198+
{
199+
QgsMapSettings mapSettings;
200+
image.reset( createImage( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) );
201+
configureMapSettings( image.get(), mapSettings );
202+
legendSettings.setMapScale( mapSettings.scale() );
203+
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
204+
}
205+
196206
if ( !mWmsParameters.rule().isEmpty() )
197207
{
198208
QString rule = mWmsParameters.rule();

0 commit comments

Comments
 (0)
Please sign in to comment.