Skip to content

Commit 7f29572

Browse files
committedApr 13, 2012
SCALE parameter for GetLegendGraphic
1 parent 49b1ad3 commit 7f29572

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed
 

‎src/mapserver/qgswmsserver.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,26 @@ QImage* QgsWMSServer::getLegendGraphics()
297297
return 0;
298298
}
299299

300+
//scale
301+
double scaleDenominator = -1;
302+
QMap<QString, QString>::const_iterator scaleIt = mParameterMap.find( "SCALE" );
303+
if ( scaleIt != mParameterMap.constEnd() )
304+
{
305+
bool conversionSuccess;
306+
double scaleValue = scaleIt.value().toDouble( &conversionSuccess );
307+
if ( conversionSuccess )
308+
{
309+
scaleDenominator = scaleValue;
310+
}
311+
}
312+
300313
QgsCoordinateReferenceSystem dummyCRS;
301-
QStringList layerIds = layerSet( layersList, stylesList, dummyCRS );
314+
QStringList layerIds = layerSet( layersList, stylesList, dummyCRS, scaleDenominator );
315+
if ( layerIds.size() < 1 )
316+
{
317+
return 0;
318+
}
319+
302320
QgsLegendModel legendModel;
303321
legendModel.setLayerSet( layerIds );
304322

@@ -1394,7 +1412,7 @@ int QgsWMSServer::featureInfoFromRasterLayer( QgsRasterLayer* layer,
13941412

13951413
QStringList QgsWMSServer::layerSet( const QStringList &layersList,
13961414
const QStringList &stylesList,
1397-
const QgsCoordinateReferenceSystem &destCRS ) const
1415+
const QgsCoordinateReferenceSystem &destCRS, double scaleDenominator ) const
13981416
{
13991417
Q_UNUSED( destCRS );
14001418
QStringList layerKeys;
@@ -1430,9 +1448,15 @@ QStringList QgsWMSServer::layerSet( const QStringList &layersList,
14301448
QgsDebugMsg( QString( "Checking layer: %1" ).arg( theMapLayer->name() ) );
14311449
if ( theMapLayer )
14321450
{
1433-
layerKeys.push_front( theMapLayer->id() );
1434-
QgsMapLayerRegistry::instance()->addMapLayers(
1435-
QList<QgsMapLayer *>() << theMapLayer, false );
1451+
//test if layer is visible in requested scale
1452+
bool useScaleConstraint = ( scaleDenominator > 0 && theMapLayer->hasScaleBasedVisibility() );
1453+
if ( !useScaleConstraint ||
1454+
( theMapLayer->minimumScale() <= scaleDenominator && theMapLayer->maximumScale() >= scaleDenominator ) )
1455+
{
1456+
layerKeys.push_front( theMapLayer->id() );
1457+
QgsMapLayerRegistry::instance()->addMapLayers(
1458+
QList<QgsMapLayer *>() << theMapLayer, false );
1459+
}
14361460
}
14371461
else
14381462
{

‎src/mapserver/qgswmsserver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ class QgsWMSServer
119119
/**Appends feature info xml for the layer to the layer element of the dom document*/
120120
int featureInfoFromRasterLayer( QgsRasterLayer* layer, const QgsPoint* infoPoint, QDomDocument& infoDocument, QDomElement& layerElement, QString version ) const;
121121

122-
/**Creates a layer set and returns a stringlist with layer ids that can be passed to a QgsMapRenderer. Usually used in conjunction with readLayersAndStyles*/
123-
QStringList layerSet( const QStringList& layersList, const QStringList& stylesList, const QgsCoordinateReferenceSystem& destCRS ) const;
122+
/**Creates a layer set and returns a stringlist with layer ids that can be passed to a QgsMapRenderer. Usually used in conjunction with readLayersAndStyles
123+
@param scaleDenominator Filter out layer if scale based visibility does not match (or use -1 if no scale restriction)*/
124+
QStringList layerSet( const QStringList& layersList, const QStringList& stylesList, const QgsCoordinateReferenceSystem& destCRS, double scaleDenominator = -1 ) const;
124125

125126
//helper functions for GetLegendGraphics
126127
/**Draws layer item and subitems

0 commit comments

Comments
 (0)