Skip to content

Commit

Permalink
Don't show invisible layers and features in wms server feature info
Browse files Browse the repository at this point in the history
  • Loading branch information
marco committed Nov 13, 2011
1 parent 41de1a0 commit 9adb57e
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/mapserver/qgswmsserver.cpp
Expand Up @@ -36,6 +36,7 @@
#include "qgssymbol.h"
#include "qgssymbolv2.h"
#include "qgsrenderer.h"
#include "qgsrendererv2.h"
#include "qgslegendmodel.h"
#include "qgscomposerlegenditem.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -624,7 +625,8 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result )
//find out the current scale denominater and set it to the SLD parser
QgsScaleCalculator scaleCalc(( outputImage->logicalDpiX() + outputImage->logicalDpiY() ) / 2 , mMapRenderer->destinationCrs().mapUnits() );
QgsRectangle mapExtent = mMapRenderer->extent();
mConfigParser->setScaleDenominator( scaleCalc.calculate( mapExtent, outputImage->width() ) );
double scaleDenominator = scaleCalc.calculate( mapExtent, outputImage->width() );
mConfigParser->setScaleDenominator( scaleDenominator );
delete outputImage; //no longer needed for feature info

//read FEATURE_COUNT
Expand Down Expand Up @@ -742,6 +744,12 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result )
continue;
}

//skip layer if not visible at current map scale
if ( currentLayer->hasScaleBasedVisibility() && ( currentLayer->minimumScale() > scaleDenominator || currentLayer->maximumScale() < scaleDenominator ) )
{
continue;
}

if ( infoPoint && infoPointToLayerCoordinates( i, j, infoPoint, mMapRenderer, currentLayer ) != 0 )
{
continue;
Expand Down Expand Up @@ -1216,6 +1224,24 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
break;
}

//check if feature is rendered at all
if ( layer->isUsingRendererV2() )
{
QgsFeatureRendererV2* r2 = layer->rendererV2();
if ( !r2 || !r2->symbolForFeature( feature ) )
{
continue;
}
}
else
{
QgsRenderer* r = const_cast<QgsRenderer*>( layer->renderer() ); //bad, 'willRenderFeature' should be const
if ( !r || !r->willRenderFeature( &feature ) )
{
continue;
}
}

QDomElement featureElement = infoDocument.createElement( "Feature" );
featureElement.setAttribute( "id", FID_TO_STRING( feature.id() ) );
layerElement.appendChild( featureElement );
Expand Down

0 comments on commit 9adb57e

Please sign in to comment.