Skip to content

Commit 9552777

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 that.
calculate mMmPerMapUnit with mapUnitsPerPixel to avoid to have redundant info fixes #21309 (cherry-picked from a04f91b 7de50a0 3e86163)
1 parent 96b25ab commit 9552777

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
 

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

+18
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,24 @@ 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 dpi and mmPerMapUnit
200+
201+
.. seealso:: :py:func:`setMapUnitsPerPixel`
202+
203+
.. versionadded:: 3.6
204+
%End
205+
206+
void setMapUnitsPerPixel( double mapUnitsPerPixel );
207+
%Docstring
208+
Sets the the mmPerMapUnit calculated by ``mapUnitsPerPixel`` mostly taken from the map settings.
209+
210+
.. seealso:: :py:func:`mapUnitsPerPixel`
211+
212+
.. versionadded:: 3.6
195213
%End
196214

197215
int dpi() const;

‎src/core/qgslegendsettings.cpp

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

40+
double QgsLegendSettings::mapUnitsPerPixel() const
41+
{
42+
return 1 / ( mMmPerMapUnit * ( mDpi / 25.4 ) );
43+
}
44+
45+
void QgsLegendSettings::setMapUnitsPerPixel( double mapUnitsPerPixel )
46+
{
47+
mMmPerMapUnit = 1 / mapUnitsPerPixel / ( mDpi / 25.4 );
48+
}
49+
4050
QStringList QgsLegendSettings::evaluateItemText( const QString &text, const QgsExpressionContext &context ) const
4151
{
4252
const QString textToRender = QgsExpression::replaceExpressionText( text, &context );

‎src/core/qgslegendsettings.h

+14
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,20 @@ class CORE_EXPORT QgsLegendSettings
178178
*/
179179
void setMapScale( double scale ) { mMapScale = scale; }
180180

181+
/**
182+
* Returns the factor of map units per pixel for symbols with size given in map units calculated by dpi and mmPerMapUnit
183+
* \see setMapUnitsPerPixel()
184+
* \since QGIS 3.6
185+
*/
186+
double mapUnitsPerPixel() const;
187+
188+
/**
189+
* Sets the the mmPerMapUnit calculated by \a mapUnitsPerPixel mostly taken from the map settings.
190+
* \see mapUnitsPerPixel()
191+
* \since QGIS 3.6
192+
*/
193+
void setMapUnitsPerPixel( double mapUnitsPerPixel );
194+
181195
int dpi() const { return mDpi; }
182196
void setDpi( int dpi ) { mDpi = dpi; }
183197

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

+10
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ namespace QgsWms
183183
std::unique_ptr<QImage> image;
184184
std::unique_ptr<QPainter> painter;
185185

186+
// getting scale from bbox
187+
if ( !mWmsParameters.bbox().isEmpty() )
188+
{
189+
QgsMapSettings mapSettings;
190+
image.reset( createImage( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) );
191+
configureMapSettings( image.get(), mapSettings );
192+
legendSettings.setMapScale( mapSettings.scale() );
193+
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
194+
}
195+
186196
if ( !mWmsParameters.rule().isEmpty() )
187197
{
188198
QString rule = mWmsParameters.rule();

0 commit comments

Comments
 (0)
Please sign in to comment.