Skip to content

Commit

Permalink
SCALE parameter for GetLegendGraphic
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 13, 2012
1 parent 49b1ad3 commit 7f29572
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
34 changes: 29 additions & 5 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -297,8 +297,26 @@ QImage* QgsWMSServer::getLegendGraphics()
return 0;
}

//scale
double scaleDenominator = -1;
QMap<QString, QString>::const_iterator scaleIt = mParameterMap.find( "SCALE" );
if ( scaleIt != mParameterMap.constEnd() )
{
bool conversionSuccess;
double scaleValue = scaleIt.value().toDouble( &conversionSuccess );
if ( conversionSuccess )
{
scaleDenominator = scaleValue;
}
}

QgsCoordinateReferenceSystem dummyCRS;
QStringList layerIds = layerSet( layersList, stylesList, dummyCRS );
QStringList layerIds = layerSet( layersList, stylesList, dummyCRS, scaleDenominator );
if ( layerIds.size() < 1 )
{
return 0;
}

QgsLegendModel legendModel;
legendModel.setLayerSet( layerIds );

Expand Down Expand Up @@ -1394,7 +1412,7 @@ int QgsWMSServer::featureInfoFromRasterLayer( QgsRasterLayer* layer,

QStringList QgsWMSServer::layerSet( const QStringList &layersList,
const QStringList &stylesList,
const QgsCoordinateReferenceSystem &destCRS ) const
const QgsCoordinateReferenceSystem &destCRS, double scaleDenominator ) const
{
Q_UNUSED( destCRS );
QStringList layerKeys;
Expand Down Expand Up @@ -1430,9 +1448,15 @@ QStringList QgsWMSServer::layerSet( const QStringList &layersList,
QgsDebugMsg( QString( "Checking layer: %1" ).arg( theMapLayer->name() ) );
if ( theMapLayer )
{
layerKeys.push_front( theMapLayer->id() );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << theMapLayer, false );
//test if layer is visible in requested scale
bool useScaleConstraint = ( scaleDenominator > 0 && theMapLayer->hasScaleBasedVisibility() );
if ( !useScaleConstraint ||
( theMapLayer->minimumScale() <= scaleDenominator && theMapLayer->maximumScale() >= scaleDenominator ) )
{
layerKeys.push_front( theMapLayer->id() );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << theMapLayer, false );
}
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions src/mapserver/qgswmsserver.h
Expand Up @@ -119,8 +119,9 @@ class QgsWMSServer
/**Appends feature info xml for the layer to the layer element of the dom document*/
int featureInfoFromRasterLayer( QgsRasterLayer* layer, const QgsPoint* infoPoint, QDomDocument& infoDocument, QDomElement& layerElement, QString version ) const;

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

//helper functions for GetLegendGraphics
/**Draws layer item and subitems
Expand Down

0 comments on commit 7f29572

Please sign in to comment.