Skip to content
Permalink
Browse files

Merge pull request #9775 from signedav/default_symbol_scale

[server] Default scale/mupmm on GetLegendGraphics
  • Loading branch information
pblottiere committed Apr 17, 2019
2 parents 8416e75 + 27fc381 commit 3c6299a199f53d3087f18e4e3d1825878e3ff833
@@ -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 );
@@ -646,6 +646,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 ) );

@@ -1305,6 +1324,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
@@ -117,7 +117,7 @@ namespace QgsWms
QList<QgsMapLayer *> layers = mContext.layersToRender();
configureLayers( layers );

// getting scale from bbox
// getting scale from bbox or default size
QgsLegendSettings settings = mWmsParameters.legendSettings();
if ( !mWmsParameters.bbox().isEmpty() )
{
@@ -127,6 +127,11 @@ namespace QgsWms
settings.setMapScale( mapSettings.scale() );
settings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
}
else
{
double defaultMapUnitsPerPixel = QgsServerProjectUtils::wmsDefaultMapUnitsPerMm( *mContext.project() ) / mContext.dotsPerMm();
settings.setMapUnitsPerPixel( defaultMapUnitsPerPixel );
}

// init renderer
QgsLegendRenderer renderer( &model, settings );
@@ -171,6 +176,11 @@ namespace QgsWms
settings.setMapScale( mapSettings.scale() );
settings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
}
else
{
double defaultMapUnitsPerPixel = QgsServerProjectUtils::wmsDefaultMapUnitsPerMm( *mContext.project() ) / mContext.dotsPerMm();
settings.setMapUnitsPerPixel( defaultMapUnitsPerPixel );
}

// create image
const int width = mWmsParameters.widthAsInt();

0 comments on commit 3c6299a

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