Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
WMS server: create rendercontext to find out visible features
  • Loading branch information
mhugent committed Mar 2, 2012
1 parent eaed670 commit 203cb9b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 18 additions & 5 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -810,6 +810,18 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
QMap< QString, QMap< int, QString > > aliasInfo = mConfigParser->layerAliasInfo();
QMap< QString, QSet<QString> > hiddenAttributes = mConfigParser->hiddenAttributes();

//Render context is needed to determine feature visibility for vector layers
QgsRenderContext renderContext;
if ( mMapRenderer )
{
renderContext.setExtent( mMapRenderer->extent() );
renderContext.setRasterScaleFactor( 1.0 );
renderContext.setMapToPixel( *( mMapRenderer->coordinateTransform() ) );
renderContext.setRendererScale( mMapRenderer->scale() );
renderContext.setScaleFactor( mMapRenderer->outputDpi() / 25.4 );
renderContext.setPainter( 0 );
}

QList<QgsMapLayer*> layerList;
QgsMapLayer* currentLayer = 0;
QStringList::const_iterator layerIt;
Expand Down Expand Up @@ -861,7 +873,8 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
layerHiddenAttributes = hiddenIt.value();
}

if ( featureInfoFromVectorLayer( vectorLayer, infoPoint, featureCount, result, layerElement, mMapRenderer, layerAliasInfo, layerHiddenAttributes, version, featuresRect ) != 0 )
if ( featureInfoFromVectorLayer( vectorLayer, infoPoint, featureCount, result, layerElement, mMapRenderer, renderContext,
layerAliasInfo, layerHiddenAttributes, version, featuresRect ) != 0 )
{
continue;
}
Expand Down Expand Up @@ -1207,6 +1220,7 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
QDomDocument& infoDocument,
QDomElement& layerElement,
QgsMapRenderer* mapRender,
QgsRenderContext& renderContext,
QMap<int, QString>& aliasMap,
QSet<QString>& hiddenAttributes,
QString version,
Expand All @@ -1226,7 +1240,7 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
//info point could be 0 in case there is only an attribute filter
if ( infoPoint )
{
double searchRadius = ( layerRect.xMaximum() - layerRect.xMinimum() ) / 200;
double searchRadius = ( layerRect.xMaximum() - layerRect.xMinimum() ) / 100;
searchRect.set( infoPoint->x() - searchRadius, infoPoint->y() - searchRadius,
infoPoint->x() + searchRadius, infoPoint->y() + searchRadius );
}
Expand Down Expand Up @@ -1262,10 +1276,9 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
continue;
}

QgsRenderContext c;
r2->startRender( c, layer );
r2->startRender( renderContext, layer );
bool renderV2 = r2->willRenderFeature( feature );
r2->stopRender( c );
r2->stopRender( renderContext );
if ( !renderV2 )
{
continue;
Expand Down
3 changes: 2 additions & 1 deletion src/mapserver/qgswmsserver.h
Expand Up @@ -33,6 +33,7 @@ class QgsMapRenderer;
class QgsPoint;
class QgsRasterLayer;
class QgsRectangle;
class QgsRenderContext;
class QgsVectorLayer;
class QgsSymbol;
class QColor;
Expand Down Expand Up @@ -114,7 +115,7 @@ class QgsWMSServer
@param featureBBox the bounding box of the selected features in output CRS
@return 0 in case of success*/
int featureInfoFromVectorLayer( QgsVectorLayer* layer, const QgsPoint* infoPoint, int nFeatures, QDomDocument& infoDocument, QDomElement& layerElement, QgsMapRenderer* mapRender,
QMap<int, QString>& aliasMap, QSet<QString>& hiddenAttributes, QString version, QgsRectangle* featureBBox = 0 ) const;
QgsRenderContext& renderContext, QMap<int, QString>& aliasMap, QSet<QString>& hiddenAttributes, QString version, QgsRectangle* featureBBox = 0 ) const;
/**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;

Expand Down

0 comments on commit 203cb9b

Please sign in to comment.