Skip to content
Permalink
Browse files

backport for default map scale / default map units per mm in project …

…for the case that GetLegendGraphic request does not pass parameters to calculate map unit sized symbol size

(cherry-picks of 7ef426b 10b5f08 3d7cc16 1c3cfd1 679b100 96f054e 7f7d910 755c8ff 1d6a7dd 8e62a89 c22effb fa8e5fa fab5254 27fc381)
  • Loading branch information
signedav committed Apr 2, 2019
1 parent 1782384 commit 042bd1f140e6b11225d5a39f7393f76fae11838e
@@ -161,6 +161,17 @@ Returns the maximum number of atlas features which can be printed in a request
:param project: the QGIS project

:return: the number of atlas features
%End

double wmsDefaultMapUnitsPerMm( const QgsProject &project );
%Docstring
Returns the default number of map units per millimeters in case of the scale is not given

:param project: the QGIS project

:return: the default number of map units per millimeter

.. versionadded:: 3.8
%End

bool wmsUseLayerIds( const QgsProject &project );
@@ -642,6 +642,25 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa

mWMSMaxAtlasFeaturesSpinBox->setValue( QgsProject::instance()->readNumEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), 1 ) );

QString defaultValueToolTip = tr( "In case of no other information to evaluate the map unit sized symbols, it uses default scale (on projected CRS) or default map units per mm (on geographic CRS)." );
mWMSDefaultMapUnitsPerMm = new QDoubleSpinBox();
mWMSDefaultMapUnitsPerMm->setDecimals( 4 );
mWMSDefaultMapUnitsPerMm->setSingleStep( 0.001 );
mWMSDefaultMapUnitsPerMm->setValue( QgsProject::instance()->readDoubleEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), 1 ) );
mWMSDefaultMapUnitsPerMm->setToolTip( defaultValueToolTip );
mWMSDefaultMapUnitScale = new QgsScaleWidget();
mWMSDefaultMapUnitScale->setScale( QgsProject::instance()->readDoubleEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), 1 ) * QgsUnitTypes::fromUnitToUnitFactor( QgsProject::instance()->crs().mapUnits(), QgsUnitTypes::DistanceMillimeters ) );
mWMSDefaultMapUnitScale->setToolTip( defaultValueToolTip );
if ( QgsProject::instance()->crs().isGeographic() )
{
mWMSDefaultMapUnitsPerMmLayout->addWidget( mWMSDefaultMapUnitsPerMm );
}
else
{
mWMSDefaultMapUnitsPerMmLayout->addWidget( mWMSDefaultMapUnitScale );
mWMSDefaultMapUnitsPerMmLabel->setText( tr( "Default scale for legend" ) );
}

mWMTSUrlLineEdit->setText( QgsProject::instance()->readEntry( QStringLiteral( "WMTSUrl" ), QStringLiteral( "/" ), QString() ) );
mWMTSMinScaleLineEdit->setValue( QgsProject::instance()->readNumEntry( QStringLiteral( "WMTSMinScale" ), QStringLiteral( "/" ), 5000 ) );

@@ -1298,6 +1317,18 @@ void QgsProjectProperties::apply()
int maxAtlasFeatures = mWMSMaxAtlasFeaturesSpinBox->value();
QgsProject::instance()->writeEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), maxAtlasFeatures );

double defaultMapUnitsPerMm;
if ( QgsProject::instance()->crs().isGeographic() )
{
defaultMapUnitsPerMm = mWMSDefaultMapUnitsPerMm->value();
}
else
{
defaultMapUnitsPerMm = mWMSDefaultMapUnitScale->scale() / QgsUnitTypes::fromUnitToUnitFactor( QgsProject::instance()->crs().mapUnits(), QgsUnitTypes::DistanceMillimeters );
}

QgsProject::instance()->writeEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), defaultMapUnitsPerMm );

QgsProject::instance()->writeEntry( QStringLiteral( "WMTSUrl" ), QStringLiteral( "/" ), mWMTSUrlLineEdit->text() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMTSMinScale" ), QStringLiteral( "/" ), mWMTSMinScaleLineEdit->value() );
bool wmtsProject = false;
@@ -22,6 +22,7 @@
#include "qgis.h"
#include "qgsunittypes.h"
#include "qgsguiutils.h"
#include "qgsscalewidget.h"
#include "qgshelp.h"
#include "qgis_app.h"

@@ -204,6 +205,9 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
QgsMetadataWidget *mMetadataWidget = nullptr;
QgsLayerCapabilitiesModel *mLayerCapabilitiesModel = nullptr;

QDoubleSpinBox *mWMSDefaultMapUnitsPerMm = nullptr;
QgsScaleWidget *mWMSDefaultMapUnitScale = nullptr;

QgsCoordinateReferenceSystem mCrs;

void checkPageWidgetNameMap();
@@ -116,6 +116,11 @@ int QgsServerProjectUtils::wmsMaxAtlasFeatures( const QgsProject &project )
return project.readNumEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), 1 );
}

double QgsServerProjectUtils::wmsDefaultMapUnitsPerMm( const QgsProject &project )
{
return project.readDoubleEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), 1 );
}

bool QgsServerProjectUtils::wmsInfoFormatSia2045( const QgsProject &project )
{
QString sia2045 = project.readEntry( QStringLiteral( "WMSInfoFormatSIA2045" ), QStringLiteral( "/" ), "" );
@@ -154,6 +154,14 @@ namespace QgsServerProjectUtils
*/
SERVER_EXPORT int wmsMaxAtlasFeatures( const QgsProject &project );

/**
* Returns the default number of map units per millimeters in case of the scale is not given
* \param project the QGIS project
* \returns the default number of map units per millimeter
* \since QGIS 3.8
*/
SERVER_EXPORT double wmsDefaultMapUnitsPerMm( const QgsProject &project );

/**
* Returns if layer ids are used as name in WMS.
* \param project the QGIS project
@@ -183,15 +183,20 @@ namespace QgsWms
std::unique_ptr<QImage> image;
std::unique_ptr<QPainter> painter;

// getting scale from bbox
// getting scale from bbox or default size
if ( !mWmsParameters.bbox().isEmpty() )
{
QgsMapSettings mapSettings;
image.reset( createImage( width(), height(), false ) );
configureMapSettings( image.get(), mapSettings );
std::unique_ptr<QImage> tmp( createImage( width(), height(), false ) );
configureMapSettings( tmp.get(), mapSettings );
legendSettings.setMapScale( mapSettings.scale() );
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
}
else
{
double defaultMapUnitsPerPixel = QgsServerProjectUtils::wmsDefaultMapUnitsPerMm( *mContext.project() ) / mContext.dotsPerMm();
legendSettings.setMapUnitsPerPixel( defaultMapUnitsPerPixel );
}

if ( !mWmsParameters.rule().isEmpty() )
{
@@ -231,6 +236,11 @@ namespace QgsWms
legendRendererNew.drawLegend( painter.get() );
painter->end();
}
else
{
double defaultMapUnitsPerPixel = QgsServerProjectUtils::wmsDefaultMapUnitsPerMm( *mContext.project() ) / mContext.dotsPerMm();
settings.setMapUnitsPerPixel( defaultMapUnitsPerPixel );
}

rootGroup.clear();
return image.release();

0 comments on commit 042bd1f

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